电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

外键约束和参绍约束的实例脚本


发布日期:2023/11/20
 

外键约束和参绍约束的实例脚本

/*外键约束和参绍约束pubs数据库的CarIfo表创建外键约束参绍CarFactory表的主键ID*/USE PubsGO/*不显示行数*/SET NOCOUNT ONGO/*创建示例表*/IF EXISTS (SELECT * FROM dbosysobjects WHERE id = object_id(NCarInfo) AND OBJECTPROPERTY(id NIsUserTable) = )DROP TABLE CarInfoGOCREATE TABLE CarInfo(Car_ID CHAR () Name CHAR () Type CHAR ()Driver_Type CHAR ())IF EXISTS (SELECT * FROM dbosysobjects WHERE id = object_id(NCarFactory) AND OBJECTPROPERTY(id NIsUserTable) = )DROP TABLE CarFactoryGOCREATE TABLE CarFactory(ID CHAR () NOT NULLName CHAR () PostCode CHAR ()Telphone CHAR ()Address CHAR ())GOALTER TABLE CarFactoryADD CONSTRAINT PK_Car_ID PRIMARY KEY NONCLUSTERED (ID)GOALTER TABLE CarInfoWITH NOCHECKADD CONSTRAINT Car_id_link FOREIGN KEY (Car_ID) REFERENCES CarFactory(ID)GOUSE masterEXEC sp_dboption Pubs dbo use only TRUEGOUSE PubsSET NOCOUNT ONGO

上一篇:轻松切换X窗口管理器

下一篇:详细介绍:安装0racle10g的艰难之旅