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

SQL×¢È멶´È«½Ó´¥ ½ø½×ƪ

µÚÒ»½Ú¡¢SQL×¢ÈëµÄÒ»°ã²½Öè
Ê×ÏÈ£¬Åжϻ·¾³£¬Ñ°ÕÒ×¢Èëµã£¬ÅжÏÊý¾Ý¿âÀàÐÍ£¬ÕâÔÚÈëÃÅƪÒѾ­½²¹ýÁË¡£
Æä´Î£¬¸ù¾Ý×¢Èë²ÎÊýÀàÐÍ£¬ÔÚÄÔº£ÖÐÖع¹SQLÓï¾äµÄԭò£¬°´²ÎÊýÀàÐÍÖ÷Òª·ÖΪÏÂÃæÈýÖÖ£º
(A) ID=49 ÕâÀà×¢ÈëµÄ²ÎÊýÊÇÊý×ÖÐÍ£¬SQLÓï¾äԭò´óÖÂÈçÏ£º
Select * from ±íÃû where
×Ö¶Î=49
×¢ÈëµÄ²ÎÊýΪID=49 And [²éѯÌõ¼þ]£¬¼´ÊÇÉú³ÉÓï¾ä£º
Select * from ±íÃû where ×Ö¶Î=49 And
[²éѯÌõ¼þ]
(B) Class=Á¬Ðø¾ç ÕâÀà×¢ÈëµÄ²ÎÊýÊÇ×Ö·ûÐÍ£¬SQLÓï¾äԭò´óÖ¸ÅÈçÏ£º
Select * from ±íÃû
where ×Ö¶Î=’Á¬Ðø¾ç’
×¢ÈëµÄ²ÎÊýΪClass=Á¬Ðø¾ç’ and [²éѯÌõ¼þ] and ‘’=’ £¬¼´ÊÇÉú³ÉÓï¾ä£º
Select *
from ±íÃû where ×Ö¶Î=’Á¬Ðø¾ç’ and [²éѯÌõ¼þ] and ‘’=’’
(C) ËÑË÷ʱû¹ýÂ˲ÎÊýµÄ£¬Èçkeyword=¹Ø¼ü×Ö£¬SQLÓï¾äԭò´óÖÂÈçÏ£º
Select * from ±íÃû
where ×Ö¶Îlike ’%¹Ø¼ü×Ö%’
×¢ÈëµÄ²ÎÊýΪkeyword=’ and [²éѯÌõ¼þ] and ‘%25’=’£¬
¼´ÊÇÉú³ÉÓï¾ä£º
Select * from ±íÃû where×Ö¶Îlike ’%’ and [²éѯÌõ¼þ] and ‘%’=’%’
½Ó×Å£¬½«²éѯÌõ¼þÌæ»»³ÉSQLÓï¾ä£¬²Â½â±íÃû£¬ÀýÈ磺
ID=49 And (Select Count(*) from Admin)>=0
Èç¹ûÒ³Ãæ¾ÍÓëID=49µÄÏàͬ£¬ËµÃ÷¸½¼ÓÌõ¼þ³ÉÁ¢£¬¼´±íAdmin´æÔÚ£¬·´Ö®£¬¼´²»´æÔÚ£¨ÇëÀμÇÕâÖÖ·½·¨£©¡£Èç´ËÑ­»·£¬Ö±ÖÁ²Âµ½±íÃûΪֹ¡£
±íÃû²Â³öÀ´ºó£¬½«Count(*)Ìæ»»³ÉCount(×Ö¶ÎÃû)£¬ÓÃͬÑùµÄÔ­Àí²Â½â×Ö¶ÎÃû¡£
ÓÐÈË»á˵£ºÕâÀïÓÐһЩżȻµÄ³É·Ö£¬Èç¹û±íÃûÆðµÃºÜ¸´ÔÓû¹æÂɵģ¬ÄǸù±¾¾ÍûµÃÍæÏÂÈ¥ÁË¡£ËµµÃºÜ¶Ô£¬ÕâÊÀ½ç¸ù±¾¾Í²»´æÔÚ100%³É¹¦µÄºÚ¿Í¼¼Êõ£¬²ÔÓ¬²»¶£ÎÞ·ìµÄµ°£¬ÎÞÂ۶༼Êõ¶à¸ßÉîµÄºÚ¿Í£¬¶¼ÊÇÒòΪ±ðÈ˵ijÌÐòдµÃ²»ÑÏÃÜ»òʹÓÃÕß±£ÃÜÒâʶ²»¹»£¬²ÅÓеÃÏÂÊÖ¡£
ÓеãÅÜÌâÁË£¬»°Ëµ»ØÀ´£¬¶ÔÓÚSQLServerµÄ¿â£¬»¹ÊÇÓа취ÈóÌÐò¸æËßÎÒÃDZíÃû¼°×Ö¶ÎÃûµÄ£¬ÎÒÃÇÔڸ߼¶ÆªÖлá×ö½éÉÜ¡£
×îºó£¬ÔÚ±íÃûºÍÁÐÃû²Â½â³É¹¦ºó£¬ÔÙʹÓÃSQLÓï¾ä£¬µÃ³ö×ֶεÄÖµ£¬ÏÂÃæ½éÉÜÒ»ÖÖ×î³£Óõķ½·¨£­AsciiÖð×Ö½âÂë·¨£¬ËäÈ»ÕâÖÖ·½·¨ËٶȺÜÂý£¬µ«¿Ï¶¨ÊÇ¿ÉÐеķ½·¨¡£
ÎÒÃǾٸöÀý×Ó£¬ÒÑÖª±íAdminÖдæÔÚusername×ֶΣ¬Ê×ÏÈ£¬ÎÒÃÇÈ¡µÚÒ»Ìõ¼Ç¼£¬²âÊÔ³¤¶È£º
http://www.19cn.com/showdetail.asp?id=49 and (select top 1
len(username) from Admin)>0
ÏÈ˵Ã÷Ô­Àí£ºÈç¹ûtop
1µÄusername³¤¶È´óÓÚ0£


Ïà¹ØÎĵµ£º

SQLÖбí±äÁ¿ºÍÁÙʱ±íµÄÓÅȱµã

http://www.cnblogs.com/Mainz/archive/2008/12/20/1358897.html
ʲôÇé¿öÏÂʹÓñí±äÁ¿£¿Ê²Ã´Çé¿öÏÂʹÓÃÁÙʱ±í£¿
±í±äÁ¿£º
DECLARE @tb  table(id   int   identity(1,1), name   varchar(100))
INSERT @tb
SELECT id, name
from mytable
WHERE name like ‘zhang%&rsquo ......

SQLÓαêÔ­ÀíºÍʹÓ÷½·¨(ת)

ÔÚÊý¾Ý¿â¿ª·¢¹ý³ÌÖУ¬µ±Äã¼ìË÷µÄÊý¾ÝÖ»ÊÇÒ»Ìõ¼Ç¼ʱ£¬ÄãËù±àдµÄÊÂÎñÓï¾ä´úÂëÍùÍùʹÓÃSELECT INSERT Óï¾ä¡£µ«ÊÇÎÒÃdz£³£»áÓöµ½ÕâÑùÇé¿ö£¬¼´´Óijһ½á¹û¼¯ÖÐÖðÒ»µØ¶ÁÈ¡Ò»Ìõ¼Ç¼¡£ÄÇôÈçºÎ½â¾öÕâÖÖÎÊÌâÄØ£¿ÓαêΪÎÒÃÇÌṩÁËÒ»ÖÖ¼«ÎªÓÅÐãµÄ½â¾ö·½°¸¡£ 1.1 ÓαêºÍÓαêµÄÓŵã ÔÚÊý¾Ý¿âÖУ¬ÓαêÊÇÒ»¸öÊ®·ÖÖØÒªµÄ¸ÅÄî¡£ÓαêÌṩÁËÒ» ......

SQL ServerÈÕÖ¾Çå¿Õ·½·¨

תÔØ£ºhttp://blog.csdn.net/cnming/archive/2009/03/11/3979290.aspx
ÔÚ²éѯ·ÖÎöÆ÷ÖÐ˳ÐòÖ´ÐÐÒÔÏÂÈý²½£¬ÆäÖР  databasename   ΪÄãµÄÊý¾Ý¿âÎļþÃû
1.Çå¿ÕÈÕÖ¾£ºDUMP   TRANSACTION   databasename   WITH   NO_LOG  
2.½Ø¶ÏÊÂÎñÈÕÖ¾£ºBACKUP ......

³£ÓÃsqlÏà¹Ø

1Ð޸Ļù±¾±í
 Ìí¼ÓÁÐ alter table tableName add<ÐÂÁÐÃû><Êý¾ÝÀàÐÍ>[ÍêÕûÐÔÔ¼Êø]
 É¾³ýÁÐ alter table tableName drop<ÐÂÁÐÃû><Êý¾ÝÀàÐÍ>[ÍêÕûÐÔÔ¼Êø]
2´´½¨
  ½¨±ícreate table tableName(
id primary key AUTO_INCREMENT(mysql);
id primary key identity(1,1)(s ......

SQL Server 2005 CTEµÄÓ÷¨

if object_id('[tb]') is not null
drop table [tb] 
go
create table [tb]([id] int,[col1] varchar(8),[col2] int) 
insert [tb] 
select 1,'ºÓ±±Ê¡',0 union all
 select 2,'ÐĮ̈ÊÐ',1 union all
 select 3,'ʯ¼ÒׯÊÐ',1 union all
 select 4,'ÕżҿÚÊÐ',1 union all
&n ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ