I can use Generate Scripts tool to get scripts for tables, procedures etc. But now I have records in tables which I want all "Insert into ..." queries from sqlserver.  My co-worker said I have to manually type all these lines for my data.sql. Do I have to? I guess there must be a way...
Thanks,
LiliTry using DTS (Data Transformation services) which will allow you to recreate and / or rename the table and also lets you populate with original data. 
The fastest way to recreate tables as you can recreate your entire database if you want to.
 :p|||DTS is awsome :) but I need to deliver data.sql (of course with all other *.sql files) to the client so that they can install and drop database any time they mess it up :P|||It sounds like you want to give the client some base data.  Could you not just BCP the data out into files and then create a command file that would truncate the tables and then BCP the data back in?
Or do you need to create the INSERT statements?
Example:INSERT myTbl (col1,col2,col3) VALUES ('xxx','aaa',123)|||Yes! base data. I need to insert statements. I just typed up some, but I'm wondering whether I can use a tool to make life easier :)
and guru, could you read my post about "Create My Own Log (for functionality) "? Thank you!
Lili|||Following sql statement will help you to generate INSERT STATEMENT for your base table
Table Name  : BaseTable 
fields       
BName   varchar(20) 
dt           smalldatetime
val          int
select 'Insert into BaseTable  VALUES (' + '''' + bname + '''' + ',' 
+ '''' + convert(varchar(10),dt,101) + ''''  + ','
+  '''' + convert(varchar(10),val) + '''' + ')'
from basetable 
handle NULL part by using ISNULL function
All the best|||Wow! Good idea. Silly me :p Thanks,
Lili|||You know sometimes I get carried away.  I wrote a stored procedure that will generate all the INSERT statements for a given table.  I've attached the proc, it worked for me on 2000.
Example on pubs
exec usp_CreateInsert discounts
OUTPUT:
INSERT  discounts ( discounttype, stor_id, lowqty, highqty, discount)
        VALUES ('Initial Customer',NULL,NULL,NULL,10.50)
INSERT  discounts ( discounttype, stor_id, lowqty, highqty, discount)
        VALUES ('Volume Discount',NULL,100,1000,6.70)
INSERT  discounts ( discounttype, stor_id, lowqty, highqty, discount)
        VALUES ('Customer Discount','8042',NULL,NULL,5.00)|||//@.@. where is the stored procedure?|||It must have stoppped me because the extension of the file was '.sql', so I had to change it to '.txt'|||wow, you are real sql guru //admire
thank you for your help and sharing :)
Have a nice weekend!
Lili
 
No comments:
Post a Comment