I have a table in a local SQL server database. I want to recreate this table in a hosted database.
What I want to do is to have a script that when run against the hosted database, this table is recreated with all the data, etc.
How do I create this script using SQL Server Management Studio? Thanks.
1- Open SQL server Management Studio.
2- Right click on the DB that contains your desired table.
3- Select "Tasks => Generate Scripts...".
4- Follow on the wizard, and choose the objects that you want to generate scripts for (Tables, Views, Stored Procedures, etc... ).
5- From the next step, click on "Advanced", and for the node that is labeled "Types of data to script" choose "Schema and data".
6- Save your script and smile :)
You can do this using Generate Scripts database task. Right-click the database > Tasks > Generate Scripts... Choose "Select specific database objects" and the table you want.
On the Set Scripting Options page, click Advanced. There is an option "Types of data to script", choose "Schema and data". Choose where to save it. Next. Next. Finish.
That is the answer however, if the table contains a large amount of data I recommend using bcp out or another method to export the data. If the new server is on the same network, you could also select it as a linked server.
The script method will generate individual insert statements.