SQL»ù±¾Óï¾ä
¡¡¡¡SQL»ù±¾Óï¾ä
Ò». SQLµÄËÄÌõ×î»ù±¾µÄÊý¾Ý²Ù×÷Óï¾äΪInsert£¬Select£¬UpdateºÍDelete¡£
¶þ.Ê×ÏÈÎÒÃÇʹÓÃCREATE TABLEÓï¾äÀ´´´½¨Ò»¸ö±í¡£DDLÓï¾ä¶ÔÊý¾Ý¿â¶ÔÏóÈç±í¡¢ÁкÍÊÓ½øÐж¨Òå¡£ËüÃDz¢²»¶Ô±íÖеÄÐнøÐд¦Àí£¬ÕâÊÇÒòΪDDLÓï¾ä²¢²»´¦ÀíÊý¾Ý¿âÖÐʵ¼ÊµÄÊý¾Ý¡£ÕâЩ¹¤×÷ÓÉÁíÒ»ÀàSQLÓï¾ä—Êý¾Ý²Ù×÷ÓïÑÔ£¨DML£©Óï¾ä½øÐд¦Àí¡£
SQLÖÐÓÐËÄÖÖ»ù±¾µÄDML²Ù×÷£ºINSERT£¬SELECT£¬UPDATEºÍDELETE¡£ÓÉÓÚÕâÊÇ´ó¶àÊýSQLÓû§¾³£Óõ½µÄ£¬ÎÒÃÇÓбØÒªÔڴ˶ÔËüÃǽøÐÐһһ˵Ã÷¡£
(1)INSERTÓï¾ä
Óû§¿ÉÒÔÓÃINSERTÓï¾ä½«Ò»ÐмǼ²åÈëµ½Ö¸¶¨µÄÒ»¸ö±íÖС£ÀýÈ磬Ҫ½«¹ÍÔ±John SmithµÄ¼Ç¼²åÈëµ½±¾ÀýµÄ±íÖУ¬¿ÉÒÔʹÓÃÈçÏÂÓï¾ä£º
¡¡¡¡INSERT INTO EMPLOYEES VALUES
¡¡¡¡ ('Smith','John','1980-06-10',
¡¡¡¡ 'Los Angles',16,45000);
ÎÒÃÇ˵¹ýϵͳ»á“ÊÔ×Å”½«ÖµÌîÈ룬³ýÁËÖ´ÐйæÔòÖ®ÍâËü»¹Òª½øÐÐÀàÐͼì²é¡£Èç¹ûÀàÐͲ»·û£¨È罫һ¸ö×Ö·û´®ÌîÈëµ½ÀàÐÍΪÊý×ÖµÄÁÐÖУ©£¬ÏµÍ³½«¾Ü¾øÕâÒ»´Î²Ù×÷²¢·µ»ØÒ»¸ö´íÎóÐÅÏ¢¡£
Èç¹ûSQL¾Ü¾øÁËÄãËùÌîÈëµÄÒ»ÁÐÖµ£¬Óï¾äÖÐÆäËû¸÷ÁеÄÖµÒ²²»»áÌîÈë¡£ÕâÊÇÒòΪSQLÌṩ¶ÔÊÂÎñµÄÖ§³Ö¡£Ò»´ÎÊÂÎñ½«Êý¾Ý¿â´ÓÒ»ÖÖÒ»ÖÂÐÔתÒƵ½ÁíÒ»ÖÖÒ»ÖÂÐÔ¡£Èç¹ûÊÂÎñµÄijһ²¿·Öʧ°Ü£¬ÔòÕû¸öÊÂÎñ¶¼»áʧ°Ü£¬ÏµÍ³½«»á±»»Ö¸´£¨»ò³Æ֮Ϊ»ØÍË£©µ½´ËÊÂÎñ֮ǰµÄ״̬¡£
»Øµ½ÔÀ´µÄINSERTµÄÀý×Ó£¬Çë×¢ÒâËùÓеÄÕûÐÎÊ®½øÖÆÊý¶¼²»ÐèÒªÓõ¥ÒýºÅÒýÆðÀ´£¬¶ø×Ö·û´®ºÍÈÕÆÚÀàÐ͵ÄÖµ¶¼ÒªÓõ¥ÒýºÅÀ´Çø±ð¡£ÎªÁËÔö¼Ó¿É¶ÁÐÔ¶øÔÚÊý×Ö¼ä²åÈ붺ºÅ½«»áÒýÆð´íÎó¡£¼Çס£¬ÔÚSQLÖжººÅÊÇÔªËصķָô·û¡£
ͬÑùҪעÒâÊäÈëÎÄ×ÖֵʱҪʹÓõ¥ÒýºÅ¡£Ë«ÒýºÅÓÃÀ´·â×°ÏÞ½ç±êʶ·û¡£
¶ÔÓÚÈÕÆÚÀàÐÍ£¬ÎÒÃDZØÐëʹÓÃSQL±ê×¼ÈÕÆÚ¸ñʽ£¨yyyy-mm-dd£©£¬µ«ÊÇÔÚϵͳÖпÉÒÔ½øÐж¨Ò壬ÒÔ½ÓÊÜÆäËûµÄ¸ñʽ¡£µ±È»£¬2000ÄêÁÙ½ü£¬ÇëÄã×îºÃ»¹ÊÇʹÓÃËÄλÀ´±íʾÄê·Ý¡£
¼ÈÈ»ÄãÒѾÀí½âÁËINSERTÓï¾äÊÇÔõÑù¹¤×÷µÄÁË£¬ÈÃÎÒÃÇתµ½EMPLOYEES±íÖеÄÆäËû²¿·Ö£º
¡¡¡¡INSERT INTO EMPLOYEES VALUES
¡¡¡¡ ('Bunyan','Paul','1970-07-04',
¡¡¡¡ 'Boston',12,70000);
¡¡¡¡INSERT INTO EMPLOYEES VALUES
¡¡¡¡ ('John','Adams','1992-01-21',
¡¡¡¡ 'Boston',20,100000);
¡¡¡¡INSERT INTO EMPLOYEES VALUES
¡¡¡¡ ('Smith','Pocahontas','1976-04-06',
¡¡¡¡ 'Los Angles',12,100000);
¡¡¡¡INSERT INTO EMPLOYEES VALUES
¡¡¡¡ ('Smith','Bessie','1940-05-02',
¡¡¡¡ 'Boston',5
Ïà¹ØÎĵµ£º
µÍЧ: (Ë÷ÒýʧЧ)
SELECT … from DEPARTMENT WHERE DEPT_CODE IS NOT NULL;
¸ßЧ: (Ë÷ÒýÓÐЧ)
SELECT … from DEPARTMENT WHERE DEPT_CODE >=0;
£¨27£©×ÜÊÇʹÓÃË÷ÒýµÄµÚÒ»¸öÁУº
Èç¹ûË÷ÒýÊǽ¨Á¢ÔÚ¶à ......
×ö¿ª·¢¹ý³ÌÖУ¬¾³£»áÓõ½½«ExcelÖÐÊý¾Ýµ¼³öµ½SQL ServerÖеÄÇé¿ö£¬Äã¿ÉÒÔÀûÓÃSQL SERVER ÖÐ×Ô´øµÄµ¼ÈëÊý¾ÝµÄ·½Ê½£¬µ«ÕâÖÖ·½Ê½£¬ÓÐʱ»á·¢ÏÖÊý¾Ýµ¼Èëºó£¬¿ÉÄÜΪ¿Õ£¬¿ÉÄÜ¿ªÍ·ÉÙ¸öÁ㣬´ËÖÖÇé¿ö¶à³öÏÖÓÚÊýÖµÐ͵ÄÁУ¬½ñÌìÔÚCSDNÉÏÏй䣬ż¶û·¢ÏÖÁËÒ»¸öÌû×Ó£¬½éÉܵÄÒÔÏÂÕâÖÖ·½·¨£¬±¾ÈËÇ¡ÆßÒò×î½ü¹«Ë¾×¼±¸ÉÏÊУ¬Éó¼Æ¾ÖÔÚ×öÉó¼Æ£¬¼¼ ......
thunder:
1.MYSQLʵÏÖ
mysql> select * from user;
+----+----------+----------+-----------------+
| ID | username | password | email |
+----+----------+----------+-----------------+
| 1 | admin | admin &nb ......
CURSOR
==================================
l SQL ÓαêCURSORµÄʹÓÃ
ʹÓÃÆðÀ´ºÜ¼òµ¥£¬Ïȶ¨Ò壬Ȼºó¸³¸öÖµ£¬´ò¿ª£¬Í¨¹ýWhile Loop Ò»¸öÒ»¸ö¶ÁÏÂÈ¥£¬×îºó¹Ø±Õ£¬ÊÍ·ÅÄÚ´æ¡£»ù±¾Ì×·ÈçÏ£º
DECLARE MyCursor cursor /* ÉùÃ÷Óα꣬ĬÈÏΪµ¥´¿ÏòÇ°µÄÓαꡣÈç¹ûÏëҪǰºóÌøÀ´ÌøÈ¥µÄ£¬Ð´³ÉScroll Cursor¼ ......