【转】SQL语句删除和添加外键、主键
--删除外键
语法:alter table 表名 drop constraint 外键约束名
如:
alter table Stu_PkFk_Sc drop constraint FK_s
alter table Stu_PkFk_SC drop constraint FK_c
--添加外键
语法:alter table 表名 add constraint 外键约束名 foreign key(列名) references 引用外键表(列名)
如:
alter table Stu_PkFk_Sc
add constraint Fk_s
foreign key (sno)
references Stu_PkFk_S(sno)
go
--删除主键
语法:alter table 表名 drop constraint 主键约束名
如:
alter table Stu_PkFk_S drop constraint PK_S
go
--增加主键
语法:alter 表名 add constraint 主键约束名 primary key(列名)
alter table Stu_PkFk_S add constraint PK_S primary key (sno)
go
图形化操作参考:https://jingyan.baidu.com/article/5225f26b05a25de6fa0908ae.html
【转】SQL语句删除和添加外键、主键的更多相关文章
- SQL语句删除和添加外键、主键的方法
--删除外键 语法:alter table 表名 drop constraint 外键约束名 如: alter table Stu_PkFk_Sc drop constraint FK_s alter ...
- SQL语句获取数据库中的表主键,自增列,所有列
SQL语句获取数据库中的表主键,自增列,所有列 获取表主键 1:SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_U ...
- SQL语句(二)创建带主键和约束的数据表
内容摘要 创建带主键和约束的表 创建带组合主键和外键的表 1. 创建带主键和约束的表 Student (学生表) CREATE TABLE Student ( sclass ) NOT NULL, - ...
- sql数据库删除表的外键约束(INSERT 语句与 FOREIGN KEY 约束"XXX"冲突。该冲突发生于数据库"XXX",表"XXX", column 'XXX)
使用如下SQL语句查询出表中外键约束名称: 1 select name 2 from sys.foreign_key_columns f join sys.objects o on f.constra ...
- sql语句删除由于无主键导致完全重复的数据方法
sql语句删除由于无主键导致完全重复的数据方法 select distinct * into #Tmp from t_column drop table t_column select * into ...
- sql新建数据库表,及添加多个主键
create table tb_Modules(module_Id int identity(1,1) primary key, (自增)model_Name varchar(50) not nul ...
- Sql Server约束的学习一(主键约束、外键约束、唯一约束)
一.约束的分类 1.实体约束 实体约束是关于行的,比如某一行出现的值不允许出现在其他行,例如主键约束. 2.域约束 域约束是关于列的,对于所有行,某一列有那些约束,例如检查约束. 3.参照完整性约束 ...
- 用sql 语句给字段添加描述
用sql 语句给字段添加描述 IF not exists (SELECT * FROM ::fn_listextendedproperty (NULL, 'user', 'dbo', 'table', ...
- SQL语句删除重复数据
1.如表中没有主键,先添加自动增长主键 alter table 表名 add 列名 int identity (1,1) primary key 2.删除重复数据 delete from 表名 whe ...
随机推荐
- mysql简单语句
创建名为user的数据库: create database user; 显示所有数据库: show databases; 选择名为user的数据库: use user; 显示所有表: show tab ...
- 使用boost.python进行混合开发
使用boost.python进行混合开发 原文请参照官网和各方参考,本文有改动! 参考链接:http://blog.csdn.net/lanbing510/article/details/121979 ...
- 引用css样式的书写格式
css的书写格式一共有三种 行内样式:意思是在行内中写样式 例如说<p style="color:red">用行内样式编写我的颜色</p> 只适用于< ...
- (转)RabbitMQ学习之路由(java)
http://blog.csdn.net/zhu_tianwei/article/details/40887755 参考:http://blog.csdn.NET/lmj623565791/artic ...
- 8 Mistakes to Avoid while Using RxSwift. Part 1
Part 1: not disposing a subscription Judging by the number of talks, articles and discussions relate ...
- 创建一个dynamics CRM workflow (四) - Development of Custom Workflows
首先我们需要确定windows workflow foundation 已经安装. 创建之后先移除MyCustomWorkflows 里面的 Activity.xaml 从packages\Micro ...
- Java中数组遍历
就是将数组中的每个元素分别获取出来,就是遍历.遍历也是数组操作中的基石. 数组的索引是 0 到 lenght-1 ,可以作为循环的条件出现 public class ArrayDemo4 { publ ...
- redhat的systemd版本list
acess https://access.redhat.com/errata/#/ https://github.com/lnykryn/systemd-rhel redhat 知识库 redhat ...
- asyncio 自动跳出长时间堵塞的 task
https://www.cnblogs.com/ywhyme/p/10660411.html 的升级版 可以知道当前是卡在哪一个 task 甚至是多少行 import asyncio import o ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup
The last stage of Football World Cup is played using the play-off system. There are n teams left in ...