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
 Import/Export (DTS) and Replication (2000)
 How to Generate CREATE TABLE and INSERT Script?

Author  Topic 

Zealander
Starting Member

2 Posts

Posted - 2010-07-20 : 17:40:23
Our company is migrating to Java platform. As part of that migration we also are moving our DB from MS SQL Server 2005 to MySQL.

Developers requested our existing SQL Server database schema and sample data so they can develop and test data migration script.

I generated a CREATE TABLE script for every table using "Generate Scripts" tool in MS SQL Server Management Studio. But can't figure out how to generate INSERTs (the TOP 3 rows) INTO those tables.

Is there a way to generate a script that will have CREATE TABLE statements followed by INSERT INTO statements that will insert TOP 3 rows from existing table?

Let's say there is a table tblUsers that has 1000 rows of data. I would like to generate a script that will have:
CREATE TABLE tblUsers(ID INT, UserName VARCHAR(50))

Followed by:
INSERT INTO tblUsers(1, 'Jill')
INSERT INTO tblUsers(2, 'John')
INSERT INTO tblUsers(3, 'Jack')

Where [1,Jill],[2,John] and [3,Jack] are real (TOP 3) rows from tblUsers.

Other ideas on how to get around that are welcome.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-20 : 17:41:49
http://vyaskn.tripod.com/code/generate_inserts.txt

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-20 : 17:42:40
Our Java apps work perfectly on SQL Server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Zealander
Starting Member

2 Posts

Posted - 2010-07-21 : 09:13:27
quote:
Originally posted by tkizer

http://vyaskn.tripod.com/code/generate_inserts.txt

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



Thanks! The script didn't work, but it gave me a good idea on how to do it. :)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-21 : 13:29:39
You're welcome. I haven't used the script in a while, perhaps I last used it on 2000.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -