【2018-01-10】Sql Server-T-SQL语言基础

T-SQL语言是标准的SQL Server的扩展,是标准的SQL程序设计语言的增强版,是用以程序与SQL Server沟通的主要语言。T-SQL是SQL Server系统产品独有的,其他的关系数据库不支持T-SQL。

 

创建数据库:create database Data2018(数据库名);

删除数据库:drop database Data2018(数据库名);

创建表:

create table Student(表名)

  列名  数据类型,

  。。。

  。。。  

  设置主键列: primary key
  设置唯一列: unique
  设置非空:not null
  设置自增列:identity(1,1) - 从1开始计数,每次自增1 

  设置外键列:alter table 外键表名 add constraint 约束名称 foreign key(外键字段) references 主键表名(约束列名)

        如表A中的Ids是主键,要约束表B中的Aid列,那么语句应该是:

        alter table B add constraint A_B_Ids foreign key(Aid) references A(Ids)

删除表:drop table Student(表名);

    truncate table student(表名);  彻底删除释放内存

添加列:alter table Student(表名) add Class(列名) nvarchar(50)(数据类型);

删除列:alter table student(表名) drop column Class(列名);

添加数据:insert into student(表名)  values('S001','2000-1-1','true',100);

删除数据:delete from student(表名);  

     truncate table student(表名);  彻底删除释放内存

查询全部数据: select * from student(表名);

注释:一段 /*  */   

   一行 --

posted @ 2018-01-10 18:36  Int64  阅读(131)  评论(0编辑  收藏  举报