I have my table 'Category' which have 30 rows.
just asking on how can I create script to create new table 'Category' and it will include the 30 rows of it?
thanks in advance
Printable View
I have my table 'Category' which have 30 rows.
just asking on how can I create script to create new table 'Category' and it will include the 30 rows of it?
thanks in advance
You didn't mention what database you are using. For SQL 2005 you can:
Select * into NewCategory from Category.
If you don't want to rename it you'll need to do something like:
Select * into #TempCategory
Drop table category
select * into Category from ##TempCategory
It would help to know what you are trying to achieve.
I think the OP is asking how to create a script that when run, will create the table and insert the values into it ... creating the table is easy... from SSMS, you can right-click the table, select Script As -> Create -> New Window... and that will generate the script to create the table. The insert data... that's going to take a little more effort as there isn't an automatic way to do that... but unless it's uber complicated, it's probably just as easy to write it by hand...
update - as I was writing that up, it occurred to me that I might have something in my bag o' tricks... sure enough... I have a script that will script the data of a table into insert statements... all you have to do it open it in SSMS, using the right database, point it at the table, set a couple of option and run it... documentation is in the script. I PROVIDE IT WITH NO SUPPORT OR WARRANTY, USE AT YOUR OWN RISK.
-tg