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

SQL ѧϰ±Ê¼Ç Like²Ù×÷·û

LIKE ²Ù×÷·ûÓÃÓÚÔÚ WHERE ×Ó¾äÖÐËÑË÷ÁÐÖеÄÖ¸¶¨Ä£Ê½¡£
SQL LIKE ²Ù×÷·ûÓï·¨
SELECT column_name(s) from table_name WHERE column_name LIKE pattern
SQL ͨÅä·û
ÔÚËÑË÷Êý¾Ý¿âÖеÄÊý¾Ýʱ£¬SQL ͨÅä·û¿ÉÒÔÌæ´úÒ»¸ö»ò¶à¸ö×Ö·û¡£
SQL ͨÅä·û±ØÐëÓë LIKE ÔËËã·ûÒ»ÆðʹÓá£
ÔÚ SQL ÖУ¬¿ÉʹÓÃÒÔÏÂͨÅä·û£º
ͨÅä·û
ÃèÊö

%
Ìæ´úÒ»¸ö»ò¶à¸ö×Ö·û
_
½öÌæ´úÒ»¸ö×Ö·û
[charlist]
×Ö·ûÁÐÖеÄÈκε¥Ò»×Ö·û
[^charlist]
»òÕß
[!charlist]
²»ÔÚ×Ö·ûÁÐÖеÄÈκε¥Ò»×Ö·û
LIKE ²Ù×÷·ûʵÀý
Àý×Ó 1
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡¾ÓסÔÚÒÔ "N" ¿ªÊ¼µÄ³ÇÊÐÀïµÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE 'N%'
Ìáʾ£º
"%" ¿ÉÓÃÓÚ¶¨ÒåͨÅä·û£¨Ä£Ê½ÖÐȱÉÙµÄ×Öĸ£©¡£
Àý×Ó 2
½ÓÏÂÀ´£¬ÎÒÃÇÏ£Íû´Ó "Persons" ±íÖÐÑ¡È¡¾ÓסÔÚÒÔ "g" ½áβµÄ³ÇÊÐÀïµÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE '%g'
Àý×Ó 3
½ÓÏÂÀ´£¬ÎÒÃÇÏ£Íû´Ó "Persons" ±íÖÐÑ¡È¡¾ÓסÔÚ°üº¬ "lon" µÄ³ÇÊÐÀïµÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE '%lon%'
Àý×Ó 4
ͨ¹ýʹÓà NOT ¹Ø¼ü×Ö£¬ÎÒÃÇ¿ÉÒÔ´Ó "Persons" ±íÖÐÑ¡È¡¾ÓסÔÚ²»°üº¬
"lon" µÄ³ÇÊÐÀïµÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City NOT LIKE '%lon%'
ʹÓà [charlist] ͨÅä·û
Àý×Ó 1
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡¾ÓסµÄ³ÇÊÐÒÔ "A" »ò "L" »ò "N" ¿ªÍ·µÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons WHERE City LIKE '[ALN]%'
Àý×Ó 2
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡¾ÓסµÄ³ÇÊв»ÒÔ "A" »ò "L" »ò "N" ¿ªÍ·µÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons WHERE City LIKE '[!ALN]%'


Ïà¹ØÎĵµ£º

ʵÏÖSQL Server 2008Êý¾ÝѹËõ

ΪʲôÐèÒªÊý¾ÝѹËõ
¡¡¡¡Ê×ÏÈ¿ÉÄÜÐèÒªÌÖÂÛµÄÎÊÌâ¾ÍÊÇΪʲôÔÚ´æ´¢³É±¾²»¶Ï½µµÍµÄ½ñÌ죬΢Èí»¹ÒªÉ··Ñ¿àÐĵØÔÚSQL ServerÖÐʵÏÖ²¢ÇÒ²»¶Ï¸Ä½øÊý¾ÝѹËõ¼¼ÊõÄØ?
¡¡¡¡¾¡¹Ü´æ´¢³É±¾ÒѾ­²»ÔÙÊÇ´«Í³ÒâÒåÉϵÄÊ×Òª¿¼ÂÇÒòËØ£¬µ«ÊÇÕâ²¢²»´ú±íÊý¾Ý¿â³ß´ç²»ÊÇÒ»¸öÎÊÌ⣬ÒòΪÊý¾Ý¿â³ß´ç³ýÁË»áÓ°Ïìµ½´æ´¢³É±¾Ö®Í⣬»¹¼«´óµØ¹ØÁªµ½¹ÜÀí³É±¾º ......

SQL Server´æ´¢¹ý³Ì

Ê×ÏȽéÉÜÒ»ÏÂʲôÊÇ´æ´¢¹ý³Ì£º´æ´¢¹ý³Ì¾ÍÊǽ«³£ÓõĻòºÜ¸´ÔӵŤ×÷£¬Ô¤ÏÈÓÃSQLÓï¾äдºÃ²¢ÓÃÒ»¸öÖ¸¶¨µÄÃû³Æ´æ´¢ÆðÀ´£¬²¢ÇÒÕâÑùµÄÓï¾äÊÇ·ÅÔÚÊý¾Ý¿âÖеģ¬»¹¿ÉÒÔ¸ù¾ÝÌõ¼þÖ´Ðв»Í¬SQLÓï¾ä£¬ ÄÇôÒÔºóÒª½ÐÊý¾Ý¿âÌṩÓëÒѶ¨ÒåºÃµÄ´æ´¢¹ý³ÌµÄ¹¦ÄÜÏàͬµÄ·þÎñʱ£¬Ö»Ðèµ÷ÓÃexecute,¼´¿É×Ô¶¯Íê³ÉÃüÁî¡£
¡¡¡¡Çë´ó¼ÒÀ´Á˽âһϴ洢¹ý³Ìµ ......

sql³£ÓÃ

select [name] from sysdatabases order by name--µÃµ½Êý¾Ý¿âÖÐËùÓеĿâÃû
select [name] from sysobjects where xtype='U'and [name]<>'dtproperties' order by [name]--µÃµ½Êý¾Ý¿â±íÖеÄÁбí
select [name] from sysobjects where xtype='V' and [name]<>'syssegments' and [name]<>'sysconstraints' ......

SQL ½«ÁÐת»»ÎªÐУ¬Ï൱ÓÚ½«±í½á¹¹Ðýת90¶È

½«ÁÐת»»ÎªÐУ¬Ï൱ÓÚ½«±í½á¹¹Ðýת90¶È
T_Student ±í
Stud_ID
Sex
Name
1
ÄÐ
Tom
2
Å®
Anne
3
ÄÐ
Jack
 
Ö´ÐÐ: Exec proColumnToRow ’T_Student’,’Name’,’ New_ID’
 
ת»»ºóµÄ±í
 
New_ID
Tom
Anne
Jack
Stud_ID
1
2
3
Sex
ÄÐ
Å®
ÄÐ
& ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ