Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
SolvedPrivate

Create table with data

Posted on 2013-11-20
9
Medium Priority
?
42 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 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 70

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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…
Viewers will learn how the fundamental information of how to create a 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…

715 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