Create Named CHECK Constraint It's a good practice to createnamed constraintsso that it is easier to alter and drop constraints. Here's an example to create a namedCHECKconstraint: -- create a named constraint named amountCK-- the constraint makes sure that amount is greater than 0CREATETABL...
SQL CHECK on CREATE TABLE The following SQL creates aCHECKconstraint on the "Age" column when the "Persons" table is created. TheCHECKconstraint ensures that the age of a person must be 18, or older: MySQL: CREATETABLEPersons ( ID intNOTNULL, ...
/***在创建表后添加默认约束***/--创建People表--createtablePeople( Uidintidentity(1,1)primarykey,--主键约束--Namevarchar(20)notnullunique,--唯一约束--HomeAdressvarchar(50)notnull,--默认约束--Notesvarchar(100)null)--添加默认约束--altertablePeopleaddconstraintDF_People_HomeAddressdefault'未填写'...
drop table 表名; go --创建表 create table 表名 ( --字段声明 列名int identity(1,1) not null, 列名nvarchar(50) null, 列名nvarchar(50) null constraint 约束名 check(约束规则), 列名nvarchar(50) null, 列名int, 列名int constraint 约束名 check(约束规则) primary key clustered(列名 asc) with(...
] referenced_table_name [ ( ref_column ) ] | CHECK ( logical_expression ) } <table_constraint> ::= [ CONSTRAINT constraint_name ] { { PRIMARY KEY | UNIQUE } { NONCLUSTERED ( column_name [ ASC | DESC ] [ ,... n ]) | NONCLUSTERED HASH ( column_name [ ,... n ] ) WITH ...
AlterTable 表名 DropConstraint 约束名 附加:在创建表的时候同时添加约束的写法: use stuDB go if exists(select *from Sysobjectswherename ='stuInfo') droptable stuInfo go createtable stuInfo ( stuNamevarchar(20)notnullprimarykey(stuName)
CREATE TABLE (Transact-SQL) 在SQL Server 2008 R2 中创建新表。 Transact-SQL 语法约定 语法 CREATE TABLE [ database_name . [ schema_name ] . | schema_name . ] table_name ( { <column_definition> | <computed_column_definition> | <column_set_definition> | [ <table_constraint> ] [ ,....
SQL>CREATETABLEtb_constraint_1 2( 3empno NUMBERPRIMARYKEY,--主键约束 4ename VARCHAR2(20)NOTNULL,--非空约束 5email VARCHAR2(60)UNIQUE,--唯一约束 6salNUMBER(5)CHECK(sal>1500),--核查约束 7deptno NUMBER(4)REFERENCEStb_dept(deptno)--外键约束 ...
< table_constraint > ::= [ CONSTRAINT constraint_name ] { { PRIMARY KEY | UNIQUE } [ CLUSTERED | NONCLUSTERED ] (column [ ASC | DESC ] [ ,...n ] ) [ WITH FILLFACTOR = fillfactor |WITH ( <index_option> [ , ...n ] ) ...
SQL> CREATE TABLE tb_constraint_1 2 ( 3 empno NUMBER PRIMARY KEY, --主键约束 4 ename VARCHAR2(20) NOT NULL, --非空约束 5 email VARCHAR2(60) UNIQUE, --唯一约束 6 sal NUMBER(5) CHECK(sal>1500), --核查约束 7 deptno NUMBER(4) REFERENCES tb_dept(deptno) --外键约束 ...