SQLcommitted

Committed with SQL

SQL Server – Customize Database object Script

SSMS provides functionality to generate script for database objects. I’ve seen developer use this functionality to generate script for various objects like Tables, Procedures, Triggers and other database objects but after generating the script they manually modify the generated scripts. When I asked one of the developers why you need to modify the generated scripts? He said the generated script is not meeting his requirement.

Below are some of the requirements –

  • Script should not start with USE <database name>.
  • It should check for existence of the object prior to the create statement.
  • It should include collation
  • If the object is Table or view it should generate scripts for all the associated index and Triggers.

SSMS allow to customize our script as per our requirement. SSMS has options to customize it.

Follow below steps to customize your scripts.

Step 1 – Go to Tools – Option. It will open the Option Page

image

Step 2 – Click on SQL Server Object Explorer and select Scripting

image

Step 3 – On left side panel you can find various customization option grouped into below three categories.

  • General scripting options
  • Object scripting options
  • Table and view options

You can set these options as per your requirement.

Example: If you don’t want Use <Database name> statement at the beginning of your script then Set Script USE <database> to false.

image

If you liked this post, do like on Facebook at https://www.facebook.com/s4sql

About these ads

November 22, 2012 - Posted by | SSMS Environment Settings | , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 76 other followers

%d bloggers like this: