Jump to content

How can I insert values to table from store procedure in another database SQL server

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
rivkic

rivkic

    Newbie

  • Members
  • PipPip
  • 19 posts
I have sql server 2008.
I have two databases: "DB1" and "DB2".
In "DB1" there is a store procedure that has to select values
and insert them to table in "DB2".

I can I do it?
I can I connect to one database from another database?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It depends on the security settings, but yes it's possible. I recently did a database migration where I connected to one database and executed:
INSERT INTO TABLE1 (values) SELECT values FROM DB2.dbo.TABLE2;

Of course, the values was a little complicated :)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
rivkic

rivkic

    Newbie

  • Members
  • PipPip
  • 19 posts
thank you so much!:thumbup: