Generate DDL Script including index with SQL Server Management Studio

Generate DDL Script including index with SQL Server Management Studio for Database

Include the Index option while generating the Database script from Generate Script button.

  1. Open the SQL Management Studio
  2. Right Click on the Database
  3. Select ALL TASK –> Generate SQL Scripts

4. Choose according to your need which objects you want to generate the Scripts:

5. Press Next and if you want to include the indexes with the script or any drop statement you need to click on the advance option as shown:

6. Open the advanced option and turn True which you want to include default index include option is false,

7. Generate the Script of the database that will have index DDL also.

7. Verify the script has index:

/****** Object:  Index [AK_Shift_Name]    Script Date: 9/28/2022 9:39:18 PM ******/
CREATE UNIQUE NONCLUSTERED INDEX [AK_Shift_Name] ON [HumanResources].[Shift]
(
	[Name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
/****** Object:  Index [AK_Shift_StartTime_EndTime]    Script Date: 9/28/2022 9:39:18 PM ******/
CREATE UNIQUE NONCLUSTERED INDEX [AK_Shift_StartTime_EndTime] ON [HumanResources].[Shift]
(
	[StartTime] ASC,
	[EndTime] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.