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

  • 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.

  • 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]

  • 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.

  • 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 3 (of 3 total)

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