Create table with data

Is there a way to generate a script on a table that will
Create the table if not exists
Insert the current data
Larry Bristersr. DeveloperAsked:
Who is Participating?
 
SStoryCommented:
Better yet, select the database, right-click, Tasks->Generate Scripts and you should be able to do anything.
0
 
SStoryCommented:
From Management Studio

Right-click the table, from the menu "Script Table as - > CREATE to->"
This will recreate the table
0
 
Larry Bristersr. DeveloperAuthor Commented:
SStory,
 That doesn't get me the data to insert as well
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
SStoryCommented:
When it gets to Set Scripting Options, click the Advanced button and change
Types of data to script to "Schema and data"

You do actually have to look around in these tools to get them to do what you need, but this should do it.
0
 
Larry Bristersr. DeveloperAuthor Commented:
In the Generate Scripts Advanced Tag was the ability to generate schema as well as data.

Thanks
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>Insert the current data
None that I'm aware of that will save it as a script.  Have fun with that.

The work-around that is easiest to pull off would be to export the table data as a .csv, save it with the script, then the target db will have to...
Execute the CREATE TABLE script
Do an SSIS / Import wizard to connect to the .csv as the source, the created table as the target, and execute.
0
 
Scott PletcherSenior DBACommented:
If the table doesn't exist, what "current data" are you talking about?

If you mean copying data from one db to another using the same table name, then, yes, there are ways to do that.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>Advanced tab, Types of data to script ... Schema and Data
Learn something new every day.  Now that's handy..
0
 
Larry Bristersr. DeveloperAuthor Commented:
Yes it is
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.