sql - How To add composite unique key to user defined table Type -
how add composite unique key user defined table type :
create type [dbo].[jobdata] table( [emp_num] [smallint] null, [job_date] [date] null, [year] [smallint] null, [job_code] [smallint] null, [order_year] [smallint] null, [order_ser] [decimal](5, 0) null, ) go
i want emp_num,job_date
composite unique key .
you can't alter userdefined table types ,you need drop , recreate again changes..
user-defined types cannot modified after created, because changes invalidate data in tables or indexes. modify type, must either drop type , re-create it, or issue alter assembly statement using unchecked data clause.
below way create unique constraint on userdefined table type
create type test table ( col1 varchar(50) , col2 int , unique (col1,col2) );
note:we can't name constraints,so creating constraints normal way not valid..
example below
create type test table ( col1 varchar(50) , col2 int , constraint test unique (col1,col2) );
Comments
Post a Comment