sql server 常用语句总结

前几天应聘软件测试工作,笔试题中遇到数据库语句操作,本人自认为数据库基本应用比较熟练,但因长时间不用仍感到生疏。

以下语句已在本机测试成功,未完待续。

查询表结构:

sp_MShelpcolumns 'dbo.table';

 

 

删除列

alter table 练习 drop column 首重播;

添加列

alter table 练习 add id int;

 

 

 

 

 

去除重复记录:

方法1:为表格添加序列号:

alter table练习add 序号 int identity(1,1);

delect from 练习 a where  序号 not in (select min(序号) from 练习 b where a.节目名称=b.节目名称 and a.所属频道=b.所属频道 and a.节目类型=b.节目类型);

如果节目类型列为空则:

delect from 练习 a where  序号 not in (select min(序号) from 练习 b where a.节目名称=b.节目名称 and a.所属频道=b.所属频道 and a.节目类型 is null);

 

 

 

方法2:去除重复记录:

新建一个相同结构的表 练习1

Insert into 练习1 select distinct * from 练习;

Delete from 练习;

Insert into 练习 select  * from 练习1;

 

 

 

 

 

 

SqlServer查询语句:

查询节目类型为空的所有记录:

select * from 练习 where 节目类型 is null

查询节目类型为空的所有不重复记录:

SELECT nickname as 昵称,email as 电子邮件

FROM testable

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值