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 2000 Forums
 SQL Server Development (2000)
 Copy Table with PK Constarint and Index

Author  Topic 

kirannatt
Yak Posting Veteran

66 Posts

Posted - 2006-09-19 : 12:04:42
HI all,

I want to copy my table(both stucture and data)with constraint from one db to another db. I tried select into but it doesn't tranfer my contraints and index. DOes any one know better way of doing it.

Thanks!

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-19 : 12:43:03
script the table in enterprise manager?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

kirannatt
Yak Posting Veteran

66 Posts

Posted - 2006-09-19 : 12:49:01
Yeah, But I am looking for way so that I can copy my table with structure(constarints) and data in one step. I don't want to create table first and do tranfer using DTS or something else.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-09-19 : 13:21:03
No way I know of to do that unless you use some 3rd part application, or brew-your-own script with something that generates INSERT statements for the data (which isn't really very efficient!)

What problem are you trying to solve - knowing that might enable us to think of a different way

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-19 : 13:25:42
well then, good luck.

Why not do SELECT * INTO t FROM t

Then just apply contraints and indexes from a script

Other than that, I don't know of a way



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-09-19 : 13:31:00
"Why not do SELECT * INTO t FROM t

Then just apply constraints and indexes from a script
"

Do you reckon that's better than the other way round:

Build the database using a script, and then:

INSERT INTO TargetDatabase.dbo.TargetTable
SELECT *
FROM SourceDatabase.dbo.SourceTable

if going that route I would apply the FK part of the script (and the indexes too if its a large database) after the import was completed.

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-19 : 14:02:47
Nah, you know I would probably dump and restore

And if it was just 1 table, create the sacript and execute it then bcp out/in

I like to have repeatable processes every time I build something


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-09-19 : 15:15:26
"I like to have repeatable processes every time I build something"

You are right, that's the most persuasive argument for Build then Import. Some extra possible hassle with IDENTITY columns, and the need to create the FKs after the import - and probably the indexes too - but that's basically just doing the job properly. "Can you import this for me, its only a one off, don't take any special trouble" ... "Sorry, now I see the data I realise I got it wrong, here's some fresh data, I know you will have scripted it!"

Kristen
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-09-20 : 06:50:51
Notice the KEY PHRASE in the answer from the poster:
quote:
I don't want to create table first and do tranfer using DTS or something else.


Regardless if this is the best way, or ONLY way or not. Never understood the "I don't want to" stuff. Whats wrong with solving the problem with industry standard practices or "expert" advice?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-09-20 : 15:28:34
"Never understood the "I don't want to" stuff"

I read the nuance differently as: the OP wants to do it in one step, rather than two.

I'd quite like a solution that does that too!

Kristen
Go to Top of Page
   

- Advertisement -