Notice (8): file_put_contents(): Write of 270 bytes failed with errno=28 No space left on device [CORE/src/Log/Engine/FileLog.php, line 140]

Notice: file_put_contents() [function.file-put-contents]: Write of 1108 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
Notice (8): unserialize() [<a href='https://secure.php.net/function.unserialize'>function.unserialize</a>]: Error at offset 94197 of 94197 bytes [APP/Controller/NewsController.php, line 5571]

Notice: file_put_contents() [function.file-put-contents]: Write of 2491 bytes failed with errno=28 No space left on device in /www/wwwroot/www.adminso.com/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 140
必须会的SQL语句(八)数据库的完整性约束 - 站长搜索
首页 > 资讯列表 > 编程/数据库 >> 数据库操作教程

必须会的SQL语句(八)数据库的完整性约束

数据库操作教程 2022-09-23 17:21:26 转载来源: 网络整理/侵权必删

实体完整性1.建表时定义主键 Createtable表名  (       Snointidentity(1,1),       Snamenvarchar(20),       --设置主键       Primarykey(Sno)  ) 2

实体完整性
1.建表时定义主键

  Create table 表名
   (
        Sno int identity(1,1),
        Sname nvarchar(20),
        --设置主键
        Primary key (Sno)
   )
 
2.添加主键

    alter table 表名
    add constraint PK_表名_Sno
    primary key(id)
参照完整性1.建表时定义外键

  create table 表名
  (
      sno int identity(1,1) primary key,
      cno int not null,
      foreign key(cno) References
      表名2(Cno)
      on Delete cascade     --级联删除
      on update cascade    --级联更新
      -- on delete on action  删除管制
  )
 
2.添加外键
   alter table 表名
   add constraint FK_表名_表名2
   Foreign key(cid) references 表名2(cid)
用户定义完整性1.非空约束
   alter table 表名
   alter column name varchar(20) not null
 
2.唯一约束
   alter table 表名
   add constraint UQ_表名_列名 unique(列)
 
3.检查约束
   alter table 表名
   add constraint CK_表名_列名 check(age>5)
 
4.默认约束
   alter table 表名
   add constraint DF_表名_列名 default('男')
   for gender
删除约束    --删除约束
   alter table 表名 drop constraint DF_表名_列

标签: 必须 会的 SQL 语句 数据库 完整性 约束


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2025 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持