Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1181767
  • 博文数量: 252
  • 博客积分: 5421
  • 博客等级: 大校
  • 技术积分: 2418
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-17 12:59
文章分类

全部博文(252)

文章存档

2017年(3)

2016年(18)

2015年(31)

2014年(18)

2013年(7)

2012年(8)

2011年(12)

2010年(30)

2009年(32)

2008年(57)

2007年(36)

分类: 数据库开发技术

2007-07-20 20:30:16

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

阅读(1162) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~