数据库 t-sql 语句

create database student --新建数据库
drop database student--删除数据库
use  student--使用数据库

create table xuesheng --新建表
(
 ids int ,
 code nvarchar(20) primary key, --表的内容  设置主键
 name nvarchar(20) not null,--不允许为空
 birthday datetime unique,--设置唯一键
 chengji decimal(10,3)

)
drop table xuesheng --删除表


select *from xuesheng--查询表
insert into xuesheng values(1,'s001','名字','2000-1-2','20.2')--添加内容
insert into xuesheng values(2,'soo2','张三','2000-3-2',20.2)

update xuesheng set name='赵四'--修改内容    

 

t-sql  语句入门

数据库名列名  表名都不能用中文

新建数据库

create database   数据库名称 

drop database 数据库名称

 

新建表的时候注意在哪个数据库中进行

use   数据库名称    使用这个数据库

新建表时要加上内容再新建

create table  表名      新建一个表

(括号里面是表的内容    最前面的单词是列明    列名后面跟类型 

 ids int identity (1,1) ,  设置自增列   从一开始  没列加1
 code nvarchar(20) primary key, --表的内容  设置主键
 name nvarchar(20) not null,--不允许为空
 birthday datetime unique,--设置唯一键
 chengji decimal(10,3)   小数类型  10代表可以有10位,   3代表小数点后边3位

drop table 表名   删除表

truncate table xuesheng--清除所有表格

(删除表是一行一行一行的删除   truncate 是全部都清楚  不可恢复)

select *from 列名   查询表

insert  into  表名 values(需要添加的内容  nvarchar date time 类型需要加单引号  int 类型 decimal 类型可以不用加)

顺序要跟建表时顺序相同

insert into xuesheng values(1,'s001','名字','2000-1-2','20.2')--添加内容

 

update xuesheng set name='赵四'--修改内容

update 表名  set  列名 =要修改的内容            

将这一列内容全部修改

添加列:alter table 表名 add 列名 数据类型
删除列:alter table 表名 drop column 列名

 

posted @ 2017-03-10 11:41  v587yy  阅读(279)  评论(0编辑  收藏  举报