-
Composite Key on Table Data Type
I am trying to add indexes to my table data types and have realized that I can only add primary keys. So, I am hoping there is a way to add a composite primary key, but I am not having any success. I have tried the following:
Declare @Sales TABLE
(SaleID INT IDENTITY(100000,1),
SalesRegion CHAR(2),
CONSTRAINT ID_PK PRIMARY KEY (SaleID,SalesRegion))
Any suggestions would be appreciated.
Thanks!
-
Indexes or other constraints applied to the table data type must be defined as part of the DECLARE variable or CREATE FUNCTION statement. They cannot be applied later, because the CREATE INDEX or ALTER TABLE statements cannot reference table variables and user-defined functions. Check 'DECLARE @local_variable' in books online.
-
Rmiao,
I realize this is true. That is why in the above example I added the constraint as part of the declare statement. Are you saying that you think it can not be done? Or do you have an example of how to do it. I have reviewed the SQL documentation for Create Table and Declare many times before posting this.
Thanks!
-
Declare @Sales TABLE
(SaleID INT IDENTITY(100000,1),
SalesRegion CHAR(2),
PRIMARY KEY (SaleID,SalesRegion))
-
WizKid,
This is exactly what I wanted. I just coudn't get the syntax right. Thanks so much!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|