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

SQL²éѯЧÂÊ 100wÊý¾Ý²éѯֻҪ1Ãë

»úÆ÷Çé¿ö
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 null default 0,
writetime datetime not null default getdate()
)
go
-- ½¨Ë÷Òý
create clustered index ix_userinfo_classid on t_userinfo(classid)
go
-- step 2.
declare @i int 
declare @k int
declare @nick varchar(10)
set @i = 1
while @i<1000000
begin
set @k = @i % 10
set @nick = convert(varchar,@i)
insert into t_userinfo(nick,classid,writetime) values(@nick,@k,getdate())
set @i = @i + 1
end
-- ºÄʱ 08:27 £¬ÐèÒªÄÍÐĵȴý
-- step 3.
select top 20 userid,nick,classid,writetime from t_userinfo 
where userid not in
(
select top 900000 userid from t_userinfo order by userid asc
)
-- ºÄʱ 8 Ãë ,¹»³¤µÄ
-- step 4.
select a.userid,b.nick,b.classid,b.writetime from
(
select top 20 a.userid from 
(
select top 900020 userid from t_userinfo order by userid asc
) a order by a.userid desc
) a inner join t_userinfo b on a.userid = b.userid 
order by a.userid asc
-- ºÄʱ 1 Ã룬̫¿ìÁ˰ɣ¬²»¿ÉÒÔ˼Òé
-- step 5 where ²éѯ
select top 20 userid,nick,classid,writetime from t_userinfo 
where 


Ïà¹ØÎĵµ£º

SQL Server 2008ÏÂÔØ&ÆÆ½â

´Ó¹ÙÍøÏÂÔØSQL Server 2008µÄ180ÌìÊÔÓðæÆäʵÓëÕýʽ°æÄÚÈÝÊÇ»ù±¾ÏàͬµÄ£¬Î¨Ò»µÄÇø±ð¾ÍÔÚÓÚ°²×°ÅäÖÃÎļþÖÐËù°üº¬µÄkey¡£¸÷ÖÖ°æ±¾µÄSQL ServerÔÚ½øÐе½ÕâÒ»²½Ö®Ç°¶¼ÊÇÍêȫһÑùµÄ£º
Microsoft® SQL Server® 2008 Enterprise Evaluation£º¿ª·¢ÈËÔ±ÊÔÓÃÌåÑé
Microsoft® SQL Server® 2008 Enterprise Evaluatio ......

SQL ServerÖ÷¼ü×Ô¶¯Ôö³¤µÄÉèÖÃ

ÔÚSQL ServerÖУ¬Èç¹û°Ñ±íµÄÖ÷¼üÉèΪidentityÀàÐÍ£¬Êý¾Ý¿â¾Í»á×Ô¶¯ÎªÖ÷¼ü¸³Öµ¡£ÀýÈ磺
create table customers (
id int identity(1,1) primary key not null,
name varchar(15)
);
insert into customers(name) values("name1"),("name2");
select id from customers;

²éѯ½á¹ûΪ£º
id
---
1
2
ÓÉ´Ë¿ ......

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] [ ......

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 ......

LINQ to SQL ²éѯÊý¾Ý¿âºÍʹÓô洢¹ý³Ì


ÈçÏÂÁгö²éѯ±í´ïʽ£¬³£ÓòÙ×÷·û£¬ÓëSQLÓï¾ä¶ÔÓ¦¡£

where  ¹Ø¼ü×ÖµÄʹÓÃ
public void MyWhere()
{
NorthwindDataContext dc = new NorthwindDataContext();
//²éѯ²úÆ·Ãû³ÆÒÔL¿ªÍ·µÄ¼Ç¼
var query = from p in dc.Products
where p.Prod ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ