SQL Server 对表的 12 种一般性操作
01、
创建
create table Strings(ID int);
go
02、
为表添加列
alter table Strings
add String nvarchar(32);
go
03、
添加计算列
alter table Strings
add ID2 as (ID+1);
go --- 看到了没有这里不用指定type了。
04、
修改定义
alter table Strings
alter column ID int not null;
go --- 对于计算列要先drop再add
05、
删除列
alter table Strings
drop column ID2;
go --- 删除时要加column添加时不要column因为根据添加的内容就可以看出加的是什么东西。
06、
为表加主键
alter table Strings
add constraint PK_ID primary key(ID);
go
07、
为表加外键
alter table Strings
add constraint FK_A
foreign key (String) references T(S);
go --- create table T(S nvarchar(32)not null primary key);
alter table Strings
add constraint FK_A
foreign key (String) references T(S) on delete cascade on update cascade;
go --- no action ,cascade,set null,set default
08、为表加uniqu约束
alter table Strings
add constraint unique_A unique(String);
go
09、
为表加check约束
alter table Strings
add constraint CK_A
check(String != '007');
go
10、
为表加default约束
alter table Strings
add constraint DF_A
default '1234656' for String;
go
11、
禁用约束
alter table Strings
nocheck constraint FK_A;
go
alter table Strings
nocheck constraint all; ---禁用所有约束
alter table Strings
check constraint all; ---启用所有约束
12、
删除约束
alter table Strings
drop constraint FK_A;
go
SQL Server 对表的 12 种一般性操作的更多相关文章
- 浅谈SQL Server中的三种物理连接操作
简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge J ...
- SQL Server中的三种物理连接操作
来源:https://msdn.microsoft.com/zh-cn/library/dn144699.aspx 简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Out ...
- 浅谈SQL Server中的三种物理连接操作(HASH JOIN MERGE JOIN NESTED LOOP)
简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge J ...
- 浅谈SQL Server中的三种物理连接操作(Nested Loop Join、Merge Join、Hash Join)
简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge J ...
- SQL Server 中的6种事务隔离级别简单总结
本文出处:http://www.cnblogs.com/wy123/p/7218316.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...
- SQL Server中的三种Join方式
1.测试数据准备 参考:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek 这篇博客中的实验数据准备.这两篇博客使用了相同的实验数据. 2.SQ ...
- SQL Server中的Image数据类型的操作
原文:SQL Server中的Image数据类型的操作 准备工作,在库Im_Test中建立一张表Im_Info,此表中有两个字段,分别为Pr_Id (INT),Pr_Info (IMAGE),用来存储 ...
- .net(C#数据库访问) Mysql,Sql server,Sqlite,Access四种数据库的连接方式
便签记录Mysql,Sql server,Sqlite,Access四种数据库的简单连接方式 //using MySql.Data.MySqlClient; #region 执行简单SQL语句,使用M ...
- SQL server分页的四种方法
SQL server分页的四种方法 1.三重循环: 2.利用max(主键); 3.利用row_number关键字: 4.offset/fetch next关键字 方法一:三重循环思路 先取前20页, ...
随机推荐
- nginx+mysql+php
根据生产环境安装操作系统(centos 6.0 64位系统),安装完成后,使用Xshell通过ssh协议连接服务器.ssh 用户名@IP+回车+输入密码后登录系统.#mkdir -p /home/to ...
- javascrit字符串截取
昨天遇见一个问题就是一个地址后面加参数第一次是需要添加参数,以后每次点击按钮的时候是替换如果不进行处理的话如果页面不刷新,地址会不断的添加越来越长,所以
- Database Go and JSON
在使用Go开发web项目的过程中, 数据库读写操作与JSON格式的输入输出是两块最基础的模块, Go的标准库已经帮我们做了很多, 熟悉database/sql与encoding/json这两个库能帮我 ...
- centos 6.5 安装 nginx+php+mysql
一.准备工作 (1)配置防火墙 1.首先检查iptables服务的状态 [root@woxplife ~]# service iptables status iptables: Firewall is ...
- TabHost刷新activity的方法
在android中,使用tabHost的时候,如果tab被点击,该tab所对应的activity被加载了,从别的tab切换回来的时候,activity不会再次被创建了(onCreate),所以要想每次 ...
- logstash grok 解析Nginx
log_format main '$remote_addr [$time_local] "$request" ' '$request_body $status $body_byte ...
- bzoj1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of wh ...
- 如何理解 css3 的 perspective 属性
一.写在前面的话 最近想多了解一下CSS3的transform 3D效果,transform:英文直译就是转换,它可以实现旋转.缩放.位移等效果,听起来有没有觉得很酷的样子,狠狠的点这里来看看旋转和位 ...
- 括号匹配问题(C++、堆栈)
原文地址:http://www.cppblog.com/GUO/archive/2010/09/12/126483.html /* 括号匹配问题,比较经典,利用堆栈来实现(摘自internet) 1. ...
- Trapping Raining Water 解答
Question Given n non-negative integers representing an elevation map where the width of each bar is ...