PrincipleandApplicationofDatabaseSystemAnQingTeachersCollegeDepartmentofComputer&Information数据库原理与应用PrincipleandApplicationofDatabasesystem安庆师范学院计算机与信息学院PrincipleandApplicationofDatabaseSystem13
1在表中定义及删除默认值约束1
默认值约束的定义1)定义表结构时定义字段的默认值约束语法格式:CREATETABLEtable_name/*指定表名*/(column_namedatatypeNOTNULL|NULL[DEFAULTconstraint_expression]/*默认值约束表达式*/[,…n])/*定义列名、该列的数据类型、是否空值及默认值约束*/PrincipleandApplicationofDatabaseSystem例1对于student数据库,定义studentx表时定义ssex字段的默认值约束为男
CREATETABLEstudentx(snochar(5)PRIMARYKEY,snamechar(8),ssexchar(2)DEFAULT'男',sbirthdaydatetime,classchar(5))PrincipleandApplicationofDatabaseSystem2)修改表添加一个字段的同时定义相应的约束语法格式:ALTERTABLEtable_name/*指定表名*/ADDcolumn_namedatatypeNOTNULL|NULLCONSTRAINTconstraint_name/*指定约束名*/DEFAULTconstraint_expressionWITHVALUES/*默认值约束表达式*/Principlea