SQL鐨勬洿鏂板拰鍒犻櫎
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL鐨勬洿鏂板拰鍒犻櫎相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%88%a0%e9%99%a4' title='鍒犻櫎'>鍒犻櫎 value other rom tab 绀轰緥 浣跨敤 HERE
銆€銆€1銆丼QL鏇存柊鏁版嵁
- 鍏抽敭瀛楋細UPDATE
- 鏂瑰紡锛氭湁涓ょ鏂瑰紡杩涜鏇存柊
- 鏇存柊琛ㄤ腑鎸囧畾鐨勮
- 鏇存柊琛ㄤ腑鎵€鏈夌殑琛?/li>
- 绀轰緥锛?/li>
UPDATE table_name SET some_column = 鈥?/span>some_value鈥?/span>锛宱ther_column = 鈥?/span>other_value鈥?/span> WHERE unique_column = 鈥?/span>unique_value鈥?/span>
銆€銆€涓婅堪绀轰緥绀烘洿鏂版寚瀹氳锛岃嫢鎯虫洿鏂版墍鏈夌殑琛岋紝閭d箞鍘绘帀WHERE瀛愬彞鍗冲彲銆備负浜嗘暟鎹殑瀹夊叏鎬э紝鏈€濂芥槸娣诲姞WHERE瀛愬彞銆?/p>
-- UPDATE涓嶴ELECT缁撳悎浣跨敤 UPDATE table_name SET (column1, column2, column3) = (SELECT col1, col2 FROM other_table_name WHERE some_col = 鈥?/span>some_value鈥?/span>) WHERE some_column = 鈥?/span>other_value鈥?/span>; -- UPDATE涓嶧ROM缁撳悎浣跨敤(瑕佺湅DBMS鏄惁鏀寔) UPDATE table_name AS t1 SET col1 = t2.column1, col2 = t2.column2 FROM other_table_name AS t2 WHERE t1.some_col = t2.some_col; -- UPDATE涓嶫OIN缁撳悎浣跨敤 UPDATE t1 INNER JOIN t2 ON t1.col1 = t2.col1 SET t1.some_col = 鈥?/span>some_col_value鈥?/span>, t2.other_col = 鈥?/span>other_col_value鈥?/span> WHERE t1.condition_col = 鈥?/span>condition_value鈥?/span>; UPDATE t1 LEFT JOIN t2 ON t1.col1 = t2.col1 SET t1.some_col = 鈥?/span>some_col_value鈥?/span>, t2.other_col = 鈥?/span>other_col_value鈥?/span> WHERE t1.condition_col = 鈥?/span>condition_value鈥?/span>;
銆€銆€2銆丼QL鍒犻櫎鏁版嵁
- 鍏抽敭瀛楋細DELETE FROM锛屾煇浜汼QL瀹炵幇涓紝鍙互鐪佺暐FROM鍏抽敭瀛楋紝涓嶈繃寤鸿杩樻槸鎻愪緵FROM鍏抽敭瀛?/li>
- 鏂瑰紡锛氭湁涓ょ鍒犻櫎鏂瑰紡
- 鍒犻櫎鎸囧畾鐨勮
- 鍒犻櫎鎵€鏈夌殑琛?/li>
- 绀轰緥锛?/li>
DELETE FROM table_name WHERE some_col = 鈥?/span>some_value鈥?/span>;
銆€銆€DELETE璇彞涓嶉渶瑕佹寚鍑哄垪鍚嶆垨鑰呴€氶厤绗︼紝鑻ユ病鏈夋寚瀹歐HERE鍏抽敭瀛楋紝閭d箞鏄垹闄ゆ墍鏈夌殑琛屻€傚叾瀹烇紝鑻ユ兂鍒犻櫎琛ㄤ腑鎵€鏈夎锛屼笉瑕佷娇鐢―ELETE锛屽彲浠ヤ娇鐢═RUNCATE TABLE璇彞锛屽畠瀹屾垚鐩稿悓鐨勫伐浣滐紝骞朵笖閫熷害瑕佸揩锛屽洜涓哄畠涓嶈褰曟暟鎹殑鍙樺姩銆?/p>
銆€銆€3銆丼QL鏇存柊鍜屽垹闄ゆ搷浣滃師鍒?/p>
- 闄ら潪鏇存柊鎴栬€呭垹闄ゆ墍鏈夎锛屽惁鍒欑殑璇濆繀椤讳娇鐢╓HERE瀛愬彞銆?/li>
- 淇濊瘉姣忎釜琛ㄩ兘鏈変富閿€?/li>
- 鍦ㄦ洿鏂版垨鑰呭垹闄や箣鍓嶏紝鏈€濂芥槸鍏圫ELECT妫€绱㈡寚瀹氱殑鏁版嵁锛屼繚璇乄HERE瀛愬彞杩囨护鐨勬暟鎹纭€?/li>
- 浣跨敤寮哄埗瀹炴柦寮曠敤瀹屾暣鎬х殑鏁版嵁搴擄紝浠ラ槻璇垹涓庡叾浠栬〃鐩稿叧鑱旂殑鏁版嵁銆?/li>
- DMBS搴旇绾︽潫闃叉涓嶅甫WHERE瀛愬彞鐨勬洿鏂版垨鍒犻櫎鎿嶄綔銆?/li>
以上是关于SQL鐨勬洿鏂板拰鍒犻櫎的主要内容,如果未能解决你的问题,请参考以下文章