SQL中的数据约束

制作人:丁琪 QQ:854804038

一、对数据库jwgl,按要求建立以下约束

1、 为student表中年龄字段添加检查约束,使字段值限制在15—30岁之间。

SQL 2005 中的数据约束_style

SQL 2005 中的数据约束_制作人_02

SQL 2005 中的数据约束_制作人_03

2、 student表中student_name字段添加唯一约束。

SQL 2005 中的数据约束_style_04

SQL 2005 中的数据约束_制作人_05SQL 2005 中的数据约束_制作人_06

SQL 2005 中的数据约束_sql_07

3、 为student表中entrance_date入学日期字段添加默认值约束。

SQL 2005 中的数据约束_制作人_08

SQL 2005 中的数据约束_数据库_09

4、 为表student、class_info表设置主键约束。

SQL 2005 中的数据约束_数据库_10

SQL 2005 中的数据约束_style_11

5、 为student表中class_id字段添加外键约束,

SQL 2005 中的数据约束_blank_12

SQL 2005 中的数据约束_style_13

6、 为course表中student_id字段添加外键约束。

SQL 2005 中的数据约束_制作人_14

SQL 2005 中的数据约束_数据库_15

7、 删除创建的唯一约束。

ALTER TABLE 表名

DROP CONSTRAINT 约束名

例如:Alter table student drop constraint IX_student*

二、对数据库market,按要求建立以下索引

1、为customers表的lastname、firstname列组合创建一个惟一性的非聚簇索引SQL 2005 中的数据约束_制作人_16

SQL 2005 中的数据约束_style_17

3、为orders表的orderid列创建一个惟一性的聚簇索引,索引排列顺序为降序。

SQL 2005 中的数据约束_sql_18

SQL 2005 中的数据约束_数据库_19