SolvedPrivate

Create table with data

Posted on 2013-11-20
9
41 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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
 

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 66

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:Scott Pletcher
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 66

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

632 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