CHECK CONSTRAINT ERROR USING SQL MANAGEMENT STUDIO -
create table [dbo].[sales] ( [saleid] [uniqueidentifier] not null default newid(), [productid] [int] not null, [workid] [int] not null, [quantity] [smallint] not null, [saledate] [datetime] not null constraint df_saledate default (getdate()) constraint chk_quantitysaledate check (quantity > 0 , datediff (d,getdate(), saledate) <=0) ) on [primary]
trying execute above query results in following error:
"column check constraint column 'saledate' references column, table 'sales'."
can please enlighten me?
it's because setting constraint column constraint. have set table constraint. so, after:
[saledate] [datetime] not null constraint df_saledate default (getdate())
you need comma sign, should be:
[saledate] [datetime] not null constraint df_saledate default (getdate()), constraint...
Comments
Post a Comment