Sunday, March 25, 2012

Copying tables between database

Hi
I have 2 user created databases in MS SQL Server 2000. Now I want to copy tables from one of this database to the other. The structure, relationships etc of these tables between these 2 databases are very similar. I searched high and low in BOL but could not find any info
Can some one help me in this please ...
Thanks
Harish MohanbabuHarish, you have many different solutions:
- SELECT col_list INTO db2.dbo.newtable FROM db1.dbo.oldtable - check
SELECT statement in Books OnLine
- Use Data Transformation Services (you can do it with the DTS Import/Export
Wizard) - check "DTS Import/Export Wizard" topic
- Create scripts, if you need metadata only, and implement scripts in the
new database - check "How to generate a script (Enterprise Manager)"
- ...
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Harish Mohanbabu" <anonymous@.discussions.microsoft.com> wrote in message
news:CFDD7D65-54E0-436D-8B40-51DBE7CA6E90@.microsoft.com...
> Hi,
> I have 2 user created databases in MS SQL Server 2000. Now I want to copy
tables from one of this database to the other. The structure, relationships
etc of these tables between these 2 databases are very similar. I searched
high and low in BOL but could not find any info.
> Can some one help me in this please ...
> Thanks,
> Harish Mohanbabu|||Hi,
Since you have the schema in both the databases, Probably you need to copy
the data from database to another in same server, then you can use
1. Copy only data
insert into tablename select * from dbname..tablename
2. If we need to replicate all the tables / users / procedures in one
database to another then you can Backup and Restore
Backup database dbname1 to disk='c:\dbname.bak' with init,stats=10
go
Restore database dbname2 from disk='c:\dbname.bak' with move
'logicaldatafilename' to 'newphysicalfile.mdf',
move 'logicallogfilename' to 'newphysicalfile.ldf'
Thanks
Hari
MCDBA
"Harish Mohanbabu" <anonymous@.discussions.microsoft.com> wrote in message
news:CFDD7D65-54E0-436D-8B40-51DBE7CA6E90@.microsoft.com...
> Hi,
> I have 2 user created databases in MS SQL Server 2000. Now I want to copy
tables from one of this database to the other. The structure, relationships
etc of these tables between these 2 databases are very similar. I searched
high and low in BOL but could not find any info.
> Can some one help me in this please ...
> Thanks,
> Harish Mohanbabu|||Hi Dejan/Hari,
Thank you very much for your kind replies. Since the structure of tables between databases were same, I used DTS to copy data between tables.
Cheers,
Harish Mohanbabu

No comments:

Post a Comment