¡¶£Ó£Ñ£Ì Óï·¨²Î¿¼ÊÖ²á(SQL)¡·
£Ó£Ñ£Ì Óï·¨²Î¿¼ÊÖ²á(SQL)/Êý¾ÝÀàÐÍ
DB2 ÌṩÁ˹ØÁ¬Ê½×ÊÁÏ¿âµÄ²éѯÓïÑÔ £Ó£Ñ£Ì (Structured Query Language)£¬ÊÇÒ»Öַdz£¿ÚÓﻯ¡¢¼ÈÒ×ѧÓÖÒ׶®µÄÓï·¨¡£´ËÒ»ÓïÑÔ¼¸ºõÊÇÿ¸ö×ÊÁÏ¿âϵͳ¶¼±ØÐëÌṩµÄ£¬ÓÃÒÔ±íʾ¹ØÁ¬Ê½µÄ*×÷£¬°üº¬ÁË×ÊÁϵĶ¨Ò壨£Ä£Ä£Ì£©ÒÔ¼°×ÊÁϵĴ¦Àí£¨£Ä£Í£Ì£©¡£SQLÔÀ´Æ´³ÉSEQUEL£¬ÕâÓïÑÔµÄÔÐÍÒԓϵͳ R“µÄÃû×ÖÔÚ IBM Ê¥ºÉÎ÷ʵÑéÊÒÍê³É£¬¾¹ýIBMÄÚ²¿¼°ÆäËûµÄÐí¶àʹÓÃÐÔ¼°Ð§ÂʲâÊÔ£¬Æä½á¹ûÏ൱ÁîÈËÂúÒ⣬²¢¾ö¶¨ÔÚϵͳR µÄ¼¼Êõ»ù´¡·¢Õ¹³öÀ´ IBM µÄ²úÆ·¡£¶øÇÒÃÀ¹ú¹ú¼Ò±ê׼ѧ»á£¨ANSI£©¼°¹ú¼Ê±ê×¼»¯×éÖ¯£¨ISO£©ÔÚ1987×ñÑÒ»¸ö¼¸ºõÊÇÒÔ IBM SQL Ϊ»ù´¡µÄ±ê×¼¹ØÁ¬Ê½×ÊÁÏÓïÑÔ¶¨Òå¡£
Ò»¡¢×ÊÁ϶¨Òå £Ä£Ä£Ì£¨Data Definition Language)
×ÊÁ϶¨ÓïÑÔÊÇÖ¸¶Ô×ÊÁϵĸñʽºÍÐÎ̬϶¨ÒåµÄÓïÑÔ£¬ËûÊÇÿ¸ö×ÊÁÏ¿âÒª½¨Á¢Ê±ºòʱÊ×ÏÈÒªÃæ¶ÔµÄ£¬¾Ù·²×ÊÁÏ·ÖÄÄЩ±í¸ñ¹Øϵ¡¢±í¸ñÄÚµÄÓÐʲ÷áÀ¸Î»Ö÷¼ü¡¢±í¸ñºÍ±í¸ñÖ®¼ä»¥Ïà²Î¿¼µÄ¹ØϵµÈµÈ£¬¶¼ÊÇÔÚ¿ªÊ¼µÄʱºòËù±ØÐë¹æ»®ºÃµÄ¡£
£±¡¢½¨±í¸ñ£º
Create TABLE table_name(
column1 DATATYPE [NOT NULL] [NOT NULL PRIMARY KEY],
column2 DATATYPE [NOT NULL],
...£©
˵Ã÷£º¡¡
DATATYPE --ÊÇ×ÊÁϵĸñʽ£¬Ïê¼û±í¡£
NUT NULL --¿É²»¿ÉÒÔÔÊÐí×ÊÁÏÓпյģ¨ÉÐδÓÐ×ÊÁÏÌîÈ룩¡£
PRIMARY KEY --ÊDZ¾±íµÄÖ÷¼ü¡£
£²¡¢¸ü¸Ä±í¸ñ¡¡
Alter TABLE table_name
ADD COLUMN column_name DATATYPE
˵Ã÷£ºÔö¼ÓÒ»¸öÀ¸Î»£¨Ã»ÓÐɾ³ýij¸öÀ¸Î»µÄÓï·¨¡£
Alter TABLE table_name
ADD PRIMARY KEY (column_name)
˵Ã÷£º¸ü¸Ä±íµÃµÄ¶¨Òå°Ñij¸öÀ¸Î»ÉèΪÖ÷¼ü¡£
Alter TABLE table_name
Drop PRIMARY KEY (column_name)
˵Ã÷£º°ÑÖ÷¼üµÄ¶¨Òåɾ³ý¡£
£³¡¢½¨Á¢Ë÷Òý¡¡
Create INDEX index_name ON table_name (column_name)
˵Ã÷£º¶Ôij¸ö±í¸ñµÄÀ¸Î»½¨Á¢Ë÷ÒýÒÔÔö¼Ó²éѯʱµÄËٶȡ£
£´¡¢É¾³ý¡¡
Drop table_name
Drop 
Ïà¹ØÎĵµ£º
1.²éѯµÄÄ£ºýÆ¥Åä
¾¡Á¿±ÜÃâÔÚÒ»¸ö¸´ÔÓ²éѯÀïÃæʹÓà LIKE '%parm1%'—— ºìÉ«±êʶλÖõİٷֺŻᵼÖÂÏà¹ØÁеÄË÷ÒýÎÞ·¨Ê¹Óã¬×îºÃ²»ÒªÓÃ.
½â¾ö°ì·¨:
ÆäʵֻÐèÒª¶Ô¸Ã½Å±¾ÂÔ×ö¸Ä½ø£¬²éѯËٶȱã»áÌá¸ß½ü°Ù±¶¡£¸Ä½ø·½·¨ÈçÏ£º
a¡¢ÐÞ¸Äǰ̨³ÌÐò——°Ñ²éѯÌõ¼þµÄ¹©Ó¦ÉÌÃû³ÆÒ»À¸ÓÉÔÀ´µÄÎı¾ÊäÈë¸ÄΪÏÂÀÁб ......
´Ó²»Í¬µÄ½Ç¶È£¬ÎÒÃÇ¿ÉÒÔ°ÑSQL ServerÊý¾Ýƽ̨»®·ÖΪ¶à¸ö×é¼þ¡£ÎÒÃÇÏÂÃæ°´ÕÕSQL Server Internal Teamͨ³£µÄ»®·ÖÔÔò£¬°ÑSQL ServerÊý¾Ýƽ̨»®·ÖΪÈçÏ£º
SSAS: SQL Server Analysis Service¡£Ö÷ÒªÓÃÀ´×ö·ÖÎöÓ㬱ÈÈçCube£¬¿ÉÒÔ´Ó²»Í¬µÄ½Ç¶ÈÉóÊÓÊý¾Ý¡£
SSIS: SQL Server Integration Servi ......
ÈçºÎ²é¿´SQL Server²¹¶¡°æ±¾ [http://www.cnblogs.com/yitian/articles/1285021.html]
1¡¢ÓÃIsql»òÕßSQL²éѯ·ÖÎöÆ÷µÇ¼µ½SQL Server£¬Èç¹ûÊÇÓÃIsql£¬ÇëÔÚcmd´°¿ÚÊäÈëisql -U sa,È»ºóÊäÈëÃÜÂ룬½øÈ룻Èç¹ûÊÇÓÃSQL²éѯ·ÖÎöÆ÷£¬Çë´Ó³ÌÐòÖÐÆô¶¯£¬ÊäÈësaºÍÃÜÂ루Ҳ¿ÉÒÔÓÃwindowsÑéÖ¤£©¡£
2¡¢ÔÚISQLÖÐÊäÈ ......
1¡£Sysdate µ±Ç°ÈÕÆÚºÍʱ¼ä
SQL> Select sysdate from dual;
SYSDATE
----------
21-6ÔÂ -05
2¡£Last_day ±¾ÔÂ×îºóÒ»Ìì
SQL> Select last_day(sysdate) from dual;
LAST_DAY(S
----------
30-6ÔÂ -05
3¡£Add_months(d,n) µ±Ç°ÈÕÆÚdºóÍÆn¸öÔÂ
ÓÃÓÚ´ÓÒ»¸öÈÕÆÚÖµÔö¼Ó»ò¼õÉÙһЩÔ·Ý
date_value:=add_mont ......