|
|
|
|
|
0 |
|
View Articles |
|
|
Name |
¼Õº´¸ñ |
(2002-05-09 05:40:35, Hit : 25603, Vote : 2048)
|
|
|
Homepage |
http://www.itmembers.net |
|
Subject |
[¸¶Áö¸·È¸] DDL(Data Definition Language) - CREATE VIEW |
|
|
µåµð¾î DB(¿À¶óŬ SQL) ÀÔ¹® °Á ¸¶Áö¸· ½Ã°£ÀÔ´Ï´Ù.
'ÀÔ¹®'ÀÇ ¹üÀ§°¡ ¾îµð±îÁöÀÎÁö´Â ¾îµð±îÁö³ª ÁÖ°üÀûÀÎ ÆÇ´Ü¿¡ ÀÇÇÑ °ÍÀÔ´Ï´Ù.
º» ÀÔ¹® °úÁ¤¿¡¼ »ý·«µÈ °ÍÀº,
SQL DDL Áß¿¡¼ CREATE TABLESPACE, ALTER TABLESAPCE, CREATE USER, ALTER USER, DROP USER, GRANT, REVOKE µî ÁÖ·Î DBA°¡ ´ã´çÇÏ´Â °Íµé°ú,
DML Áß¿¡¼´Â ´Ù¸¥ DBÀÇ ·¹Äڵ带 °Ë»öÇÏ´Â SELECT(UPDATE, INSERT,DELETE) ¡ FROM Å×À̺í@DB Çü½ÄÀÇ ¹®Àå µîÀÌ ÀÖ½À´Ï´Ù.
±× ¿Ü¿¡ SUBSELECT¿¡ ´ëÇؼµµ ÃæºÐÇÑ ½Ç½ÀÀÌ ¾ø¾ú°í, ÇÔ¼ö¿¡ ´ëÇؼµµ ±âº»ÀûÀÎ °Í¸¸ ´Ù·ð½À´Ï´Ù.
¿À´Ã ´Ù·ç´Â VIEW¿Í °ü·ÃÇؼµµ CREATE VIEW ¿Ü¿¡ DROP, SELECT, UPDATE, INSERT INTO, DELETE µî¿¡ ´ëÇؼ´Â ´Ù·çÁö ¾Ê¾Ò½À´Ï´Ù.
¹é¾÷ ¹× º¹±¸¿Í °ü·ÃµÈ ³»¿ë, SQL ÆíÁý ¸í·É µî¿¡ ´ëÇؼµµ ´Ù·çÁö ¾Ê¾Ò½À´Ï´Ù.
¸¸¾à ±âȸ°¡ µÈ´Ù¸é À§ÀÇ ³»¿ëµé·Î ¿À¶óŬ(SQL) Áß±Þ °Á¸¦ Çѹø ÁøÇàÇßÀ¸¸é ÇÏ´Â »ý°¢ÀÔ´Ï´Ù.
±×·³ DB ÀÔ¹® ¸¶Áö¸· ½Ã°£, CREATE VIEW ÇнÀÀ» ½ÃÀÛÇÕ´Ï´Ù.
VIEW´Â ¿À¶óŬ¿¡¼ Á¦°øÇÏ´Â °¡»óÀÇ Å×À̺í(Virtual Table)ÀÔ´Ï´Ù. ÀÌ¹Ì ¿ì¸° ¿©·¯ ½Ç½ÀÀ» ÅëÇØ ½ÇÁ¦ Å×À̺íÀ» ¸¸µé°í °Ë»öÇÏ´Â ÀϵéÀ» ÇغýÀ´Ï´Ù. VIEW´Â ½ÇÁ¦ Å×À̺íÀ» ¹ÙÅÁÀ¸·Î ¸¸µé¾îÁø °¡»óÀÇ Å×À̺íÀ̸ç, °Ë»ö µî ±âŸ »ç¿ë¹ýÀº ½ÇÁ¦ Å×À̺í°ú °ÅÀÇ À¯»çÇÕ´Ï´Ù.
µû¶ó¼ À̹ø ½Ã°£¿¡´Â VIEW¸¦ ¸¸µå´Â ¹æ¹ýÀ» ÁÖ·Î ´Ù·ç±â·Î ÇÏ°í, ±âŸ µ¥ÀÌÅÍ °Ë»ö, »èÁ¦, º¯°æ µîÀº ½ÇÁ¦ Å×À̺í·Î ÀÛ¾÷ÇÏ´Â °Í°ú °ÅÀÇ µ¿ÀÏÇϹǷΠµû·Î ¼³¸íÇÏÁö´Â ¾Ê°Ú½À´Ï´Ù.
- VIEW ¸¸µé±â
CREATE OR REPLACE VIEW view_name
AS query
[WITH CHECK OPTION]
[WITH READ ONLY];
Âü°í·Î ¸¸µé¾îÁø VIEW¸¦ »èÁ¦ÇÏ·Á¸é,
DROP VIEW view_name; ¶ó°í ÇÏ¸é µË´Ï´Ù.
ºä¸¦ ¸¸µé ¶§ CREATE OR RELPACE VIEW ´ë½Å ±×³É CREATE VIEW¸¸ »ç¿ëÇصµ µË´Ï´Ù. ±×·¯³ª ±×³É CREATE VIEW¸¦ ÅëÇØ ¸¸µé¾îÁø ºäÀÇ ±¸Á¶¸¦ ¹Ù²Ù·Á¸é ºä¸¦ »èÁ¦ÇÏ°í ´Ù½Ã ¸¸µé¾î¾ß µÇ´Â ¹Ý¸é, CREATE OR REPLACE VIEW´Â »õ·Î¿î ºä¸¦ ¸¸µé°Å³ª ±âÁ¸ÀÇ ºä¸¦ ÅëÇØ »õ·Î¿î ±¸Á¶ÀÇ ºä¸¦ ¸¸µé ¼öµµ ÀÖ½À´Ï´Ù. ±×·¡¼ ´ëºÎºÐ ºä¸¦ ¸¸µé ¶§´Â CREATE VIEW ´ë½Å CREATE OR REPLACE VIEW¸¦ »ç¿ëÇÏ´Â ÆíÀÔ´Ï´Ù.
- VIEW¿¡´Â VIEW¸¦ »ý¼ºÇÏ´Â SELECT ¹®¸¸ ÀúÀåµË´Ï´Ù. Áï ½ÇÁ¦·Î Å×À̺íÀº Á¸ÀçÇÏÁö ¾ÊÀ¸¸ç, VIEW¸¦ SELECT ¹®À¸·Î °Ë»öÇÏ´Â ¼ø°£ ½ÇÁ¦ Å×À̺íÀ» ÂüÁ¶ÇÏ¿© º¸¿©ÁÝ´Ï´Ù.
- VIEWÀÇ query¹®¿¡´Â ORDER BY ÀýÀ» »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.
- WITH CHECK OPTIONÀ» »ç¿ëÇϸé, ÇØ´ç VIEW¸¦ ÅëÇؼ º¼ ¼ö ÀÖ´Â ¹üÀ§ ³»¿¡¼¸¸ UPDATE ¶Ç´Â INSERT°¡ °¡´ÉÇÏÇÕ´Ï´Ù.
¿¹¸¦ µé¾î,
CREATE OR REPLACE VIEW V_EMP_SKILL
AS
SELECT *
FROM EMP_SKILL
WHERE AVAILABLE = 'YES'
WITH CHECK OPTION;
À§¿Í °°ÀÌ WITH CHECK OPTIONÀ» »ç¿ëÇÏ¿© ºä¸¦ ¸¸µé¸é, AVAILABLE Ä÷³ÀÌ 'YES'°¡ ¾Æ´Ñ µ¥ÀÌÅÍ´Â VIEW¸¦ ÅëÇØ ÀÔ·ÂÇÒ ¼ö ¾ø½À´Ï´Ù. Áï, ¾Æ·¡¿Í °°ÀÌ ÀÔ·ÂÇÏ´Â °ÍÀº 'ºÒ°¡´É'ÇÏ´Ù´Â °ÍÀÔ´Ï´Ù.
INSERT INTO V_EMP_SKILL
VALUES('10002', 'C101', '01/11/02','NO');
- WITH READ ONLYÀ» »ç¿ëÇϸé ÇØ´ç VIEW¸¦ ÅëÇؼ´Â SELECT¸¸ °¡´ÉÇϸç INSERT/UPDATE/DELETE¸¦ ÇÒ ¼ö ¾ø°Ô µË´Ï´Ù. ¸¸¾à ÀÌ°ÍÀ» »ý·«ÇÑ´Ù¸é, ºä¸¦ »ç¿ëÇÏ¿© Create, Update, Delete µî ¸ðµÎ °¡´ÉÇÕ´Ï´Ù.
- VIEW ¸¸µé±â ½Ç½À
EMP_SKILL Å×À̺í°ú SKILL Å×À̺íÀÇ EMP_NUM, SKILL_NO, SKILL_NAME Ä÷³À» º¼ ¼ö ÀÖ´Â ºä(V_EMP_SKILL2) ¸¸µé±â
CREATE OR REPLACE VIEW V_EMP_SKILL2
AS
SELECT A.EMP_NUM, A.SKILL_NO, B.SKILL_NAME
FROM EMP_SKILL A, SKILL B
WHERE A.SKILL_NO = B.SKILL_NO;
- VIEW °Ë»ö ½Ç½À
À§¿¡¼ ¸¸µç V_EMP_SKILL2 ºäÀÇ ³»¿ëÀ» °Ë»öÇÏ·Á¸é ÀÏ¹Ý Å×À̺íÀ» °Ë»öÇϵíÀÌ ´ÙÀ½°ú °°ÀÌ ÇÏ¸é µË´Ï´Ù.
SELECT * FROM V_EMP_SKILL2;
ÀÌ»óÀ¸·Î DB ÀÔ¹® °Á¸¦ ¸ðµÎ ¸¶Ä¨´Ï´Ù.
Áö±Ý±îÁö µ¿ÁÖ ¾Æºü ¼Õº´¸ñÀ̾ú½À´Ï´Ù.
|
|
|
|
|
|