SolvedPrivate

Create table with data

Posted on 2013-11-20
9
37 Views
Last Modified: 2016-02-11
Is there a way to generate a script on a table that will
Create the table if not exists
Insert the current data
0
Comment
Question by:lrbrister
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39662652
From Management Studio

Right-click the table, from the menu "Script Table as - > CREATE to->"
This will recreate the table
0
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 39662663
Better yet, select the database, right-click, Tasks->Generate Scripts and you should be able to do anything.
0
 

Author Comment

by:lrbrister
ID: 39662707
SStory,
 That doesn't get me the data to insert as well
0
 
LVL 25

Expert Comment

by:SStory
ID: 39662731
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Closing Comment

by:lrbrister
ID: 39662737
In the Generate Scripts Advanced Tag was the ability to generate schema as well as data.

Thanks
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39662739
>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
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 39662743
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
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39662763
>Advanced tab, Types of data to script ... Schema and Data
Learn something new every day.  Now that's handy..
0
 

Author Comment

by:lrbrister
ID: 39662775
Yes it is
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My client sends data in an Excel file to me to load them into Staging database. The file contains many sheets that they have same structure. In this article, I would like to share the simple way to load data of multiple sheets by using SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now