热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

sqlserver常用语句总结

前几天应聘软件测试工作,笔试题中遇到数据库语句操作,本人自认为数据库基本应用比较熟练,但因长时间不用仍感到生疏。以下语句已在本机测试成功,未完待续。查询表结构:sp_MShelpcolumnsdb

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

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

查询表结构:

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


推荐阅读
author-avatar
wjdd8888
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有