MySqlÖд´½¨ÊÓͼ
CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
¸ÃÓï¾äÄÜ´´½¨ÐµÄÊÓͼ£¬Èç¹û¸ø¶¨ÁËOR REPLACE×Ӿ䣬¸ÃÓï¾ä»¹ÄÜÌæ»»ÒÑÓеÄÊÓͼ¡£select_statementÊÇÒ»ÖÖSELECTÓï¾ä£¬Ëü¸ø³öÁËÊÓͼµÄ¶¨Òå¡£¸ÃÓï¾ä¿É´Ó»ù±í»òÆäËûÊÓͼ½øÐÐÑ¡Ôñ¡£
¸ÃÓï¾äÒªÇó¾ßÓÐÕë¶ÔÊÓͼµÄCREATE VIEWȨÏÞ£¬ÒÔ¼°Õë¶ÔÓÉSELECTÓï¾äÑ¡ÔñµÄÿһÁÐÉϵÄijЩȨÏÞ¡£¶ÔÓÚÔÚSELECTÓï¾äÖÐÆäËûµØ·½Ê¹ÓõÄÁУ¬±ØÐë¾ßÓÐSELECTȨÏÞ¡£Èç¹û»¹ÓÐOR REPLACE×Ӿ䣬±ØÐëÔÚÊÓͼÉϾßÓÐDROPȨÏÞ¡£
ÊÓͼÊôÓÚÊý¾Ý¿â¡£ÔÚĬÈÏÇé¿öÏ£¬½«ÔÚµ±Ç°Êý¾Ý¿â´´½¨ÐÂÊÓͼ¡£ÒªÏëÔÚ¸ø¶¨Êý¾Ý¿âÖÐÃ÷È·´´½¨ÊÓͼ£¬´´½¨Ê±£¬Ó¦½«Ãû³ÆÖ¸¶¨Îªdb_name.view_name¡£
mysql> CREATE VIEW test.v AS SELECT * from t;
±íºÍÊÓͼ¹²ÏíÊý¾Ý¿âÖÐÏàͬµÄÃû³Æ¿Õ¼ä£¬Òò´Ë£¬Êý¾Ý¿â²»ÄÜ°üº¬¾ßÓÐÏàͬÃû³ÆµÄ±íºÍÊÓͼ¡£
ÊÓͼ±ØÐë¾ßÓÐΨһµÄÁÐÃû£¬²»µÃÓÐÖظ´£¬¾ÍÏñ»ù±íÄÇÑù¡£Ä¬ÈÏÇé¿öÏ£¬ÓÉSELECTÓï¾ä¼ìË÷µÄÁÐÃû½«ÓÃ×÷ÊÓͼÁÐÃû¡£ÒªÏëΪÊÓͼÁж¨ÒåÃ÷È·µÄÃû³Æ£¬¿ÉʹÓÿÉÑ¡µÄcolumn_list×Ӿ䣬ÁгöÓɶººÅ¸ô¿ªµÄID¡£column_listÖеÄÃû³ÆÊýÄ¿±ØÐëµÈÓÚSELECTÓï¾ä¼ìË÷µÄÁÐÊý¡£
SELECTÓï¾ä¼ìË÷µÄÁпÉÒÔÊǶԱíÁеļòµ¥ÒýÓá£Ò²¿ÉÒÔÊÇʹÓú¯Êý¡¢³£Á¿Öµ¡¢²Ù×÷·ûµÈµÄ±í´ïʽ¡£
¶ÔÓÚSELECTÓï¾äÖв»ºÏ¸ñµÄ±í»òÊÓͼ£¬½«¸ù¾ÝĬÈϵÄÊý¾Ý¿â½øÐнâÊÍ¡£Í¨¹ýÓÃÇ¡µ±µÄÊý¾Ý¿âÃû³ÆÏÞ¶¨±í»òÊÓͼÃû£¬ÊÓͼÄܹ»ÒýÓñí»òÆäËûÊý¾Ý¿âÖеÄÊÓͼ¡£
Äܹ»Ê¹ÓöàÖÖSELECTÓï¾ä´´½¨ÊÓͼ¡£ÊÓͼÄܹ»ÒýÓûù±í»òÆäËûÊÓͼ¡£ËüÄÜʹÓÃÁªºÏ¡¢UNIONºÍ×Ó²éѯ¡£SELECTÉõÖÁ²»ÐèÒýÓÃÈÎºÎ±í¡£ÔÚÏÂÃæµÄʾÀýÖУ¬¶¨ÒåÁË´ÓÁíÒ»±íÑ¡ÔñÁ½ÁеÄÊÓͼ£¬²¢¸ø³öÁ˸ù¾ÝÕâЩÁмÆËãµÄ±í´ïʽ£º
mysql> CREATE TABLE t (qty INT, price INT);
mysql> INSERT INTO t VALUES(3, 50);
mysql> CREATE VIEW v AS SELECT qty, price, qty*price AS value from t;
mysql> SELECT * from v;
+------+-------+-------+
| qty | price | value |
+------+-------+-------+
| 3 | 50 | 150 |
+------+-------+-------+
ÊÓͼ¶¨Òå·þ´ÓÏÂÊöÏÞÖÆ£º
· SELECTÓï¾ä²»ÄÜ°üº¬from×Ó¾äÖеÄ×Ó²éѯ¡£
·
Ïà¹ØÎĵµ£º
MysqlËùÖ§³ÖµÄÒýÇæÄ¿Ç°ÓÐÒÔϼ¸ÖÖ£º
MyISAM,InnoDB,MERGE,MEMORY(HEAR),BDB(BerkeleyDB),EXAMPLE,FEDERATED,ARCHIVE,CSV,BLACKHOLE.
ΪʲôҪÓÐÕâô¶àÒýÇ棿Ö÷ÒªÊÇMysqlÊÇÒ»¿î¼«ÎªÇ¿´óµÄÊý¾Ý¿â£¬ËüÊÊÓ¦ºÜ¶à²»Í¬µÄÔËÐл·¾³£¬ÎªÁËÂú×ã¸÷ÖÖ²»Í¬µÄÔËÐл·¾³Óë´æ´¢·½°¸µÄÐèÒª£¬ÕâЩËÑË÷ÒýÇæÒ²¾ÍÓ¦Ô˶øÉú£¨²»¹âÊÇΪÁËÅäºÏMysql ......
MySQL Workbench ÊÇ MySQL ×î½üÊͷŵĿÉÊÓÊý¾Ý¿âÉè¼Æ¹¤¾ß¡£Õâ¸ö¹¤¾ßÊÇÉè¼Æ MySQL Êý¾Ý¿âµÄרÓù¤¾ß¡£
ÄãÔÚ MySQL Workbench Öн¨Á¢µÄ±»³Æ֮ΪÎïÀíÊý¾ÝÄ£ÐÍ¡£Ò»¸öÎïÀíÊý¾ÝÄ£ÐÍÊÇÕë¶ÔÒ»¸öÌض¨ RDBMS ²úÆ·µÄÊý¾ÝÄ£ÐÍ£»±¾ÎÄÖеÄÄ£Ðͽ«¾ßÓÐһЩ MySQL µÄ¶ÀÌع淶¡£ÎÒÃÇ¿ÉÒÔʹÓÃËüÉú³É£¨forward-engineer£©Êý¾Ý¿â¶ÔÏ󣬳ýÁË°üº¬± ......
ÏñMySQLÕâÑùµÄ¹ØϵÐÍÊý¾Ý¿â¹ÜÀíϵͳ£¬ËüÃǵĻù´¡ÊÇÔÚÊý¾Ý¿âµÄ±íÖ®¼ä´´½¨¹ØϵµÄÄÜÁ¦¡£Í¨¹ý·½±ãµØÔÚ²»Í¬±íÖн¨Á¢¼Ç¼µ½¼Ç¼µÄÁªÏµ£¬RDBMS¿ÉÒÔÀûÓò»Í¬µÄ·½·¨·ÖÎöÊý¾Ý£¬Í¬Ê±±£³ÖÊý¾Ý¿âÒÔϵͳµÄ·½Ê½¡¢×îСµÄÈßÓà½øÐÐ×éÖ¯¡£
¼òµ¥ÃèÊö£º
ÕâЩ¹Øϵ»ù±¾ÉÏÒÀ¿¿Íâ¼ü½øÐйÜÀí£¬ÔÚ¹ØϵÖÐËùÓбíÖоßÓÐÏàͬº¬ÒåµÄ×Ö¶Î×÷Ϊ¹«¹²²¿·ÖÀ´Á¬½Ó ......
Ë÷ÒýÓÃÓÚ¿ìËÙÕÒ³öÔÚij¸öÁÐÖÐÓÐÒ»Ìض¨ÖµµÄÐС£²»Ê¹ÓÃË÷Òý£¬MySQL±ØÐë´ÓµÚ1Ìõ¼Ç¼¿ªÊ¼È»ºó¶ÁÍêÕû¸ö±íÖ±µ½ÕÒ³öÏà¹ØµÄÐС£±íÔ½´ó£¬»¨·ÑµÄʱ¼äÔ½¶à¡£Èç¹û±íÖвéѯµÄÁÐÓÐÒ»¸öË÷Òý£¬MySQLÄÜ¿ìËÙµ½´ïÒ»¸öλÖÃÈ¥ËÑÑ°µ½Êý¾ÝÎļþµÄÖм䣬ûÓбØÒª¿´ËùÓÐÊý¾Ý¡£Èç¹ûÒ»¸ö±íÓÐ1000ÐУ¬Õâ±È˳Ðò¶ÁÈ¡ÖÁÉÙ¿ì100±¶¡£×¢ÒâÈç¹ûÄãÐèÒª·ÃÎÊ ......