|
Ïðîãðàììèðîâàíèå >> Ïîíÿòèå sql
ÎÏÅÐÀÒÎÐ IN...............................................................................................................................................................................39 ÎÏÅÐÀÒÎÐ BETWEEN................................................................................................................................................................40 ÎÏÅÐÀÒÎÐ LIKE...........................................................................................................................................................................42 ÐÀÁÎÒÀ Ñ ÍÓËÅÂÛÌÈ (NULL) ÇÍÀ×ÅÍÈßÌÈ........................................................................................................................44 NULL ÎÏÅÐÀÒÎÐ.........................................................................................................................................................................44 ÈÑÏÎËÜÇÎÂÀÍÈÅ NOT ÑÎ ÑÏÅÖÈÀËÜÍÛÌÈ ÎÏÅÐÀÒÎÐÀÌÈ........................................................................................45 ÐÅÇÞÌÅ........................................................................................................................................................................................46 ÐÀÁÎÒÀ Ñ SQL.............................................................................................................................................................................46 ÎÁÎÁÙÅÍÈÅ ÄÀÍÍÛÕ Ñ ÏÎÌÎÙÜÞ ÀÃÐÅÃÀÒÍÛÕ ÔÓÍÊÖÈÉ............................................47 ×ÒÎ ÒÀÊÎÅ ÀÃÐÅÃÀÒÍÛÅ ÔÓÍÊÖÈÈ ?....................................................................................................................................48 ÊÀÊ ÈÑÏÎËÜÇÎÂÀÒÜ ÀÃÐÅÃÀÒÍÛÅ ÔÓÍÊÖÈÈ ?...................................................................................................................48 ÑÏÅÖÈÀËÜÍÛÅ ÀÒÐÈÁÓÒÛ COUNT........................................................................................................................................49 ÈÑÏÎËÜÇÎÂÀÍÈÅ DISTINCT....................................................................................................................................................49 ÈÑÏÎËÜÇÎÂÀÍÈÅ COUNT ÑÎ ÑÒÐÎÊÀÌÈ, À ÍÅ ÇÍÀ×ÅÍÈßÌÈ.......................................................................................50 ÂÊËÞ×ÅÍÈÅ ÄÓÁËÈÊÀÒΠ ÀÃÐÅÃÀÒÍÛÅ ÔÓÍÊÖÈÈ........................................................................................................50 ÀÃÐÅÃÀÒÛ ÏÎÑÒÐÎÅÍÍÛÅ ÍÀ ÑÊÀËßÐÍÎÌ ÂÛÐÀÆÅÍÈÈ...............................................................................................51 ÏÐÅÄËÎÆÅÍÈÅ GROUP BY.......................................................................................................................................................51 ÏÐÅÄËÎÆÅÍÈÅ HAVING............................................................................................................................................................53 ÍÅ ÄÅËÀÉÒÅ ÂËÎÆÅÍÍÛÕ ÀÃÐÅÃÀÒÎÂ.................................................................................................................................54 ÐÅÇÞÌÅ........................................................................................................................................................................................55 ÐÀÁÎÒÀ Ñ SQL.............................................................................................................................................................................55 ÔÎÐÌÈÐÎÂÀÍÈÅ ÂÛÂÎÄΠÇÀÏÐÎÑÎÂ.................................................................................56 ÑÒÐÎÊÈ È ÂÛÐÀÆÅÍÈß............................................................................................................................................................57 ÓÏÎÐßÄÎ×ÅÍÈÅ ÂÛÂÎÄÀ ÏÎËÅÉ..........................................................................................................................................59 ÐÅÇÞÌÅ........................................................................................................................................................................................63 ÐÀÁÎÒÀ Ñ SQL.............................................................................................................................................................................63 ÇÀÏÐÀØÈÂÀÍÈÅ ÌÍÎÃÎ×ÈÑËÅÍÛÕ ÒÀÁËÈÖ ÒÀÊ ÆÅ, ÊÀÊ ÎÄÍÎÉ...................................64 ÎÁÚÅÄÈÍÅÍÈÅ ÒÀÁËÈÖ............................................................................................................................................................65 ÈÌÅÍÀ ÒÀÁËÈÖ È ÑÒÎËÁÖÎÂ..................................................................................................................................................65 ÑÎÇÄÀÍÈÅ ÎÁÜÅÄÈÍÅÍÈß......................................................................................................................................................65 ÎÁÚÅÄÈÍÅÍÈÅ ÒÀÁËÈÖ ×ÅÐÅÇ ÑÏÐÀÂÎ×ÍÓÞ ÖÅËÎÑÒÍÎÑÒÜ......................................................................................66 ÎÁÚÅÄÈÍÅÍÈß ÒÀÁËÈÖ ÏÎ ÐÀÂÅÍÑÒÂÓ ÇÍÀ×ÅÍÈÉ Â ÑÒÎËÁÖÀÕ È ÄÐÓÃÈÅ ÂÈÄÛ ÎÁÚÅÄÈÍÅÍÈÉ...................67 ÎÁÚÅÄÈÍÅÍÈÅ ÁÎËÅÅ ÄÂÓÕ ÒÀÁËÈÖ....................................................................................................................................68 ÐÅÇÞÌÅ........................................................................................................................................................................................69 ÐÀÁÎÒÀ Ñ SQL.............................................................................................................................................................................69 ÎÁÚÅÄÈÍÅÍÈÅ ÒÀÁËÈÖÛ Ñ ÑÎÁÎÉ........................................................................................70 ÊÀÊ ÄÅËÀÒÜ ÎÁÚÅÄÈÍÅÍÈÅ ÒÀÁËÈÖÛ Ñ ÑÎÁÎÉ ?............................................................................................................71 ÏÑÅÂÄÎÍÈÌÛ.............................................................................................................................................................................71 ÓÑÒÐÀÍÅÍÈÅ ÈÇÁÛÒÎ×ÍÎÑÒÈ...............................................................................................................................................72 ÏÐÎÂÅÐÊÀ ÎØÈÁÎÊ...................................................................................................................................................................73 ÁÎËÜØÅ ÏÑÅÂÄÎÍÈÌÎÂ..........................................................................................................................................................74 ÅÙÅ ÁÎËÜØÅ ÊÎÌÏËÅÊÑÍÛÕ ÎÁÚÅÄÈÍÅÍÈÉ....................................................................................................................74 ÐÅÇÞÌÅ........................................................................................................................................................................................76 ÐÀÁÎÒÀ Ñ SQL.............................................................................................................................................................................76 ÂÑÒÀÂÊÀ ÎÄÍÎÃÎ ÇÀÏÐÎÑÀ ÂÍÓÒÐÜ ÄÐÓÃÎÃÎ.....................................................................77 ÊÀÊ ÐÀÁÎÒÀÅÒ ÏÎÄÇÀÏÐÎÑ?..................................................................................................................................................78 ÇÍÀ×ÅÍÈß, ÊÎÒÎÐÛÅ ÌÎÃÓÒ ÂÛÄÀÂÀÒÜ ÏÎÄÇÀÏÐÎÑÛ.................................................................................................79 DISTINCT Ñ ÏÎÄÇÀÏÐÎÑÀÌÈ...................................................................................................................................................79 ÏÐÅÄÈÊÀÒÛ Ñ ÏÎÄÇÀÏÐÎÑÀÌÈ ßÂËßÞÒÑß ÍÅÎÁÐÀÒÈÌÛÌÈ......................................................................................80 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÀÃÐÅÃÀÒÍÛÕ ÔÓÍÊÖÈÉ Â ÏÎÄÇÀÏÐÎÑÀÕ..........................................................................................81 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÏÎÄÇÀÏÐÎÑÎÂ, ÊÎÒÎÐÛÅ ÂÛÄÀÞÒ ÌÍÎÃÎ ÑÒÐÎÊ Ñ ÏÎÌÎÙÜÞ ÎÏÅÐÀÒÎÐÀ IN.................82 ÏÎÄÇÀÏÐÎÑÛ ÂÛÁÈÐÀÞÒ ÎÄÈÍÎ×ÍÛÅ ÑÒÎËÁÖÛ..........................................................................................................84 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÂÛÐÀÆÅÍÈÉ Â ÏÎÄÇÀÏÐÎÑÀÕ.............................................................................................................84 ÏÎÄÇÀÏÐÎÑÛ Â ÏÐÅÄËÎÆÅÍÈÈ HAVING.............................................................................................................................85 ÐÅÇÞÌÅ........................................................................................................................................................................................86 ÐÀÁÎÒÀ Ñ SQL.............................................................................................................................................................................86 ÑÎÎÒÍÅÑÅÍÍÛÅ ÏÎÄÇÀÏÐÎÑÛ...............................................................................................87 ÊÀÊ ÑÔÎÐÌÈÐÎÂÀÒÜ ÑÎÎÒÍÅÑÅÍÍÛÉ ÏÎÄÇÀÏÐÎÑ.......................................................................................................88 ÊÀÊ ÐÀÁÎÒÀÅÒ ÑÎÎÒÍÅÑÅÍÍÛÉ ÏÎÄÇÀÏÐÎÑ...................................................................................................................88 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÑÎÎÒÍÅÑÅÍÍÛÕ ÏÎÄÇÀÏÐÎÑΠÄËß ÍÀÕÎÆÄÅÍÈß ÎØÈÁÎÊ...................................................91 ÑÐÀÂÍÅÍÈÅ ÒÀÁËÈÖÛ Ñ ÑÎÁÎÉ............................................................................................................................................91 ÑÎÎÒÍÅÑÅÍÍÛÅ ÏÎÄÇÀÏÐÎÑÛ Â ÏÐÅÄËÎÆÅÍÈÈ HAVING............................................................................................92 ÑÎÎÒÍÅÑÅÍÍÛÅ ÏÎÄÇÀÏÐÎÑÛ È ÎÁÜÅÄÈÍÅÍÈß............................................................................................................93 ÐÅÇÞÌÅ........................................................................................................................................................................................93 ÐÀÁÎÒÀ Ñ SQL.............................................................................................................................................................................94 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÎÏÅÐÀÒÎÐÀ EXISTS...................................................................................95 ÊÀÊ ÐÀÁÎÒÀÅÒ EXISTS?.............................................................................................................................................................96 ÂÛ1ÁÎÐÑÒÎËÁÖÎÂÑ ÏÎÌÎÙÜÞ EXISTS.............................................................................................................................97 ÈÑÏÎËÜÇÎÂÀÍÈÅ EXISTS Ñ ÑÎÎÒÍÅÑÅÍÍÛÌÈ ÏÎÄÇÀÏÐÎÑÀÌÈ................................................................................97 ÊÎÌÁÈÍÀÖÈß ÈÇ EXISTS È ÎÁÜÅÄÈÍÅÍÈß.........................................................................................................................98 ÈÑÏÎËÜÇÎÂÀÍÈÅ NOT EXISTS................................................................................................................................................99 EXISTS È ÀÃÐÅÃÀÒÛ...................................................................................................................................................................99 ÁÎËÅÅ ÓÄÀ×ÍÛÉ ÏÐÈÌÅÐ ÏÎÄÇÀÏÐÎÑÀ...........................................................................................................................100 ÐÅÇÞÌÅ......................................................................................................................................................................................101 ÐÀÁÎÒÀ Ñ SQL...........................................................................................................................................................................101 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÎÏÅÐÀÒÎÐΠANY, ALL È SOME............................................................102 ÑÏÅÖÈÀËÜÍÛÅ ÎÏÅÐÀÒÎÐÛ ANY èëè SOME.....................................................................................................................103 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÎÏÅÐÀÒÎÐΠIN ÈËÈ EXISTS ÂÌÅÑÒÎ ÎÏÅÐÀÒÎÐÀ ANY.............................................................104 ÊÀÊ ANY ÌÎÆÅÒ ÑÒÀÒÜ ÍÅÎÄÍÎÇÍÀ×ÍÛÌ.......................................................................................................................105 ÑÏÅÖÈÀËÜÍÛÉ ÎÏÅÐÀÒÎÐ ALL............................................................................................................................................108 ÐÀÂÅÍÑÒÂÀ È ÍÅÐÀÂÅÍÑÒÂÀ................................................................................................................................................109 ÏÐÀÂÈËÜÍÎÅ ÏÎÍÈÌÀÍÈÅ ANY È ALL................................................................................................................................111 ÊÀÊ ANY, ALL, È EXIST ÏÎÑÒÓÏÀÞÒ Ñ ÎÒÑÓÒÑÒÂÓÞÙÈÌÈ È ÍÅÈÇÂÅÑÒÍÛÌÈ ÄÀÍÍÛÌÈ...................................111 ÊÎÃÄÀ ÏÎÄÇÀÏÐÎÑ ÂÎÇÂÐÀÙÀÅÒÑß ÏÓÑÒÛÌ.................................................................................................................111 ANY È ALL ÂÌÅÑÒÎ EXISTS Ñ ÏÓÑÒÛÌ ÓÊÀÇÀÒÅËÅÌ (NULL)..........................................................................................112 ÈÑÏÎËÜÇÎÂÀÍÈÅ COUNT ÂÌÅÑÒÎ EXISTS........................................................................................................................113 ÐÅÇÞÌÅ......................................................................................................................................................................................114 ÐÀÁÎÒÀ Ñ SQL...........................................................................................................................................................................114 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÏÐÅÄËÎÆÅÍÈß UNION.............................................................................115 ÎÁÚÅÄÈÍÅÍÈÅ ÌÍÎÃÎ×ÈÑËÅÍÍÛÕ ÇÀÏÐÎÑΠ ÎÄÈÍ...............................................................................................116 ÊÎÃÄÀ ÂÛ ÌÎÆÅÒÅ ÄÅËÀÒÜ ÎÁÚÅÄÈÍÅÍÈÅ ÌÅÆÄÓ ÇÀÏÐÎÑÀÌÈ?............................................................................117 UNION È ÓÑÒÐÀÍÅÍÈÅ ÄÓÁËÈÊÀÒÎÂ...................................................................................................................................118 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÑÒÐÎÊ È ÂÛÐÀÆÅÍÈÉ Ñ UNION..........................................................................................................119 ÈÑÏÎËÜÇÎÂÀÍÈÅ UNION Ñ ORDER BY................................................................................................................................120 ÂÍÅØÍÅÅ ÎÁÚÅÄÈÍÅÍÈÅ......................................................................................................................................................121 ÐÅÇÞÌÅ......................................................................................................................................................................................125 ÐÀÁÎÒÀ Ñ SQL...........................................................................................................................................................................125 ÂÂÎÄ, ÓÄÀËÅÍÈÅ È ÈÇÌÅÍÅÍÈÅ ÇÍÀ×ÅÍÈÉ ÏÎËÅÉ...........................................................127 ÊÎÌÀÍÄÛ ÌÎÄÈÔÈÊÀÖÈÈ ßÇÛÊÀ DML...............................................................................................................................128 ÂÂÎÄ ÇÍÀ×ÅÍÈÉ.......................................................................................................................................................................128 ÂÑÒÀÂÊÀ ÏÓÑÒÛÕ ÓÊÀÇÀÒÅËÅÉ (NULL)...............................................................................................................................128 ÈÌÅÍÎÂÀÍÈÅ ÑÒÎËÁÖÀ ÄËß ÂÑÒÀÂÊÈ (INSERT).............................................................................................................129 ÂÑÒÀÂÊÀ ÐÅÇÓËÜÒÀÒΠÇÀÏÐÎÑÀ.......................................................................................................................................129 ÈÇÌÅÍÅÍÈÅ ÇÍÀ×ÅÍÈÉ ÏÎËß..............................................................................................................................................131 ÌÎÄÈÔÈÖÈÐÎÂÀÍÈÅ ÒÎËÜÊÎ ÎÏÐÅÄÅËÅÍÍÛÕ ÑÒÐÎÊ.................................................................................................131 ÊÎÌÀÍÄÀ UPDATE ÄËß ÌÍÎÃÈÕ ÑÒÎËÁÖÎÂ.....................................................................................................................131 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÂÛÐÀÆÅÍÈÉ ÄËß ÌÎÄÈÔÈÊÀÖÈÈ.....................................................................................................131 ÌÎÄÈÔÈÖÈÐÎÂÀÍÈÅ ÏÓÑÒÛÕ(NULL) ÇÍÀ×ÅÍÈÉ.............................................................................................................132 ÐÅÇÞÌÅ......................................................................................................................................................................................132 ÐÀÁÎÒÀ Ñ SQL...........................................................................................................................................................................133 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÏÎÄÇÀÏÐÎÑÎÂ Ñ ÊÎÌÀÍÄÀÌÈ ÌÎÄÈÔÈÊÀÖÈÈ.................................134 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÏÎÄÇÀÏÐÎÑÎÂ Ñ INSERT.....................................................................................................................135 ÍÅ ÂÑÒÀÂËßÉÒÅ ÄÓÁËÈÊÀÒÛ ÑÒÐÎÊ..................................................................................................................................136 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÏÎÄÇÀÏÐÎÑÎÂ, ÑÎÇÄÀÍÛÕ ÂÎ ÂÍÅØÍÅÉ ÒÀÁËÈÖÅ ÇÀÏÐÎÑÀ.................................................136 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÏÎÄÇÀÏÐÎÑÎÂ Ñ DELETE....................................................................................................................137 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÏÎÄÇÀÏÐÎÑÎÂ Ñ UPDATE...................................................................................................................139 ÑÒÎËÊÍÎÂÅÍÈÅ Ñ ÎÃÐÀÍÈ×ÅÍÈßÌÈ ÏÎÄÇÀÏÐÎÑΠÊÎÌÀÍÄÛ DML.......................................................................139 ÐÅÇÞÌÅ......................................................................................................................................................................................140 ÐÀÁÎÒÀ Ñ SQL...........................................................................................................................................................................140 ÑÎÇÄÀÍÈÅ ÒÀÁËÈÖ...................................................................................................................141 ÊÎÌÀÍÄÀ ÑÎÇÄÀÍÈß ÒÀÁËÈÖÛ...........................................................................................................................................142 ÈÍÄÅÊÑÛ....................................................................................................................................................................................143 ÓÍÈÊÀËÜÍÎÑÒÜ ÈÍÄÅÊÑÀ......................................................................................................................................................144 ÓÄÀËÅÍÈÅ ÈÍÄÅÊÑÎÂ.............................................................................................................................................................144 ÈÇÌÅÍÅÍÈÅ ÒÀÁËÈÖÛ ÏÎÑËÅ ÒÎÃÎ, ÊÀÊ ÎÍÀ ÁÛËÀ ÑÎÇÄÀÍÀ...................................................................................145 ÓÄÀËÅÍÈÅ ÒÀÁËÈÖ..................................................................................................................................................................145 ÐÅÇÞÌÅ......................................................................................................................................................................................146 ÐÀÁÎÒÀ Ñ SQL...........................................................................................................................................................................146 ÎÃÐÀÍÈ×ÅÍÈÅ ÇÍÀ×ÅÍÈÉ ÂÀØÈÕ ÄÀÍÍÛÕ........................................................................147 ÎÃÐÀÍÈ×ÅÍÈÅ ÒÀÁËÈÖ..........................................................................................................................................................148 ÎÁÚßÂËÅÍÈÅ ÎÃÐÀÍÈ×ÅÍÈÉ...............................................................................................................................................148 ÈÑÏÎËÜÇÎÂÀÍÈÅ ÎÃÐÀÍÈ×ÅÍÈÉ ÄËß ÈÑÊËÞ×ÅÍÈß ÏÓÑÒÛÕ (NULL) ÓÊÀÇÀÒÅËÅÉ.............................................148 ÓÁÅÄÈÒÅÑÜ, ×ÒÎ ÇÍÀ×ÅÍÈß ÓÍÈÊÀËÜÍÛ.........................................................................................................................149 ÓÍÈÊÀËÜÍÎÑÒÜ ÊÀÊ ÎÃÐÀÍÈ×ÅÍÈÅ ÑÒÎËÁÖÀ.................................................................................................................149 ÓÍÈÊÀËÜÍÎÑÒÜ ÊÀÊ ÎÃÐÀÍÈ×ÅÍÈÅ ÒÀÁËÈÖÛ................................................................................................................150
|
© 2006 - 2024 pmbk.ru. Ãåíåðàöèÿ ñòðàíèöû: 0
Ïðè êîïèðîâàíèè ìàòåðèàëîâ ïðèâåòñòâóþòñÿ ññûëêè. |