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 种一般性操作的更多相关文章

  1. 浅谈SQL Server中的三种物理连接操作

    简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge J ...

  2. SQL Server中的三种物理连接操作

    来源:https://msdn.microsoft.com/zh-cn/library/dn144699.aspx 简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Out ...

  3. 浅谈SQL Server中的三种物理连接操作(HASH JOIN MERGE JOIN NESTED LOOP)

    简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge J ...

  4. 浅谈SQL Server中的三种物理连接操作(Nested Loop Join、Merge Join、Hash Join)

    简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge J ...

  5. SQL Server 中的6种事务隔离级别简单总结

    本文出处:http://www.cnblogs.com/wy123/p/7218316.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...

  6. SQL Server中的三种Join方式

      1.测试数据准备 参考:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek 这篇博客中的实验数据准备.这两篇博客使用了相同的实验数据. 2.SQ ...

  7. SQL Server中的Image数据类型的操作

    原文:SQL Server中的Image数据类型的操作 准备工作,在库Im_Test中建立一张表Im_Info,此表中有两个字段,分别为Pr_Id (INT),Pr_Info (IMAGE),用来存储 ...

  8. .net(C#数据库访问) Mysql,Sql server,Sqlite,Access四种数据库的连接方式

    便签记录Mysql,Sql server,Sqlite,Access四种数据库的简单连接方式 //using MySql.Data.MySqlClient; #region 执行简单SQL语句,使用M ...

  9. SQL server分页的四种方法

    SQL server分页的四种方法 1.三重循环: 2.利用max(主键); 3.利用row_number关键字: 4.offset/fetch next关键字 方法一:三重循环思路  先取前20页, ...

随机推荐

  1. Pseudoprime numbers(POJ 3641 快速幂)

    #include <cstring> #include <cstdio> #include <iostream> #include <cmath> #i ...

  2. Stall Reservations(POJ 3190 贪心+优先队列)

    Stall Reservations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4434   Accepted: 158 ...

  3. Stars(BIT树状数组)

    Stars Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  4. Hits per second 下降的几个原因

    1.首先看看服务器的资源消耗情况,可能是服务器 处理不了那么多请求, 有很多请求都在等待,此时可以监控一下服务器的资源 看看是不是有很多等待队列 是不是有很多的等待的请求,可用vmstat命令,第一个 ...

  5. Primo Ramdisk配置教程

    首先感谢xiaohu在太平洋电脑网上发表的“将内存当硬盘用!Primo Ramdisk图文教程”,本文主要是将其图文整理了一下,以方便以后使用. 原文地址:http://fashion.pconlin ...

  6. SQL Server 索引的自动维护 <第十三篇>

    在有大量事务的数据库中,表和索引随着时间的推移而碎片化.因此,为了增进性能,应该定期检查表和索引的碎片,并对具有大量碎片的进行整理. 1.确定当前数据库中所有需要分析碎片的表. 2.确定所有表和索引的 ...

  7. perl return和break

    zjzc01:/root/test# cat a3.pl sub mask { my $n=shift; my $j =100; for ($i = 1;$i <= 5;$i++){ print ...

  8. LeeCode-Single Number II

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  9. JAVA JNI

    jni非常好的一篇文章 http://m.blog.csdn.net/article/details?id=22827307 JAVA JNI介绍 http://blog.csdn.net/cyg08 ...

  10. 文件MD5

    package mainimport (    "crypto/md5"    "fmt"    // "github.com/astaxie/bee ...