Sqlserver-dba.com

SQL Table variables do not support indexes MYTH

False. Let’s look at the definition of a table variable:

 DECLARE @myTableVar TABLE

(companyID INT NOT NULL,

 companySize INT NOT NULL)

 The constraints allowed on table variables are : PRIMARY KEY,UNIQUE KEY and NULL.

 A PRIMARY KEY constraint can only be defined if certain criteria are met: No duplicate values

A UNIQUE KEY Creates a unique index on a table or view. A unique index is one in which no two rows are permitted to have the same index key value

 To create a PRIMARY KEY constraint :

 DECLARE @myTableVar TABLE

(companyID INT PRIMARY KEY,

 companyName INT NOT NULL

)

 

 

Source:Jack Vamvas (http://www.sqlserver-dba.com)


Author: Jack Vamvas (http://www.sqlserver-dba.com)

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact