Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2014
    Posts
    294

    Unanswered: Dynamical switching of one database to other database

    HI,

    I am very new to sybase. can someone kindly let me know , how to switch from one database to other database inside a procedure dynamically in Sybase. In SQL server like use database command.


    Thanks

  2. #2
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4
    If your procedure is in databaseA you can access an object in databaseB by using databaseB.<owner>.<objectname>.
    For instance select emp_id, emp_name from databaseB.dbo.employees.
    I'm not crazy, I'm an aeroplane!

  3. #3
    Join Date
    Jul 2014
    Posts
    294
    Thanks for the answer Martijnvs .

    This really helps me. My scenario is I have to create some index on a table on one database by sitting on other database.All the operations can't be done sitting on one database, I think . something like creating roles on other database, creating views etc.
    On a procedure is there any way so that i can directly switch from one database to other database & to create some objects on the target database.

  4. #4
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4
    Within a stored procedure you can't really 'switch' to another database, but you can acces objects using the method I described.
    From what you describe in your latest post I understand that you want to create objects in various databases in one single script.
    You can use the use d<database> command for the:
    Code:
    use databaseA
    go
    <create objects etc>
    go
    use databaseB
    go
    <execute more sql>
    go
    The use d<database> command does not work in a stored procedure, though.
    I'm not crazy, I'm an aeroplane!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •