1、列出数据库里所有的表名
select name from sysobjects where type='U'
2、新建一个与a表一样的空的b表
select * into b from a where 1<>1
3、列出表里的所有的字段
select name from syscolumns where id=object_id('TableName')
4、说明:初始化表table1
TRUNCATE TABLE table1
5、说明:随机选择记录
select top 10 * from tablename order by newid()
6、跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)
insert into b(a, b, c) select d,e,f from b in '具体数据库' where 条件
例子:..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..
7、日程安排提前五分钟提醒
SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())>5
8、删除重复记录
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
9、日期算當月天數:
select Day(dateadd(day,-1,convert(datetime,convert(char(07),dateadd(m,1,getdate()),120)+'-01')))
select 32-Day(getdate()+(32-Day(getdate())))
10、按姓氏笔画排序
select * from 表名 order by 列名 Collate Chinese_PRC_Stroke_ci_as
11、按拼音首字母排序
select * from 表名 order by 列名 Collate Chinese_PRC_CS_AS_KS_WS
12、查看硬盘分区:
EXEC master..xp_fixeddrives
阅读(1187) | 评论(0) | 转发(0) |