Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My technology blog on SQL Server, TSQL, XML, FILESTREAM and other areas of SQL Server.
Browse by Tags · View All
XML 112
TSQL 69
XQuery 69
XQuery Functions 67
XQuery Training 65
XQuery in TSQL 64
XQuery Tutorial 63
SQL Server XQuery 63
XQuery-Labs 57
BRH 38

Archive · View All
September 2008 32
August 2008 30
July 2008 21
August 2009 19
June 2009 19
May 2010 18
January 2009 15
January 2010 14
October 2008 14
June 2008 13

SQL Server - Generating scripts for schema (and data) using SSMS 2008

Jul 13 2012 11:47PM by Jacob Sebastian   

Recently a friend asked me steps/instructions to scripting schema and data of tables from a SQL Server database. I thought of writing a post and sharing the link rather than writing the process in an email, because I think this may benefit more people.

Sample Table

Let us assume that we have a table with the schema/structure and data as follows.

IF OBJECT_ID('Customers','U') IS NOT NULL BEGIN
	DROP TABLE Customers
END
CREATE TABLE Customers (
	CustomerID INT IDENTITY,
	FirstName VARCHAR(20),
	LastName VARCHAR(20),
	City VARCHAR(20) 
)

INSERT INTO Customers (FirstName, LastName, City)
SELECT 'Jacob', 'Sebatian','Ahmedabad' UNION ALL
SELECT 'Pinal', 'Dave', 'Bangalore'

Script Wizard

let us now try to generate the script for the schema and data of this table and find out what we get from SSMS.

The first step is to right click on the database and select Tasks > Generate Scrits

step1

This will start the wizard. Click Next

step2

If you would like to script all the objects in the database, leave the default options. Otherwise, select the specific objects you wish to script.

step3

This is a critical step if you wish to generate scripts for the data also. Click on the Advanced button (as shown in the below screen image) and specify the additional options (as explained below)

step4

At this step, locate the option Types of data to script and select Schema and Data (or any other option that suites your requirements)

step5

This step is a usual ‘overhead’ that every wizard has and usually no one pays attention to that. However, it is recommended that you review the information before clicking on next

step6

This will generate the scripts in the selected folder. Wait for the process to complete before proceeding.

step7

Click on Finish to close the wizard.

Examine the results

Now let us go to the folder specified in the wizard and take a look at the script the wizard generated.  Here is what I got.

USE [NorthPole]
GO
/****** Object:  Table [dbo].[Customers]    Script Date: 07/13/2012 19:02:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Customers](
	[CustomerID] [int] IDENTITY(1,1) NOT NULL,
	[FirstName] [varchar](20) NULL,
	[LastName] [varchar](20) NULL,
	[City] [varchar](20) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

SET IDENTITY_INSERT [dbo].[Customers] ON
INSERT [dbo].[Customers] ([CustomerID], [FirstName], [LastName], [City]) 
	VALUES (1, N'Jacob', N'Sebatian', N'Ahmedabad')
INSERT [dbo].[Customers] ([CustomerID], [FirstName], [LastName], [City]) 
	VALUES (2, N'Pinal', N'Dave', N'Bangalore')
SET IDENTITY_INSERT [dbo].[Customers] OFF

Tags: 


Jacob Sebastian
1 · 100% · 32004
12
 
0
Lifesaver
 
 
 
0
Incorrect



Submit

9  Comments  

  • This is excellent script! I am going to link it back soon from blog. Lots of good scripts during this script week!

    commented on Jul 14 2012 12:44AM
    Pinal Dave
    146 · 1% · 326
  • Thanks Jacob, Good to know this one.

    commented on Jul 18 2012 6:41AM
    sk2000
    504 · 0% · 73
  • Hi,

    can we use this method table have 500000 records?

    thanks ananda

    commented on Jul 21 2012 1:05AM
    Ananda
    1493 · 0% · 13
  • I dont see any reason why this should not work. However, for larger tables, I would recommend an ssis package or the import/export wizard. The database publishing wizard is also worth a look

    commented on Jul 21 2012 1:14AM
    Jacob Sebastian
    1 · 100% · 32004
  • Hi Jacob

    A good and useful script. Does this work on SSMS 2008 though? Looks like it works on SSMS 2012. There are no such options in SSMS 2008. Not sure if 2008 R2 has this option.

    commented on Aug 20 2012 6:20AM
    Anurag
    2706 · 0% · 3
  • @Anurag: I believe this functionality exists within SSMS 2008 forward.

    commented on Aug 20 2012 8:13AM
    Marc Jellinek
    97 · 2% · 546
  • yes, it exists in SSMS 2008, however, the UI is slightly different, which may have caused the confusion.

    alt text

    commented on Aug 20 2012 11:27AM
    Jacob Sebastian
    1 · 100% · 32004
  • Ah yes it does. I should have checked the options. Thanks @Marc and @Jacob.

    commented on Aug 21 2012 1:44AM
    Anurag
    2706 · 0% · 3
  • HI Jacob,

    Fantastic script. i have taken the whole database(Any one database in 2008 R2) objects script into new query window with out data.

    Here my question is is this scripts works with SQL Server-2005??????

    Thanks in advance.

    commented on Jan 18 2013 5:48AM
    Bala Krishna
    85 · 2% · 642

Your Comment


Sign Up or Login to post a comment.

"SQL Server - Generating scripts for schema (and data) using SSMS 2008" rated 5 out of 5 by 12 readers
SQL Server - Generating scripts for schema (and data) using SSMS 2008 , 5.0 out of 5 based on 12 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]