SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 How to Generate CREATE TABLE and INSERT Script?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Zealander
Starting Member

Canada
2 Posts

Posted - 07/20/2010 :  17:40:23  Show Profile  Reply with Quote
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

USA
37471 Posts

Posted - 07/20/2010 :  17:41:49  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

USA
37471 Posts

Posted - 07/20/2010 :  17:42:40  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

Canada
2 Posts

Posted - 07/21/2010 :  09:13:27  Show Profile  Reply with Quote
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

USA
37471 Posts

Posted - 07/21/2010 :  13:29:39  Show Profile  Visit tkizer's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000