Last post Feb 17, 2015 04:12 AM by m4bharat_outlook.com
Feb 16, 2015 05:21 AM|m4bharat_outlook.com|LINK
How to copy table from one database to another database with key constraints and data in sql server 2008 R2.
Plzz reply me ASAP.
Thanks in advance
Feb 16, 2015 06:40 AM|eralper|LINK
First script table using SSMS
Right click on "table > script table as > create to" script with constraints, etc
Then create the new table
Later run script like following
set identity_insert t2 on
insert into t2 (col1,col2)
select col1,col2 from db1.dbo.t1
set identity_insert t2 off
Feb 16, 2015 07:05 AM|m4bharat_outlook.com|LINK
i need to do this by query only
Feb 16, 2015 07:13 AM|eralper|LINK
select * into Table2 from db1.dbo.Table1
Following SELECT will automatically create a new table named Table2 but will not copy constraints on original table
Feb 16, 2015 07:16 AM|Yousef_Jadallah|LINK
You can use Generate and publish Scripts for your table , then run the script to the second database.:
Feb 16, 2015 07:49 AM|pka246|LINK
You need to Generate Script with only data by right click database=>Tasks=>Generate Scripts.. it will open Generate and Publish script wizard.
then click "Next".
then select specific tables from by clicking "Select specific object from database" radio button.
then click "Next".
here you need to click Advance button and this will open Options window.
go to General=>Types of data to script=>select Data Only from dropdown => then click OK.
Finish the wizard.
it will generate scripts with data only.
Feb 16, 2015 08:53 AM|m4bharat_outlook.com|LINK
it doesn't copy constraints on table.
Feb 16, 2015 08:54 AM|m4bharat_outlook.com|LINK
i want to copy table from one database to another database with data and constraints using sql query or stored procedure.
Feb 16, 2015 10:18 PM|Michelle Ge - MSFT|LINK
So far as I know, you can use select * into sql.
Please refer to the sql demo below:
Select * into DestinationDB.dbo.tableName from SourceDB.dbo.SourceTable
For more information, please refer to the link below:
Hope it's useful for you
Feb 17, 2015 04:12 AM|m4bharat_outlook.com|LINK
I got the solution.
I have generated scripti through c# sharp cod
and written stored procedure to created table structure and copy data from source db.