sqlÓï¾äÓÅ»¯2
£¨18£©ÓÃEXISTSÌæ»»DISTINCT£º
µ±Ìá½»Ò»¸ö°üº¬Ò»¶Ô¶à±íÐÅÏ¢(±ÈÈ粿ÃűíºÍ¹ÍÔ±±í)µÄ²éѯʱ,±ÜÃâÔÚSELECT×Ó¾äÖÐʹÓÃDISTINCT¡£Ò»°ã¿ÉÒÔ¿¼ÂÇÓÃEXISTÌæ»», EXISTS ʹ²éѯ¸üΪѸËÙ,ÒòΪRDBMSºËÐÄÄ£¿é½«ÔÚ×Ó²éѯµÄÌõ¼þÒ»µ©Âú×ãºó,Á¢¿Ì·µ»Ø½á¹û¡£Àý×Ó£º
(µÍЧ):
SELECT DISTINCT DEPT_NO,DEPT_NAME from DEPT D , EMP E
WHERE D.DEPT_NO = E.DEPT_NO
(¸ßЧ):
SELECT DEPT_NO,DEPT_NAME from DEPT D WHERE EXISTS ( SELECT ‘X'
from EMP E WHERE E.DEPT_NO = D.DEPT_NO);
£¨19£©SQLÓï¾äÓôóдµÄ£»ÒòΪOracle×ÜÊÇÏȽâÎöSQLÓï¾ä£¬°ÑСдµÄ×Öĸת»»³É´óдµÄÔÙÖ´ÐС£
£¨20£©ÔÚJava´úÂëÖо¡Á¿ÉÙÓÃÁ¬½Ó·û“£«”Á¬½Ó×Ö·û´®¡£
£¨21£©±ÜÃâÔÚË÷ÒýÁÐÉÏʹÓÃNOTͨ³££¬ÎÒÃÇÒª±ÜÃâÔÚË÷ÒýÁÐÉÏʹÓÃNOT, NOT»á²úÉúÔÚºÍÔÚË÷ÒýÁÐÉÏʹÓú¯ÊýÏàͬµÄÓ°Ïì¡£µ±Oracle“Óöµ½”NOT,Ëû¾Í»áֹͣʹÓÃË÷Òýת¶øÖ´ÐÐÈ«±íɨÃè¡£
£¨22£©±ÜÃâÔÚË÷ÒýÁÐÉÏʹÓüÆËã¡£WHERE×Ó¾äÖУ¬Èç¹ûË÷ÒýÁÐÊǺ¯ÊýµÄÒ»²¿·Ö¡£ÓÅ»¯Æ÷½«²»Ê¹ÓÃË÷Òý¶øÊ¹ÓÃÈ«±íɨÃè¡£
¾ÙÀý:
µÍЧ£º
SELECT … from DEPT WHERE SAL * 12 > 25000;
¸ßЧ:
SELECT … from DEPT WHERE SAL > 25000/12;
£¨23£©ÓÃ>=Ìæ´ú>£º
¸ßЧ:
SELECT * from EMP WHERE DEPTNO >=4
µÍЧ:
SELECT * from EMP WHERE DEPTNO >3
Á½ÕßµÄÇø±ðÔÚÓÚ, ǰÕßDBMS½«Ö±½ÓÌøµ½µÚÒ»¸öDEPTµÈÓÚ4µÄ¼Ç¼¶øºóÕß½«Ê×Ïȶ¨Î»µ½DEPTNO=3µÄ¼Ç¼²¢ÇÒÏòǰɨÃèµ½µÚÒ»¸öDEPT´óÓÚ3µÄ¼Ç¼¡£
£¨24£©ÓÃUNIONÌæ»»OR (ÊÊÓÃÓÚË÷ÒýÁÐ)£º
ͨ³£Çé¿öÏÂ, ÓÃUNIONÌæ»»WHERE×Ó¾äÖеÄOR½«»áÆðµ½½ÏºÃµÄЧ¹û¡£¶ÔË÷ÒýÁÐʹÓÃOR½«Ôì³ÉÈ«±íɨÃè¡£×¢Òâ, ÒÔÉϹæÔòÖ»Õë¶Ô¶à¸öË÷ÒýÁÐÓÐЧ. Èç¹ûÓÐcolumnûÓб»Ë÷Òý, ²éѯЧÂÊ¿ÉÄÜ»áÒòΪÄãûÓÐÑ¡ÔñOR¶ø½µµÍ¡£ÔÚÏÂÃæµÄÀý×ÓÖÐ, LOC_ID ºÍREGIONÉ϶¼½¨ÓÐË÷Òý¡£
¸ßЧ:
SELECT LOC_ID , LOC_DESC , REGION
from LOCATION
WHERE LOC_ID = 10
UNION
SELECT
Ïà¹ØÎĵµ£º
1.Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)¡¡¡¡
¡¡¡¡ SQLSERVERµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬Òò´Ëfrom×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±ídriving table£©½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í£¬µ±SQLSERVER´¦Àí¶à¸ö±íʱ£¬»áÔËÓÃÅÅÐò¼°ºÏ²¢µÄ·½Ê½Á ......
Èç¹ûÄã¾³£Óöµ½ÏÂÃæµÄÎÊÌ⣬Äã¾ÍÒª¿¼ÂÇʹÓÃSQL ServerµÄÄ£°åÀ´Ð´¹æ·¶µÄSQLÓï¾äÁË£º
SQL³õѧÕß¡£
¾³£Íü¼Ç³£ÓõÄDML»òÊÇDDL SQL Óï¾ä¡£
ÔÚ¶àÈË¿ª·¢Î¬»¤µÄSQLÖУ¬Ã¿¸öÈ˶¼ÓÐ×Ô¼ºµÄSQLϰ¹ß£¬Ã»ÓÐÒ»Ì×ͳһµÄ¹æ·¶¡£
ÔÚSQL Server Management StudioÖУ¬ÒѾ¸ø´ó¼ÒÌṩÁ˺ܶೣÓõÄÏÖ³ÉSQL¹æ·¶Ä£°å¡£
SQL Server Management ......
֮ǰÓÐÒ»¸öSQLServerµÄ·ÖÒ³´æ´¢¹ý³Ì µ«ÊÇÐÔÄܲ»ÊÇÊ®·ÖÀíÏë
ÓÖÕÒÁËÒ»¸ö
--SQL2005·ÖÒ³´æ´¢¹ý³Ì
/**
if exists(select * from sysobjects where name='fenye')
drop proc fenye
**/
CREATE procedure fenye
@tableName nvarchar(200) ,
@pageSize int,
@curPage int ,
......
Table-Naming Standards
Table-naming standards, as well as any standard within a business, are critical to
maintaining control. After studying the tables and data in the previous sections, you
probably noticed that each table’s suffix is _TBL. This is a naming standard selected
for use, suc ......