Professional Documents
Culture Documents
Not Null
USE SQLDemo
GO
CREATE TABLE ConstraintDemo1
(
ID INT NOT NULL,
Name VARCHAR(50) NULL
)
Unique Constraint
SELECT CONSTRAINT_NAME,
TABLE_SCHEMA ,
TABLE_NAME,
CONSTRAINT_TYPE
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_NAME='ConstraintDemo2'
Primary Key
Check Constraint
cust_name char(50),
cust_address char(50),
cust_credit_limit money,
Foreign Key
part_name char(30),
part_weight decimal(6,2),
part_color char(15) );
(order_nmbr int,
part_nmbr int
ON DELETE NO ACTION,
qty_ordered int);
GO
CASCADE specifies that all the rows with foreign keys pointing to the
deleted row are also deleted.
SET NULL specifies that all rows with foreign keys pointing to the deleted
row are set to NULL.
SET DEFAULT specifies that all rows with foreign keys pointing to the
deleted row are set to their default value. For more information,
see Defaults.
Default Constraint
create table dbo.CustomerReport
(
customer_id int,
report_id int,
rundate datetime not null
constraint df_CustomerReport_rundate default getdate()
)
go