sql学用语句
来源:互联网 发布:linux卸载已安装的jdk 编辑:程序博客网 时间:2024/05/02 03:55
1.如何删除表中的重复记录?(这里指记录的每个字段都要相同)
select distinct * into #temp from tab
delete tab
insert tab select * from #temp
drop table #temp
2.怎样返回数据库中用户表的表单名
select name from sysobjects where xtype='U'
select name from sysobjects where xtype = 'u' and status >=0
3.返回两个表中共有的所有记录
select * from testTable as a inner join TestTableChild as b on a.id = b.parentid
4.返回两个表里共有的记录,且不重复
select a.id,a.name,b.name from testTable as a inner join TestTableChild as b on a.id = b.parentid group by a.id,a.name,b.name
5.向一个表A中插入记录,并且插入的记录在A中不存在(通过一个字段来判断)
insert into trace_users
(tracekey,muteSMS,CreateTime,traceuser,tracetime,traceSlot,traceduration)
Select 'TRACE_TIMER',0,getdate(),mobileid,getdate(),'30','0' from Epm_EmployeeList where corpid = 10001 and not exists (select traceuser from trace_users ) and mobileid like '13%' and len(mobileid) = 11
6、根据出生日期,算出年龄
DATEDIFF(month, T.Birthday, GETDATE()) AS MONTHS //得到月份
MONTHS /12 取整就是年龄
7、等待时间再执行语句
waitfor delay '00:00:05'
select * from studentinfo
waitfor time ’23:08:00
select * from employee
8、指定值的范围查询
stockname like '[a-zA-Z]%' --------- ([]指定值的范围)
stockname like '[^F-M]%' --------- (^排除指定范围)
9、从表中获取值并插入另一张表中
insert into table2 (a) select a from table1
10、备份与恢复数据库
backup database SCardDB to disk = 'F:/SCardDB.
restore database kangda from disk='d:/backup.bak‘
11、对查询结果随机排序
SELECT * FROM Northwind..Orders ORDER BY NEWID()
12、按姓氏笔画排序
Select * From TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as
13获取某一个表的所有字段
select name from syscolumns where id=object_id('表名')
14、记录转换
select *,case Type when 1 then '移动' when 2 then '联通' when 3 then '小灵通' end as TypeName from abc
15、按拼音首字母排序
select * from 表名 order by 列名 Collate Chinese_PRC_CS_AS_KS_WS
- sql学用语句
- sql中常用语句
- sql server中常用语句
- 尝试用语句备份sql数据库
- 如何用语句修改sql server年份
- Sql中常用语句及通配符的介绍
- Sql中常用语句及通配符的介绍
- SCREEN中常用语句
- Oracle 便用语句
- 工作中常用语句
- js中常用语句
- Oracle中常用语句
- mysql不常用语句
- JavaScript中常用语句
- 英语日常用语100句
- 英语日常用语百句
- 日语常用语3000句
- 商务午餐中常用语句
- 导出 hibernate3.2.6ga java源码 打包成jar
- DDE进程通讯C/C++
- 数字转人民币大写
- WinForm 程序开发小结
- 空间数据库的设计与建设
- sql学用语句
- c++ const 关于数组的经典用法在c中认为有错
- 初读 《c++程序设计语言特别版》 2 体味c++的哲理与学习方法
- 寓言故事
- ddd
- dwr(ajax)分页
- 检查是否已连接上 Internet
- 让机器进入待机或休眠状态
- 小型MRP系统