惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
月光博客
月光博客
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
Stack Overflow Blog
Stack Overflow Blog
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
宝玉的分享
宝玉的分享
A
About on SuperTechFans
Vercel News
Vercel News
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
Jina AI
Jina AI
Y
Y Combinator Blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI

博客园 - 潘伟

linux下快速查找文件大全 终于明白vi的用法了 什么是虚拟主机,为什么要使用虚拟主机? 一个存储前辈的一些业界知识(待了解) 10秒为任意数据库增加执行日志功能 - 潘伟 - 博客园 运动会的收获 从无奈到偷笑 一曲彩虹天堂 使用sql server中的全文索引经过大体的4个步骤 索引的创建 经常遇到的字段合并的问题 匹配符详解 数据库中的正则表达试 系统表的应用 使用SQLServer2000 发送邮件详细配置过程 求记录中的最新数据的方法! 关于sql mail的配置问题(微软技术支持) 数据库设计范式深入浅出 锁定数据库的一个表_概述
约束的使用
潘伟 · 2005-11-21 · via 博客园 - 潘伟

使用约束
1.使用 primary key 约束
  其值能唯一的标识表中的每一行。这样的一列或多列成为表的主键,通过它可强制表的实体完整性。
 
  job_id int primary key clustered
  
  emp_id empid constraint pk_emp_id primary key nonclustered
2.使用foreign key 约束
   约束引用其他的表
   job_id samllint not null  references jobs(job_id)
  
  foreign key(job_id) references jobs(job_id)
 
 constraint fk_sales foreign key(stor_id,orde_num,title_id)
 references sales(stor_id,ord_num,title_id)
3.使用unique 约束
  unqiue约束用于强制非主键列的唯一性,允许存在空值(应该只有一个)
  person varchar(30) null unique nonclustered

 constraint u_store unique nonclustered(stor_name,city)
4.使用default定义
 使用insert和update语句时,如果没有提供值,则使用默认值。
 提供了默认值,  用dbgrid 编辑必须在onnewrecord 事件加上默认值的赋值,否则提示错误
 ‘row can not be located for updating.some values has been changed since it was last read '  
 default(getdate())
 创建一个产品价格表,并且设置产品的改价者为当时增修改数据的用户
 create table price
(
  prod_id char(5),
  sup_id   char(5),
 unit_price money,
 modifier char(5)
 modi_date datetime default getdate(),
 primary key(prod_id,sup_id)
 default user for modifier
)
5.使用check约束

  check(min_lvl>=10)  
  check(max_lvl<=250)

 constraint ck_emp_id check (emp_id like '[a-z][a-z][a-z][1-9][0-9][0-9][0-9][0-9]'
 or emp_id like [a-z][a-z][1-9][0-9][0-9][0-9][0-9]')
  
 check (pub_id in ('1389','0736','0877') or pub_id like'99[0-9][0-9]')