SQL简短汇总

建立数据库:

create database 数据库名
on
(
name=数据库名_dat;
filename='****数据库位置*****\数据库名.mdf',
size=**,
maxfile=**,
filegrowth=10%
)
log on
(
name=数据库名_log,
filename='****数据库位置*****\数据库名.ldf',
size=**,
maxfile=**,
filegrowth=10%
)

删除数据库:
drop database 数据库名;



建立数据库的表:
create table 表名
(
列名 数据类型 ({可加可不加}约束),  --主键:primary key
列名 数据类型 ({可加可不加}约束),
....
列名 数据类型 ({可加可不加}约束)
)
---数据类型:int、varchar、char...
---约束: not null、

删除表:
drop table 表名;



表中添加数据:
insert into 表名(列名1,列名2,...列名n)
values (列值1,列值2,...列值n);
----字符串类型的列值用单引号引起来;
---当添加表中所有数据时,表名后的列名可不写

删除表中的数据:
delete from 表名 where 表中的列名满足的条件;

修改表中数据:
update  表名 set 列名=“表达式(要修改的内容)”
where 条件表达式;

删除表中的所有数据:
truncate table 表名;


查询表中的数据:
select * from 表名  where 条件表达式;














添加表的列:
alter table 表名 add 列名 数据类型;
删除列:
alter table 表名 drop 列名;
修改列的数据类型:
alter table 表名 alter column 列名 数据类型;
更改列名:
sp_rename '表名.旧列名','新列名';

更改表名:
sp_rename '数据库名.旧表名','新表名';


posted on 2015-05-04 20:40  冰冥寒流  阅读(120)  评论(0编辑  收藏  举报