数据库定义语言:create alter drop declare
数据操作语言:select delete update insert
数据控制语言:grant revoke commit rollback
//创建数据库
create database Test1
//删除数据库
drop database Test1
//备份sqlserver
use master
backup database pubs to test
//创建新表
create table tableName
//删除新表
drop table tableName
//增加一列
alter table tableName add column col type;
//添加主键
alter table tbName add primary key(col)
//删除主键
alter table tbName drop primary key(col)
//创建索引
create index indexName on tabname(col)
//删除索引
drop index indexName;
//创建视图
craate view viewName as select * from test;
//删除视图
drop view veiwName;
选择
select * from table wehre
范围
insert into table (1,1) value
//删除
delete from table wehre
//范围更新
update table set field=1 wehre
//范围查找
select *from table wehre field like'%你%'
//排序
select * from table order by id desc
//总数
select count(*) from table;
//求和
select sum(field) as sum form table;
//平均
Selsect avg(field) as avg from table;
//最大
select max(fiedl) as max from table;
//最小
select min(field) as min from table;
//union运算词
union运算符通过组合其他两个结果表,并消去表中的任何重复行,派生出一个结果表
except 运算符
except 原酸符通过包括所有在table中但不再table中的行table2zhong d
12使用外连接
left outer join :左外链接:结果集包括连接表的匹配行,包括做链接的左右行
全外链接
full outer join 包括两个链接表中的所有的记录
//拷贝表
insert into b(1,1,1) select 1,1,1from b;
//子查询
select * from b where id in(select id from d);
//between的用法
select *from table where time between 2012 and 2014
//in的用法
delete from table where a in('1','2','3');
//两张表删除主表中在附表中没有的信息
delete from table where not exists(select * from wehre table 2)
//查询前10条数据
select top(10)* from table where
//
//选择随机的记录
select newid()
//显示数据库所有的表名
select name from sysobjects where type="u"
//选择10到15的记录
select top(5) * from (select top15)
数据操作语言:select delete update insert
数据控制语言:grant revoke commit rollback
//创建数据库
create database Test1
//删除数据库
drop database Test1
//备份sqlserver
use master
backup database pubs to test
//创建新表
create table tableName
//删除新表
drop table tableName
//增加一列
alter table tableName add column col type;
//添加主键
alter table tbName add primary key(col)
//删除主键
alter table tbName drop primary key(col)
//创建索引
create index indexName on tabname(col)
//删除索引
drop index indexName;
//创建视图
craate view viewName as select * from test;
//删除视图
drop view veiwName;
选择
select * from table wehre
范围
insert into table (1,1) value
//删除
delete from table wehre
//范围更新
update table set field=1 wehre
//范围查找
select *from table wehre field like'%你%'
//排序
select * from table order by id desc
//总数
select count(*) from table;
//求和
select sum(field) as sum form table;
//平均
Selsect avg(field) as avg from table;
//最大
select max(fiedl) as max from table;
//最小
select min(field) as min from table;
//union运算词
union运算符通过组合其他两个结果表,并消去表中的任何重复行,派生出一个结果表
except 运算符
except 原酸符通过包括所有在table中但不再table中的行table2zhong d
12使用外连接
left outer join :左外链接:结果集包括连接表的匹配行,包括做链接的左右行
全外链接
full outer join 包括两个链接表中的所有的记录
//拷贝表
insert into b(1,1,1) select 1,1,1from b;
//子查询
select * from b where id in(select id from d);
//between的用法
select *from table where time between 2012 and 2014
//in的用法
delete from table where a in('1','2','3');
//两张表删除主表中在附表中没有的信息
delete from table where not exists(select * from wehre table 2)
//查询前10条数据
select top(10)* from table where
//
//选择随机的记录
select newid()
//显示数据库所有的表名
select name from sysobjects where type="u"
//选择10到15的记录
select top(5) * from (select top15)
1351

被折叠的 条评论
为什么被折叠?



