SQL小短句收集
Select TOP N * from TABLE Order By NewID()
--Access:
Select TOP N * from TABLE Order By Rnd(ID)
Rnd(ID) 其中的ID是自动编号字段,可以利用其他任何数值来完成,比如用姓名字段(UserName)
Select TOP N * from TABLE Order BY Rnd(Len(UserName))
--MySql:
Select * from TABLE Order By Rand() Limit 10
--开头到N条记录
Select Top N * from 表
--N到M条记录(要有主索引ID)
Select Top M-N * from 表Where ID in (Select Top M ID from 表) Order by ID Desc
--选择10从到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名order by id desc
--N到结尾记录
Select Top N * from 表Order by ID Desc
--显示最后5条记录,但是显示的顺序必须为5,6,7,8,9,10,而不是10,9,8,7,6,5 如下解决方法:
select top 5 from test where id in(select top 5 from test order by id desc) order by id asc
--通过这个问题也能总结出4-10条,5-100条这种限定一定范围内的sql语句的写法:
select top <末端ID-顶端ID+1> * from <表名> where ID not in(select top <顶端ID-1>) ID from <表名>)
--例如:4-10条就应该写成
select top 10-4+1 * from test where id not in(select top 4-1 id from test)
上一篇: select top 1 * from [news_table] where [新闻标识列]<当前id号 where ......
下一篇: select top 1 * from [news_table] where [新闻标识列]>当前id号 where ...... order by [新闻标识列] desc --两条记录完全相同,如何删除其中一条
set rowcount=1
delete from thetablename where id=@duplicate_id--@duplicate_id为重复值的id
--模糊查询
select * from product&n
相关文档:
我在学习关于java编程,现在涉及到的是sql的问题,比如软件选择、环境的连接设置等问题,对于这些问题我真是束手无策啊!请求Java编程高手赐教:
1、我用的Java是j2sdk-1_4_2_13-nb-5_0,我用了sql server2000,我用jdbc3.0行吗?所有连接设置该怎么样设置?
&nb ......
declare @t varchar(255),@c varchar(255)
declare table_cursor cursor for select a.name,b.name
from sysobjects a,syscolumns b ,systypes c
where a.id=b.id and a.xtype='u'&n ......
Insert Into 数据表名称(字段名称1,字段名称2,...) values(字段值1,字段值2,...)
insert into user(username,password,age) values('李老四','6666',45)
Update 数据表名称 Set 字段名称=字段值,字段名称=字段值,...[Where 条件]
Delete from 数据表
下列查询返回在LONDON(伦敦)或SEATTLE(西雅图)的所有雇员:
S ......
机器情况
p4: 2.4
内存: 1 G
os: windows 2003
数据库: ms sql server 2000
目的: 查询性能测试,比较两种查询的性能
SQL查询效率 step by step
-- setp 1.
-- 建表
create table t_userinfo
(
userid int identity(1,1) primary key nonclustered,
nick varchar(50) not null default '',
classid int not nul ......
数据库快照是MSSQL2005的新功能,仅在 Microsoft SQL Server 2005 Enterprise Edition 中可用。而且SQL Server Management Studio 不支持创建数据库快照,创建快照的唯一方式是使用 Transact-SQL。
数据库快照是数据库(称为“源数据库”)的只读静态视图。在创建时,每个数据库快照在事务上都与源数据库一致 ......