Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

script Table as Create via SSMS doesn't show unique index

Using SQL Server Management Studio 2008, why can't I see unique index ( not primary key ) when I generate Create Table SQL code?

It includes only primary key constraint. Is it by design ? There is a possibility to get SQL code for index creation via right mouse click on an index and "Script index as", but it is another step.

like image 272
MicMit Avatar asked Jun 18 '10 06:06

MicMit


People also ask

How do I add a unique index to a table?

Right-click the table on which you want to create a unique index and select Design. On the Table Designer menu, select Indexes/Keys. In the Indexes/Keys dialog box, click Add. Select the new index in the Selected Primary/Unique Key or Index text box.

Does unique key CREATE INDEX SQL Server?

We know that the unique constraint in SQL Server creates a unique SQL Server index as well. SQL Server allows us to disable an index as well without dropping it.


2 Answers

Is the "Script Unique Keys" option set to TRUE in your SSMS?

In SSMS, Tools -> Options will get you to the pop-up window shown below. alt text

like image 100
Joe Stefanelli Avatar answered Oct 01 '22 20:10

Joe Stefanelli


Note that in SSMS 2012, you have to set "Script indexes" to TRUE to script out unique indexes.

SSMS 2012 Screenshot

like image 21
TimS Avatar answered Oct 01 '22 20:10

TimS