SQL ServerÖеÄͨÅä·û
ͨÅä·û_
"_"ºÅ±íʾÈÎÒâµ¥¸ö×Ö·û,¸Ã·ûºÅÖ»ÄÜÆ¥ÅäÒ»¸ö×Ö·û."_"¿ÉÒÔ·ÅÔÚ²éѯÌõ¼þµÄÈÎÒâλÖÃ,ÇÒÖ»ÄÜ´ú±íÒ»¸ö×Ö·û.Ò»¸öºº×ÖֻʹÓÃÒ»¸ö"_"±íʾ.
Àý×Ó£º
if PATINDEX('%[ß¹-×ö]%','ÐèÒªÅжϵÄ×Ö·û')>0 -- ÅжÏÊÇ·ñÓÐ×Ö·û
print 'Óкº×Ö'
else
print 'ÎÞºº×Ö'
ͨÅä·û%
"%"·ûºÅÊÇ×Ö·ûÆ¥Åä·û,ÄÜÆ¥Åä0¸ö»ò¸ü¶à×Ö·ûµÄÈÎÒⳤ¶ÈµÄ×Ö·û´®.ÔÚSQLÓï¾äÖпÉÒÔÔÚ²éѯÌõ¼þµÄÈÎÒâλÖ÷ÅÖÃÒ»¸ö%À´´ú±íÒ»¸öÈÎÒⳤ¶ÈµÄ×Ö·û´®.ÔÚ²éѯÌõ¼þʱҲ¿ÉÒÔ·ÅÖÃÁ½¸ö%½øÐвéѯ,µ«ÔÚ²éѯÌõ¼þÖÐ×îºÃ²»ÒªÁ¬Ðø³öÏÖÁ½¸ö%
ͨÅä·û[]
ÔÚģʽ²éѯÖпÉÒÔÀûÓÃ"[]"À´ÊµÏÖ²éѯһ¶¨·¶Î§µÄÊý¾Ý.[]ÓÃÓÚÖ¸¶¨Ò»¶¨·¶Î§ÄÚµÄÈκε¥¸ö×Ö·û,°üÀ¨Á½¶ËÊý¾Ý
ͨÅä·û[^]
[^]ÓÃÀ´²éѯ²»ÊôÓÚÖ¸¶¨·¶Î§ ([a-f]) »ò¼¯ºÏ ([abcdef]) µÄÈκε¥¸ö×Ö·û¡£
Èç:select * from alluser
where username like 'M[^abc]%'
±íʾ´Ó±íalluserÖвéѯÓû§ÃûÒÔM¿ªÍ·,ÇÒµÚ¶þ¸ö×Ö·û²»ÊÇa,b,cÐÅÏ¢.
ESCAPE×Ó¾äµÄģʽƥÅä
¿ÉËÑË÷°üº¬Ò»¸ö»ò¶à¸öÌØÊâͨÅä·ûµÄ×Ö·û´®¡£ÀýÈ磬customers Êý¾Ý¿âÖÐµÄ discounts ±í¿ÉÄÜ´æ´¢º¬°Ù·ÖºÅ (%) µÄÕÛ¿ÛÖµ¡£ÈôÒªËÑË÷×÷Ϊ×Ö·û¶ø²»ÊÇͨÅä·ûµÄ°Ù·ÖºÅ£¬±ØÐëÌṩ ESCAPE ¹Ø¼ü×ÖºÍתÒå·û¡£ÀýÈ磬һ¸öÑù±¾Êý¾Ý¿â°üº¬ÃûΪ comment µÄÁУ¬¸ÃÁк¬Îı¾ 30%¡£ÈôÒªËÑË÷ÔÚ comment ÁÐÖеÄÈκÎλÖðüº¬×Ö·û´® 30% µÄÈκÎÐУ¬ÇëÖ¸¶¨ÓÉ Where comment LIKE '%30!%%' ESCAPE '!' ×é³ÉµÄ Where ×Ӿ䡣Èç¹û²»Ö¸¶¨ ESCAPE ºÍתÒå·û£¬SQL Server ½«·µ»ØËùÓк¬×Ö·û´® 30 µÄÐС£
ÏÂÀý˵Ã÷ÈçºÎÔÚ pubs Êý¾Ý¿â titles ±íµÄ notes ÁÐÖÐËÑË÷×Ö·û´®"50% off when 100 or more copies are purchased"£º
Select notes from titles
Where notes LIKE '50%% off when 100 or more copies are purchased'
ESCAPE '%'
escapeµÄÖ÷ÒªÓÃ;
1.ʹÓà ESCAPE ¹Ø¼ü×Ö¶¨ÒåתÒå·û¡£ ÔÚģʽÖУ¬µ±×ªÒå·ûÖÃÓÚͨÅä·û֮ǰʱ£¬¸ÃͨÅä·û¾Í½âÊÍΪÆÕͨ×Ö·û¡£ÀýÈ磬ҪËÑË÷ÔÚÈÎÒâλÖðüº¬×Ö·û´® 5% µÄ×Ö·û´®£¬ÇëʹÓ㺠Where ColumnA LIKE '%5/%%' ESCAPE '/'
2.ESCAPE 'escape_character' ÔÊÐíÔÚ×Ö·û´®ÖÐËÑË÷ͨÅä·û¶ø²»Êǽ«Æä×÷ΪͨÅä·ûʹÓᣠescape_character ÊÇ·ÅÔÚͨÅä·ûÇ°±íʾ´ËÌØÊâÓÃ;µÄ×Ö·û¡£
Select * from finances Where description LIKE 'gs_' ESCAPE 'S'
Òâ˼¾ÍÊÇ£º ±ÈÈ磬ÎÒÃÇÒªËÑË÷Ò»¸ö×Ö·û´® "g_" ,Èç¹ûÖ±½Ó like "g_"£¬ÄÇô "_"µÄ×÷ÓþÍÊÇͨÅä·û£¬¶ø²»ÊÇ×Ö·û£¬½á¹û£¬ÎÒÃÇ»á²éµ½±ÈÈç "ga","gb","gc",
Ïà¹ØÎĵµ£º
Differring Constraints:
Constraints can have the following attributes: DEFFERRABLE / NOT DEFFERRABLE, INITIALLY DEFFERRED / INITIALLY IMMEDIATE.
e.g.:
alter table dept2 add constraint dept2_id_pk primary key (department_id) deferrable initially deferred; // deferring constraint on creation. ......
CREATE VIEW MYVIEW
AS
SELECT * from bjxxdiweb_database2007.dbo.bm_tongji
UNION ALL
SELECT * from aa.DBO.chen
select * into aa..chen from bjxxdiweb_database2007.dbo.bm_tongji where 1=2
˵Ã÷£ºÊý¾Ý¿âAµÄ±íµÄ×Ö¶ÎÃû±ØÐëºÍÊý¾Ý¿âBµÄ±íµÄ×Ö¶ÎÃûÏàͬ£¬°üÀ¨Êý¾ÝÀàÐ͵ȡ£ ......
PairWise subquery:
e.g.:
select * from wf_docsort where (ndocsortid,nmoduleinfoid) in (select ndocsortid, nmoduleinfoid from wf_docsort where instr(cname,'ÎÄ')>0)
the above sql is the same function as:
select * from wf_docsort where ndocsortid = (select ndocsortid from wf_docsort where ......
WAITFOR
Ö¸¶¨´¥·¢Óï¾ä¿é¡¢´æ´¢¹ý³Ì»òÊÂÎñÖ´ÐеÄʱ¼ä¡¢Ê±¼ä¼ä¸ô»òʼþ¡£
Óï·¨
WAITFOR { DELAY 'time' | TIME
'time' }
²ÎÊý
DELAY
ָʾ Microsoft® SQL Server™ Ò»Ö±µÈµ½Ö¸¶¨µÄʱ¼ä¹ýÈ¥£¬×¿É´ï 24 Сʱ¡£
'time'
ÒªµÈ´ýµÄʱ¼ä¡£¿ÉÒÔ°´ datetime Êý¾Ý¿É½ÓÊܵĸñʽָ¶¨
time£¬Ò²¿ÉÒÔÓþֲ¿±äÁ¿Ö¸¶ ......
in µÄ»°£¬ Èç¹ûÊÇnull ¾Í²»±È½ÏÁË£¬¼È²»ÊÇin Ò²²»ÊÇ not in
existsµÄ»° ÒòΪÓà = ¼ÓÔÚÌõ¼þÀï±È½ÏÁË£¬ËùÒÔ null ÊÇ not exists
select *
from pricetemp
where cast(ÉÌÆ·¥³ー¥É as varchar(10))not in(
select shohin_cd
&nbs ......