Link to home
Start Free TrialLog in
Avatar of donpick
donpick

asked on

Table variable and constraints

Running SQL server 2000  on Windows 2000 server

I have created a table variable.  I cannot seem to assign a primary key.
I get the error:
  Incorrect syntax near the keyword 'CONSTRAINT'.

See my code below:

What am I doing wrong?
DECLARE @tblAmibrokerRawTemp	table
    (Symbol		varchar(7)	NOT NULL	,
     EntryDate		smalldatetime	NOT NULL	
     	CONSTRAINT tblAmibrokerRawTemp_PK PRIMARY KEY(Symbol, EntryDate),
     Active		smallint	NOT NULL	DEFAULT 1)

Open in new window

Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

This should work:
DECLARE @tblAmibrokerRawTemp    table
    (Symbol             varchar(7)      NOT NULL        ,
     EntryDate          smalldatetime   NOT NULL        ,
     Active             smallint        NOT NULL        DEFAULT 1,
     CONSTRAINT tblAmibrokerRawTemp_PK PRIMARY KEY(Symbol, EntryDate)
)

Open in new window

i dont think you can do that with a table variable, you need to convert that into a temp table
you can assign pk's on table variables
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of donpick
donpick

ASKER

This is not documented anywhere I can find.  Thank you for your help.
it is documented,
see syntax part of table datatype from here
http://msdn.microsoft.com/en-us/library/ms175010.aspx