Can I create a table in Database B from a view in Database A in a script that's using Database A?

  • lmk1

    Old Hand

    Points: 385

    Example:

    USE DatabaseA

    SELECT * INTO Table1 FROM V_View1

    SELECT * INTO Table2 FROM V_View2

    SELECT * INTO DatabaseB.dbo.Table3 FROM V_View3

    Would the above create Table 3 in Database B, while creating Table 1 and Table 2 in Database A? Database A and Database B are both on the same server instance.

  • Alvin Ramard

    SSC-Forever

    Points: 41190

    What happened when you tried it?



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • lmk1

    Old Hand

    Points: 385

    Just kept spinning, perhaps because View3 is rather large...or it could be that it doesn't really work, I've had that happen before too. I don't have my own test database to play with at the moment and I don't want to risk inadvertently messing anything up on the company DBs. I'm about 90% sure that the SQL I posted originally works as I intend it to, but I want to be extra cautious before I update the script. It may be that my Google-Fu is not very strong, but I wasn't able to find any sufficiently similar posts out there.

  • viralbhatt

    SSC Journeyman

    Points: 79

    best to run query and check, use top 10 to reduce time. i have done that on my pc and it does create table in database B.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply