增加主键:
use accounting
alter  table  employee
add  constraint  pk_employeeid
primary key (id)
增加唯一性约束:
alter    table    employee
add  constraint   ak_employeeSSN
unique(ssn)这个constraint是什么意思来的,是不是增加主\外键、唯一性约束都要用这个单词的啊?

解决方案 »

  1.   

    /*
    constraint
    KK: []
    DJ: []
    n.
    1. 约束;限制[C][(+on)]
    legal constraints on the company's activities
    对该公司活动法律的限制
    2. 强迫;强制[U]
    He acted under constraint.
    他被迫采取行动。
    3. 抑制;拘束;态度不自然[U]
    She showed constraint in the presence of the strangers.
    她在陌生人面前显得很拘束。
    4. 拘禁[U]
    5. 拘束(或限制)的事物[C]
    */
      

  2.   

    SQL约束控制 
     1)禁止所有表约束的SQL 
     select ''alter table ''+name+'' nocheck constraint all'' fromwhere type=''U'' 
     2)删除所有表数据的SQL 
     select ''TRUNCATE TABLE ''+name from sysobjects '' 
     3)恢复所有表约束的SQL 
     select ''alter table ''+name+'' check constraint all'' from type=''U'' 
     4)删除某字段的约束 
     declare @name varchar(100) 
     --DF为约束名称前缀 
     selectb.name from syscolumns a,sysobjects b where a.id=object_id(''表名'') and b.id=a.cdefault ''字段名'' and b.name like ''DF%'' 
     --删除约束 
     alter table 表名 drop constraint @name 
     为字段添加新默认值和约束 
     ALTER TABLE 表名 ADD CONSTRAINT @name DEFAULT (0) FOR [ 
     对字段约束进行更改 
     --删除约束 
     ALTER TABLE tablename 
     Drop CONSTRAINT 约束名 
     --修改表中已经存在的列的属性(不包括约束,但可以为主键或递增或唯一) 
     ALTER column 列名 int not null 
     --添加列的约束 
     ALTER TABLE tablename 
     ADD CONSTRAINT DF_tablename_列名 DEFAULT(0) FOR 列名 
     --添加范围约束 
     alter table tablename (''M'',''F''))
      

  3.   

    constraint ---英文翻译为:约束、限制 
    是关键字