SQL ɾ³ýÖØ¸´Êý¾Ý£¬Ö»±£Áô1Ìõ
if not object_id('Tempdb..#T') is null
drop table #T
Go
Create table #T([ID] int,[Name] nvarchar(1),[Memo] nvarchar(2))
Insert #T
select 1,N'A',N'A1' union all
select 2,N'A',N'A2' union all
select 3,N'A',N'A3' union all
select 4,N'B',N'B1' union all
select 5,N'B',N'B2'
Go
--I¡¢NameÏàͬID×îСµÄ¼Ç¼(ÍÆ¼öÓÃ1,2,3),±£Áô×îСһÌõ
·½·¨1:
delete a from #T a where exists(select 1 from #T where Name=a.Name and ID<a.ID)
·½·¨2:
delete a from #T a left join (select min(ID)ID,Name from #T group by Name) b on a.Name=b.Name and a.ID=b.ID where b.Id is null
·½·¨3:
delete a from #T a where ID not in (select min(ID) from #T where Name=a.Name)
·½·¨4(×¢:IDΪΨһʱ¿ÉÓÃ):
delete a from #T a where ID not in(select min(ID)from #T group by Name)
·½·¨5:
delete a from #T a where (select count(1) from #T where Name=a.Name and ID<a.ID)>0
·½·¨6:
delete a from #T a where ID<>(select top 1 ID from #T where Name=a.name order by ID)
·½·¨7:
delete a from #T a where ID>any(select ID from #T where Name=a.Name)
select * from #T
Éú³É½á¹û:
/*
ID Name Memo
----------- ---- ----
1 A A1
4 B B1
(2 ÐÐÊÜÓ°Ïì)
*/
--II¡¢NameÏàͬID±£Áô×î´óµÄÒ»Ìõ¼Ç¼:
·½·¨1:
delete a from #T a where exists(select 1 from #T where Name=a.Name and ID>a.ID)
·½·¨2:
delete a from #T a left join (select max(ID)ID,Name from #T group by Name) b on a.Name=b.Name and a.ID=b.ID where b.Id is null
·½·¨3:
delete a from #T a where ID not in (select max(ID) from #T where Name=a.Name)
·½·¨4(×¢:IDΪΨһʱ¿ÉÓÃ):
delete a from #T a where ID not in(select max(ID)from #T group by Name)
·½·¨5:
delete a from #T a where (select count(1) from #T where Name=a.Name and ID>a.ID)>0
·½·¨6:
delete a from #T a where ID<>(select top 1 ID fr
Ïà¹ØÎĵµ£º
×î½üÒ»Ö±ÔÚÓÃjavascriptÔÚ×öÏîÄ¿
¿ÉÊÇ×ö×Å×ö×Å
¸Ð¾õºÜ¶à¹¦ÄÜ´úÂë¶¼ÊÇÖØ¸´µÄ¡£
±ÈÈç¶ÔjavascriptÊý×éµÄÅÅÐò
»¹ÓжÔÊý×éÊý¾ÝµÄɾѡÒÔ¼°·Ö×é
ËùÒÔ£¬ºóÀ´ÐËÖÂÒÔÉÏÀ´¡£
Ò»·¢²»¿ÉÊÕʰ¡£
дÁËÒ»¸öÄÜÔÚjavascriptÖÐÓ¦ÓÃµÄ SQL ¿â
ºóÀ´ÓÖÏ룬Ôõô²»ÄÜÓÃjavascriptÖ±½ÓÁ¬½ÓÊý¾Ý¿âÄØ£¿
ÓÖ×öÁËÒ»¸öjavascriptÖ±Á¬SqlÊý¾ÝµÄÀà¿â ......
×÷Õߣºsuperhasty
2007-11-29
ÔÚÂÛ̳Éϳ£¼ûÓÐÅóÓѱ§Ô¹£¬ËµSQL ServerÌ«³ÔÄÚ´æÁË¡£ÕâÀï±ÊÕ߸ù¾Ý¾Ñé¼òµ¥½éÉÜÒ»ÏÂÄÚ´æÏà¹ØµÄµ÷ÓÅ֪ʶ¡£Ê×ÏÈ˵Ã÷Ò»ÏÂSQL
ServerÄÚ´æÕ¼ÓÃÓÉÄ¿·Ö×é³É¡£SQL ServerÕ¼ÓõÄÄÚ´æÖ÷ÒªÓÉÈý²¿·Ö×é³É£ºÊý¾Ý»º´æ(Data
Buffer)¡¢Ö´Ðлº´æ(Procedure Cache)¡¢ÒÔ¼°SQL ServerÒýÇæ³ÌÐò¡£S ......
alert index mem_ct monitoring usage;
desc v$object_usage;
set linesize 190
select * from v$object_usage;
SQL>SET AUTOTRACE ON;
¡¡¡¡*autotrace¹¦ÄÜÖ»ÄÜÔÚSQL*PLUSÀïʹÓÃ
¡¡¡¡ÆäËûһЩʹÓ÷½·¨£º
¡¡¡¡2.2.1¡¢ÔÚSQLPLUSÖеõ½Óï¾ä×ܵÄÖ´ÐÐʱ¼ä
¡¡¡¡SQL> set timing on;
2.2.2¡¢Ö»ÏÔʾִÐмƻ®--(»áÍ¬Ê ......
1¡¢²éѯÁ½¸öʱ¼äÖ®¼ä
select * from [tablename] where date between \'value1\' and \'value2\'
2¡¢ÏÔʾ×îºó»Ø¸´Ê±¼ä
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
3¡¢Èճ̰²ÅÅÌáǰ5·ÖÖÓÌáÐÑ
select * from Èճ̰²ÅÅ w ......
2010-05-05 13:35:52.06 Server Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
2010-05-05 13:35:52.06 Server (c) 2005 Microsoft Corporation.
201 ......