天道酬勤。。。

SQL-列约束

上一篇 / 下一篇  2007-07-01 23:40:17 / 天气: 晴朗 / 心情: 高兴 / 个人分类:数据库

1、候选键和主键约束
如:create table employee
    (name char(20),
     birthday date,
     id int,
     primary key(id)
     unique(name))
unique用来指定候选键,表明name的值不能重复。一个表中可以有多个候选键。候选键可以是多个列的组合.
但是只能有一个主键,用primary key进行定义。主键不能为空。主键可以是多个列的组合.

2、外部键约束:foreign key和references定义外部键约束。外键可以为空.
如: create table employee
    (name char(20),
     birthday date,
     id int,
     dno int
     references department(dnumber),
     primary key(id)
     unique(name)
     )
或放在最后:
create table employee
    (name char(20),
     birthday date,
     id int,
     dno int,
     primary key(id)
     unique(name)
     foreign key(dno) references department(dnumber)
     )

3、null 与 not null约束:

4、校验约束:check创建校验约束,使用任何运算符来确定条件。
如:create table employee
    (name char(20),
     sex  char(10),
     birthday date,
     salary numeric(10,2)
     check(salary>1000.00)
     )

5、默认值(default)
create table employee
    (name char(20),
     sex  char(10)
     default '男',
     birthday date    
     )


TAG: 数据库

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-17  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 3769
  • 日志数: 8
  • 建立时间: 2006-12-29
  • 更新时间: 2007-07-03

RSS订阅

Open Toolbar