SQLÀïµÄEXISTSÓëin¡¢not existsÓënot in
SQLÀïµÄEXISTSÓëin¡¢not existsÓënot in
ϵͳҪÇó½øÐÐSQLÓÅ»¯£¬¶ÔЧÂʱȽϵ͵ÄSQL½øÐÐÓÅ»¯£¬Ê¹ÆäÔËÐÐЧÂʸü¸ß£¬ÆäÖÐÒªÇó¶ÔSQLÖеIJ¿·Öin/not inÐÞ¸ÄΪexists/not exists
Ð޸ķ½·¨ÈçÏ£º
inµÄSQLÓï¾ä
SELECT id, category_id, htmlfile, title, convert(varchar(20),begintime,112) as pubtime
from tab_oa_pub WHERE is_check=1 and
category_id in (select id from tab_oa_pub_cate where no='1')
order by begintime desc
ÐÞ¸ÄΪexistsµÄSQLÓï¾ä
SELECT id, category_id, htmlfile, title, convert(varchar(20),begintime,112) as pubtime
from tab_oa_pub WHERE is_check=1 and
exists (select id from tab_oa_pub_cate where tab_oa_pub.category_id=convert(int,no) and no='1')
order by begintime desc
·ÖÎöÒ»ÏÂexistsÕæµÄ¾Í±ÈinµÄЧÂʸßÂð£¿
ÎÒÃÇÏÈÌÖÂÛINºÍEXISTS¡£
select * from t1 where x in ( select y from t2 )
ÊÂʵÉÏ¿ÉÒÔÀí½âΪ£º
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
--Èç¹ûÄãÓÐÒ»¶¨µÄSQLÓÅ»¯¾Ñ飬´ÓÕâ¾äºÜ×ÔÈ»µÄ¿ÉÒÔÏëµ½t2¾ø¶Ô²»ÄÜÊǸö´ó±í£¬ÒòΪÐèÒª¶Ôt2½øÐÐÈ«±íµÄ“ΨһÅÅÐò”£¬Èç¹ût2ºÜ´óÕâ¸öÅÅÐòµÄÐÔÄÜÊDz»¿ÉÈÌÊܵġ£µ«ÊÇt1¿ÉÒԺܴó£¬ÎªÊ²Ã´ÄØ£¿×îͨË×µÄÀí½â¾ÍÊÇÒòΪt1.x=t2.y¿ÉÒÔ×ßË÷Òý¡£µ«Õâ²¢²»ÊÇÒ»¸öºÜºÃµÄ½âÊÍ¡£ÊÔÏ룬Èç¹ût1.xºÍt2.y¶¼ÓÐË÷Òý£¬ÎÒÃÇÖªµÀË÷ÒýÊÇÖÖÓÐÐòµÄ½á¹¹£¬Òò´Ët1ºÍt2Ö®¼ä×î¼ÑµÄ·½°¸ÊÇ×ßmerge join¡£ÁíÍ⣬Èç¹ût2.yÉÏÓÐË÷Òý£¬¶Ôt2µÄÅÅÐòÐÔÄÜÒ²ÓкܴóÌá¸ß¡£
select * from t1 where exists ( select null from t2 where y = x )
¿ÉÒÔÀí½âΪ£º
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD!
end if
end loop
--Õâ¸ö¸üÈÝÒ×Àí½â£¬t1ÓÀÔ¶ÊǸö±íɨÃ裡Òò´Ët1¾ø¶Ô²»ÄÜÊǸö´ó±í£¬¶øt2¿ÉÒÔº
Ïà¹ØÎĵµ£º
MSDN: http://msdn.microsoft.com/en-us/library/bb386976.aspx £¨Ó¢ÎÄ£©
http://msdn.microsoft.com/zh-cn/library/bb386976.aspx £¨ÖÐÎÄ£©
ScottGu µÄLINQ ϵÁУº
Part 1: Introduction to LINQ to SQL
Part 2: Defining our Dat ......
½ñÌìÔÚ´¦ÀíÒ»¸öÓû§ÃûÊý¾Ý¿âʱ£¬·¢ÏÖÓÐЩ²»Õý³£µÄÊý¾Ý´æÔÚ£¬°´ÕÕÂß¼£¬Óû§ÃûÖ»ÄÜÊÇÊý×Ö£¬×Öĸ£¬Ï»®Ïߺʹ¿ÖÐÎÄÕâÑùµÄ×Ö·û×éºÏ´æÔÚ£¬²»Ó¦¸ÃÓÐÆäËû×éºÏ´æÔÚ£¬µ«ÊÇ·¢ÏÖÊý¾Ý¿âÖÐÓÉÓÚ¸÷ÖÖÀúÊ·ÔÒò£¬ÓÐЩ²»Õý³£µÄ´æÔÚ£¬ÈçºÎÕÒµ½ÕâЩÒì³£Êý¾Ý£¬ÔÚCSDNµÄ SQL Server °æÎÊÁËÕâÑùÁ½¸öÎÊÌ⣬ÈçÏ£º http://topic.csdn.net/u/20100111 ......
²éѯËÙ¶ÈÂýµÄÔÒòºÜ¶à£¬³£¼ûÈçϼ¸ÖÖ£º
¡¡¡¡1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
¡¡¡¡2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
¡¡¡¡3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
¡¡¡¡4¡¢ÄÚ´æ²»×ã
¡¡¡¡5¡¢ÍøÂçËÙ¶ÈÂý
¡¡¡¡6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó(¿ÉÒÔ²ÉÓöà ......
SQL²Ù×÷È«¼¯
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE ......
Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:mssql7backupMyNwind_1.dat'
--- ¿ªÊ¼±¸·Ý
BACKUP DATABASE pubs TO testBack
......