Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Move table to another DB with constraints

Author  Topic 

Mng
Yak Posting Veteran

59 Posts

Posted - 2010-04-02 : 08:11:42
Hi, i am trying to move a "Student" table from database "DB1" to database "DB2" using import and export wizard. It wents fine and the data is transfered. But i realise, that its not getting constraints like primary key, identity etc.

How can i acheive this. I need to move some tables from one DB to another DB with all data along with constriants and keys.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-02 : 08:21:47
1 Script Tables and run them in DB2
2 Write queries

Insert into DB2..table (column_list)
select column_list from DB1..table

.
.
.


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Mng
Yak Posting Veteran

59 Posts

Posted - 2010-04-02 : 08:28:09
Hi Madhivan,
Is this a way to write a query..i tried this but getting error saying object not found.
Insert into dbo.DB2.Student Select * from Student

Error:Invalid object name 'dbo.DB2.Student'.

If i do like this, i can get constratins, indexes and primiarykeys of a table from Db1 to Db2 ??

quote:
Originally posted by madhivanan

1 Script Tables and run them in DB2
2 Write queries

Insert into DB2..table (column_list)
select column_list from DB1..table

.
.
.


Madhivanan

Failing to plan is Planning to fail

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-02 : 10:07:01
It should be

Insert into DB2.dbo.Student Select * from Student

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -