常用的sql命令

数据库定义语言: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)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值