Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Location
    Tennessee
    Posts
    2

    Unanswered: What is the opposite of USE

    This seems to be a silly question, but I have had little luck finding the answer.

    How do I de-select any database selection that has been selected using a line such as the following?

    USE somedatabase

    I do not want to select another database, but instead select none.

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322

    Re: What is the opposite of USE

    Originally posted by jkrew_db
    This seems to be a silly question, but I have had little luck finding the answer.

    How do I de-select any database selection that has been selected using a line such as the following?

    USE somedatabase

    I do not want to select another database, but instead select none.
    Where are you doing this and why do you want to?

    I don't think (damn there it goes again) there is a way to do this.

  3. #3
    Join Date
    Oct 2003
    Location
    Tennessee
    Posts
    2
    And example of where I thought this could be used is in a stored procedure I'm currently working on (no sp guru here, I'm one of those that usually let's my code perform most of the logic).

    Let's say I need to delete all of the data in quite a few tables in one database and then select all of the data in ONLY ONE table in another database. This is handled by one stored procedure, and the two databases are identical in structure. I was looking into a way to cut some syntax out of the code and still make sure that it was easy to identify which particular database each block of code is dealing with.

    The sp currently looks something like this:

    delete from some_database..data_from_table_1
    delete from some_database..data_from_table_2
    delete from some_database..data_from_table_3

    (declare some variables, do some stuff, and then...)

    select from some_database_2..some_data_from_table_1

    Instead, I was wondering if could write something more like the following:

    USE some_database
    delete from data_from_table_1
    delete from data_from_table_2
    delete from data_from_table_3
    UNUSE some_database

    (declare some variables, do some stuff, and then...)

    select from some_database_2..some_data_from_table_1

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    No. You can't use USE or GO inside stored procedures.

    You'll have to code the db names.

    But there are tricks to generate code...typing is such a drag

    for Example...



    SELECT 'DELETE FROM '+TABLE_NAME FROM INFORMATION_SCHEMA.TABLES

    Then just cut and paste the results you want in to your code..

    and sprocs are THE way to

Posting Permissions

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