Thursday, December 7, 2017

SQL SERVER - How create table with constraint on column

This example shows creating table with constraint on column [type]. Allowed values are "I", "E" and "W" (..and null, column is not mandatory).
create table [logs]
( 
  id int not null primary key identity,
  [date] datetime default getdate(),
  /* I=info; E=error, W=warning */
  [type] varchar(1) check ( [type] in ( 'I', 'E', 'W' ) ),
  [description] nvarchar( 1024 ),
  [data_group] varchar( 10 )
)

No comments:

Post a Comment