Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL Select N to M Records (single Table)

È¡±íÀïnµ½mÌõ¼Í¼µÄ¼¸ÖÖ·½·¨:
1. Ö»ÐèÒª²éѯǰMÌõÊý¾Ý(0 to M),
1.1 ʹÓà top(M) ·½·¨:
select top(3) * from [tablename]
 
1.2 ʹÓà set rowcount ·½·¨:
http://msdn.microsoft.com/zh-cn/library/ms188774(SQL.90).aspx
set rowcount M
select * from [tablename]
set rowcount 0
ȨÏÞ ÒªÇó¾ßÓÐ public ½ÇÉ«³ÉÔ±×ʸñ¡£
ÒªÖ´ÐÐset rowcount 0, ·ñÔòÓ°ÏìÒÔºó²éѯµÈ.
 
 
2.²éѯNµ½MÌõÊý¾Ý(N to M),
2.1  ±íÀïÃæÓбêʶÁÐ
2.1.1
select top (M-N+1) * from [tablename] where [columnname] not in (select top (N) [columnname] from [tablename])
 
2.1.2  ÄæÐòÏÔʾ
select top N * from (select top M * from [tablename] order by [columnname]) temp order by [columnname] desc
 
2.1.3 ˳ÐòÏÔʾ
select * from (select top N * from (select top M * from [tablename] order by [columnname]) temp1 order by [columnname] desc) temp2 order by [columnname]
 
 
2.2 ±íÀïÓÐidentityÊôÐÔ
select * from [tablename] where identitycol between N and M
 
Èç[columnname]ΪidentityÊôÐÔ,Ôò¿ÉÒÔд³É:
select * from [tablename] where [columnname] between N and M
 
2.3 ±íÀïÃæÓбêʶÁÐ, ÀûÓÃÁÙʱ±í
IF Exists(Select 1 from sysObjects Where Name ='temptable' And Type In ('temptable','U'))
begin
    drop table [temptable]
end
select top M * into [temptable] from [tablename] order by [columnname]
set rowcount N
select * from [temptable] order by [columnname] desc
set rowcount 0
drop table [temptable] 
 
2.4 Èç¹ûtablenameÀïûÓÐÆäËûidentityÁУ¬ÄÇô£º
exec sp_dboption [DataBaseName] ,'select into/bulkcopy',true
IF Exists(Select 1 from sysObjects Where Name ='temptable' And Type In ('temptable','U'))
begin
    drop table temptable
end
select identity(int) id0,* into [temptable] from [tablename]
select * from temp where id0 >= N and id0 <= M
drop table temptable 
 
Èç¹ûÄãÔÚÖ´ÐÐselect identity(int) id0,* into [temp


Ïà¹ØÎĵµ£º

sql·Ö頁

Ó¦Ò»¸öÅóÓѵÄÒªÇó£¬ÌùÉÏÊղصÄSQL³£Ó÷ÖÒ³µÄ°ì·¨¡«¡«
±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º 
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
  (SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
  from ±íÃû
  ORDER BY ......

Ò»²¿µçÄÔ,Íæ×ªsql server¶à»úÁ¬½Ó.

    ×î½ü,Òò¸öÈ˵çÄÔÓ²ÅÌËð»µ,йºÈëÁË500GµÄ´óÓ²ÅÌ,°²×°ÁËwindows7,ÔÚwin7Éϰ²×°Á˶à¸öÐéÄâxp»ú,ÐéÄâ»úÓëʵ¼ÊµÄ»úÆ÷(Ö÷»ú)×é³ÉÁËÒ»¸ö¾ÖÓòÍø,ʵÏÖÔÚÐéÄâ»úÖÐͨ¹ýÔ¶³ÌÁ¬½ÓÖ÷»úµÄsql server.ÏÖ½«ÎÒµÄÊÔÑé¹ý³Ì½éÉÜÈçÏÂ,¹©ÓÐÐËȤ³¢ÊԵĴóÏÀ²Î¿¼.
1. °²×°ÐéÄâ»ú»·¾³.
ÏȰ²×°window7.0Æì½¢°æ (רҵÓëÆóÒµ°æÒ²¿ ......

SQL Server·ÖÒ³3ÖÖ·½°¸±ÈÆ´

½¨Á¢±í£º
CREATE TABLE [TestTable] (
 [ID] [int] IDENTITY (1, 1) NOT NULL ,
 [FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [LastName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [Country] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Note] [ ......

Oracle SQL PLUS µÇ¼ Æô¶¯ ¹Ø±Õ


Oracle SQL PLUS »ù±¾²Ù×÷1
怬
c:\>sqlplus "sys/test1234 as sysdba"  ÒÔsysdbaÉí·ÝµÇ¼
 
c:\>sqlplus/nolog   ÒÔnologÉí·ÝµÇ¼
sql> connect sys/test1234 as sysdba
Connected.
 
 
Æô¶¯ 
SQL>  startup    &nb ......

SQLÉí·ÝÖ¤¸ñʽÑéÖ¤


SQL°æ±¾Éí·ÝÖ¤¸ñʽÑéÖ¤ 0Ϊ´íÎó£¬1ΪÕýÈ·
CREATE  function [dbo].[IsID](@str nvarchar(18),@sex int)--´«ÈëÁ½¸ö±äÁ¿ Éí·ÝÖ¤ºÍÐÔ±ð(ÄÐ1Å®2)
returns bit
as
begin
declare @len int
declare @result bit
--set @result=0
set @len=len(@str)
if(@len!=18 and @len!=15)--³¤¶ÈÊÇ18λ»ò15λ
 begin
& ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ