① 鍏寵仈鍏崇郴琛ㄤ竴鎬庝箞濉
闂棰樹竴錛氫紒涓氬勾搴﹀叧鑱斾笟鍔″線鏉ユ姤鍛婅〃涓鐨勮〃涓銆婂叧鑱斿叧緋昏〃銆嬪叧鑱旀柟鍚嶇О搴旇ュ備綍濉錛 浼佷笟鍩烘湰閮芥病鏈夊叧鑱斿崟浣嶇殑錛屽叧鑱旀槸鎸囦互浼佷笟鐨勫悕涔夊湪澶栧仛鐨勬姇璧
闂棰樹簩錛氬叧鑱斿叧緋昏〃鎬庝箞濉 鎮ㄥソ錛
鎸夌収浣犱笂榪板唴瀹癸紝鍦ㄦ硶寰嬪艦寮忎笂涓嶆槸鍏寵仈浼佷笟鐨勮寖鐣淬備笂榪癆\B\C,鍚堣祫絳瑰緩鐨勪紒涓氾紝浠栦滑鏄鍏鍙哥殑鑲′笢銆
鎵璋撳叧鑱斾紒涓氾紝鏄鎸囦笌鍏朵粬浼佷笟涔嬮棿瀛樺湪鐩存帴鎴栭棿鎺ユ帶鍒跺叧緋繪垨閲嶅ぇ褰卞搷鍏崇郴鐨勪紒涓氥傜浉浜掍箣闂村叿鏈夎仈緋葷殑鍚勪紒涓氫簰涓哄叧鑱斾紒涓氥傚叧鑱斾紒涓氬湪娉曞緥涓婂彲琛ㄧ幇涓虹敱鎺у埗鍏鍙稿拰浠庡睘鍏鍙告瀯鎴愩傝屾帶鍒跺叕鍙鎬笌浠庡睘鍏鍙哥殑褰㈡垚涓昏佸湪騫插叧鑱斿叕鍙鎬箣闂寸殑緇熶竴綆$悊鍏崇郴鐨勫瓨鍦ㄣ傝繖縐嶅叧緋誨線寰綾嶅姪浜庢帶鍒跺叕鍙稿逛粠灞炲叕鍙稿疄璐ㄤ笂鐨勬帶鍒惰屽艦鎴愩
闂棰樹笁錛氬叧鑱斿叧緋昏〃(琛ㄤ竴)鐨勪唬鐮佽侀夊摢涓 [緙栬緫鏈孌礭鍏寵仈鍏崇郴琛ㄦ傝堪 鍏寵仈鍏崇郴蹇呯劧鏈変竴涓鍙傜収琛錛屼緥濡傦細 鏈変竴涓鍛樺伐妗f堢$悊緋葷粺欏圭洰錛岃繖涓欏圭洰瑕佸寘鎷涓嬮潰鐨勪竴浜涙暟鎹琛錛氬熀鏈淇℃伅琛ㄣ佸憳宸ユ。妗堣〃銆侀儴闂ㄨ〃銆侀」鐩緇勮〃銆侀摱琛屽崱琛錛堢敤鏉ヨ板綍鍛樺伐鐨勯摱琛屽崱璧勬枡錛夈 榪欎簺鏁版嵁琛ㄤ箣闂村瓨鍦ㄤ竴瀹氱殑鍏寵仈鍏崇郴錛屾垜浠浠ュ憳宸ュ熀鏈淇℃伅琛ㄤ負鍙傜収鏉ュ垎鏋愬拰鍏朵粬琛ㄤ箣闂寸殑鍏寵仈錛 姣忎釜鍛樺伐蹇呯劧鏈夊瑰簲鐨勫憳宸ユ。妗堣祫鏂欙紝鎵浠ュ睘浜嶩AS_ONE鍏寵仈錛 姣忎釜鍛樺伐蹇呴』灞炰簬鏌愪釜閮ㄩ棬錛屾墍浠ュ睘浜嶣ELONGS_TO鍏寵仈錛 姣忎釜鍛樺伐鍙浠ユ湁澶氫釜閾惰屽崱錛屼絾鏄姣忓紶閾惰屽崱鍙鍙鑳藉睘浜庝竴涓鍛樺伐錛屽洜姝ゅ睘浜嶩AS_MANY鍏寵仈錛 姣忎釜鍛樺伐鍙浠ュ悓鏃跺湪澶氫釜欏圭洰緇勶紝姣忎釜欏圭洰緇勫悓鏃舵湁澶氫釜鍛樺伐錛屽洜姝ゅ睘浜嶮ANY_TO_MANY鍏寵仈錛 鍒嗘瀽娓呮氭暟鎹琛ㄤ箣鍓嶇殑鍏寵仈鍏崇郴鍚庯紝鎴戜滑鎵嶅彲浠ヨ繘琛屽叧鑱斿畾涔夊拰鍏寵仈鎿嶄綔銆 [緙栬緫鏈孌礭鏁版嵁搴撲笂鐨勫叧鑱斿叧緋 涓や釜鏁版嵁搴撳強鍏訛紙鏁版嵁錛夎〃涔嬮棿鐨勬暟鎹鐨勭浉浜掍緷璧栧拰褰卞搷鍏崇郴銆 姣斿傜幇鏈夋煇瀛︽牎涓変釜鏁版嵁琛錛氬︾敓錛堝﹀彿錛屽撳悕錛夛紝璇劇▼錛堣劇▼鍚嶏紝璇劇▼緙栧彿錛夛紝閫夎撅紙瀛﹀彿錛岃劇▼鍙鳳紝鎴愮嘩錛夈傞夎捐〃涓鐨勨滃﹀彿鈥濓紝鈥滆劇▼鍙封濆繀欏繪槸鍙﹀栦袱涓琛ㄤ腑瀛樺湪鐨勬暟鎹錛屾墠鏈夋剰涔夛紱鑰屼笖涓鏃﹀彟澶栦袱琛ㄤ腑鐨勬煇涓瀛︾敓鎴栬劇▼琚鍒犻櫎錛岄夎捐〃涓鐨勭浉搴斿﹀彿鎴栬劇▼鍙峰繀欏昏嚜鍔ㄥ垹闄ゃ傝繖灝辨槸涓縐嶅叧鑱斿叧緋匯傚畠瀹為檯涓婃槸淇濊瘉鏁版嵁瀹屾暣鎬х殑涓縐嶅仛娉曘 [緙栬緫鏈孌礭紼庡姟涓婂叧鑱斿叧緋昏〃濉鍐欒存槑 鍏寵仈鍏崇郴琛ㄩ渶瑕佸~鍐欑殑淇℃伅鍖呮嫭錛氬叧鑱旀柟鍚嶇О錛岀撼紼庝漢璇嗗埆鍙鳳紝鍥藉訛紙鍦板尯錛夛紝鍦板潃錛屽拰浼佷笟鐨勫叧緋伙紝娉曞畾浠h〃浜猴紝鍏寵仈鍏崇郴綾誨瀷銆傚叿浣撳~鎶ヨ佹眰濡備笅錛 涓銆佲滅撼紼庝漢璇嗗埆鍙封濓細濉鎶ュ叧鑱旀柟鎵鍦ㄥ浗瀹舵垨鍦板尯鐢ㄤ簬綰崇◣鐢蟲姤鐨勭撼紼庝漢鍙風爜銆 浜屻佲滃浗瀹訛紙鍦板尯錛夆濓細濉鎶ュ叧鑱旀柟鎵鍦ㄥ浗瀹舵垨鍦板尯鐨勫悕縐般 涓夈佲滃湴鍧鈥濓細濉鎶ュ叧鑱斾紒涓氭敞鍐屽湴鍧鍜屽疄闄呯粡钀ョ$悊鏈烘瀯鎵鍦ㄥ湴鍦板潃鎴栧叧鑱斾釜浜轟綇鎵銆 鍥涖佲滃叧鑱斿叧緋葷被鍨嬧濓細搴旀寜浠ヤ笅鍏寵仈鍏崇郴鏍囧噯濉鎶ヤ唬鐮丄銆丅銆丆絳夛紝鏈夊氫釜鍏寵仈鍏崇郴綾誨瀷鐨勶紝搴斿~鎶ュ氫釜浠g爜錛 A錛庝竴鏂圭洿鎺ユ垨闂存帴鎸佹湁鍙︿竴鏂圭殑鑲′喚鎬誨拰杈懼埌25%鎴栦互涓婏紱鎴栬呭弻鏂圭洿鎺ユ垨闂存帴鍚屼負絎涓夋柟鎵鎸佹湁鑲′喚杈懼埌25%鎴栦互涓娿傝嫢涓鏂歸氳繃涓闂存柟瀵瑰彟涓鏂歸棿鎺ユ寔鏈夎偂浠斤紝鍙瑕佷竴鏂瑰逛腑闂存柟鎸佽偂姣斾緥杈懼埌25%鎴栦互涓婏紝鍒欎竴鏂瑰瑰彟涓鏂圭殑鎸佽偂姣斾緥鎸夌収涓闂存柟瀵瑰彟涓鏂圭殑鎸佽偂姣斾緥璁$畻錛 B錛庝竴鏂逛笌鍙︿竴鏂癸紙鐙絝嬮噾鋙嶆満鏋勯櫎澶栵級涔嬮棿鍊熻捶璧勯噾鍗犱竴鏂瑰疄鏀惰祫鏈50%鎴栦互涓婏紝鎴栬呬竴鏂瑰熻捶璧勯噾鎬婚濈殑10%鎴栦互涓婃槸鐢卞彟涓鏂癸紙鐙絝嬮噾鋙嶆満鏋勯櫎澶栵級鎷呬繚錛 C錛庝竴鏂瑰崐鏁頒互涓婄殑楂樼駭綆$悊浜哄憳錛堝寘鎷钁d簨浼氭垚鍛樺拰緇忕悊錛夋垨鑷沖皯涓鍚嶅彲浠ユ帶鍒惰懀浜嬩細鐨勮懀浜嬩細楂樼駭鎴愬憳鏄鐢卞彟涓鏂瑰旀淳錛屾垨鑰呭弻鏂瑰崐鏁頒互涓婄殑楂樼駭綆$悊浜哄憳錛堝寘鎷钁d簨浼氭垚鍛樺拰緇忕悊錛夋垨鑷沖皯涓鍚嶅彲浠ユ帶鍒惰懀浜嬩細鐨勮懀浜嬩細楂樼駭鎴愬憳鍚屼負絎涓夋柟濮旀淳錛 D錛庝竴鏂瑰崐鏁頒互涓婄殑楂樼駭綆$悊浜哄憳錛堝寘鎷钁d簨浼氭垚鍛樺拰緇忕悊錛夊悓鏃舵媴浠誨彟涓鏂圭殑楂樼駭綆$悊浜哄憳錛堝寘鎷钁d簨浼氭垚鍛樺拰緇忕悊錛夛紝鎴栬呬竴鏂硅嚦灝戜竴鍚嶅彲浠ユ帶鍒惰懀浜嬩細鐨勮懀浜嬩細楂樼駭鎴愬憳鍚屾椂鎷呬換鍙︿竴鏂圭殑钁d簨浼氶珮綰ф垚鍛橈紱 E錛庝竴鏂圭殑鐢熶駭緇忚惀媧誨姩蹇呴』鐢卞彟涓鏂規彁渚涚殑宸ヤ笟浜ф潈銆佷笓鏈夋妧鏈絳夌壒璁告潈鎵嶈兘姝e父榪涜岋紱 F錛庝竴鏂圭殑璐涔版垨閿鍞媧誨姩涓昏佺敱鍙︿竴鏂規帶鍒訛紱 G錛庝竴鏂規帴鍙楁垨鎻愪緵鍔沖姟涓昏佺敱鍙︿竴鏂規帶鍒訛紱 H錛庝竴鏂瑰瑰彟涓鏂圭殑鐢熶駭緇忚惀銆佷氦鏄撳叿鏈夊疄璐ㄦ帶鍒躲佹垨鑰呭弻鏂瑰湪鍒╃泭涓婂叿鏈夌浉鍏寵仈鐨勫叾瀹冨叧緋伙紝鍖呮嫭鉶芥湭杈懼埌A欏規寔鑲℃瘮渚嬶紝浣嗕竴鏂逛笌鍙︿竴鏂圭殑涓昏佹寔鑲℃柟浜鍙楀熀鏈鐩稿悓鐨勭粡嫻庡埄鐩婏紝浠ュ強瀹舵棌銆佷翰灞炲叧緋葷瓑銆
闂棰樺洓錛氬叧鑱斿叧緋昏〃鎬庢牱濉鍐欙紵 闂錛 絳旓細娼嶅潑甯傚浗紼庡矓錛堟綅鍥界◣浼佷究鍑斤薊2012錛4鍙風彁鏂囦歡涓錛屼笓闂ㄥ瑰叧鑱旂敵鎶ラ棶棰樻彁鍑轟簡鍏蜂綋瑕佹眰錛屽唴瀹瑰備笅錛氣滀紒涓氬勾搴﹀叧鑱斾笟鍔″線鏉ユ姤鍛婅〃錛屽叾灝侀潰銆佸叧鑱斿叧緋昏〃錛堣〃涓錛夊繀欏誨~鍐欑浉鍏沖唴瀹癸紝涓嶈兘涓虹┖錛涘叧鑱斾氦鏄撴眹鎬昏〃(琛ㄤ簩)銆佽喘閿琛錛堣〃涓夛級銆佸姵鍔¤〃錛堣〃鍥涳級銆佹棤褰㈣祫浜ц〃錛堣〃浜旓級銆佸滻瀹氳祫浜ц〃錛堣〃鍏錛夈佽瀺閫氳祫閲戣〃錛堣〃涓冿級錛屽傛灉鍚屾椂瀛樺湪鍏寵仈浜ゆ槗銆侀潪鍏寵仈浜ゆ槗鎯呭艦鎴栦粎瀛樺湪鍏朵腑涓縐嶆儏褰錛屽潎搴斿~鍐欑浉搴旀儏褰㈢殑鏁版嵁鍙婄浉鍏沖悎璁¢」錛堝挨鍏舵槸浠呭瓨闈炲叧鑱斾氦鏄撴儏褰錛屼害搴斿~鍐欓潪鍏寵仈浜ゆ槗鏁版嵁鍙婄浉鍏沖悎璁¢」錛夛紱瀵瑰栨姇璧勬儏鍐佃〃錛堣〃鍏錛夈佸瑰栨敮浠樻鵑」鎯呭喌琛錛堣〃涔濓級鏍規嵁浼佷笟瀹為檯鎯呭喌濉鍐欍傗
闂棰樹簲錛氬勾搴︾敵鎶ュ叧鑱斿叧緋誨線鏉ヨ〃涓鐨勬渶鍚庝竴涓鍏寵仈鍏崇郴琛ㄥ備綍濉鍐欙紝璧峰嬫棩鏈熶笌 鐪嬬鍏鏉$殑璇存槑
闂棰樺叚錛氫紒涓氬叧鑱斿叧緋昏〃 浼佷笟涓昏佸㈡埛鍜屼緵搴斿晢涓嶅睘浜庡叧鑱斾紒涓氥
鎵璋撳叧鑱斾紒涓氾紝鏄鎸囦笌鍏朵粬浼佷笟涔嬮棿瀛樺湪鐩存帴鎴栭棿鎺ユ帶鍒跺叧緋繪垨閲嶅ぇ褰卞搷鍏崇郴鐨勪紒涓氥傜浉浜掍箣闂村叿鏈夎仈緋葷殑鍚勪紒涓氫簰涓哄叧鑱斾紒涓氥
浼佷笟鍏寵仈鍏崇郴錛
1銆佺浉浜掗棿鐩存帴鎴栬呴棿鎺ユ寔鏈夊叾涓涓鏂圭殑鑲′喚鎬誨拰杈懼埌25%鎴栦互涓婄殑錛
2銆佺洿鎺ユ垨闂存帴鍚屼負絎涓夎呮墍鎷ユ湁鎴栨帶鍒惰偂浠借揪鍒25%鎴栦互涓婄殑錛
3銆佷紒涓氫笌鍙︿竴浼佷笟(鐙絝嬮噾鋙嶆満鏋勯櫎澶)涔嬮棿鍊熻捶璧勯噾鍗犱紒涓氬疄鏀惰祫鏈50%鎴栦互涓婏紝鎴栦紒涓氬熻捶璧勯噾鎬婚濈殑10%鏄鐢卞彟涓浼佷笟鐙絝嬮噾鋙嶆満鏋勯櫎澶栨媴淇濈殑錛
4銆佷紒涓氱殑钁d簨鎴栫粡鐞嗙瓑楂樼駭綆$悊浜哄憳涓鍗婁互涓婃垨鏈変竴鍚嶅父鍔¤懀浜嬫槸鐢卞彟涓浼佷笟鎵濮旀淳鐨勶紱 銆銆5銆佷紒涓氱殑鐢熶駭緇忚惀媧誨姩蹇呴』鐢卞彟涓浼佷笟鎻愪緵鐨勭壒璁告潈鍒╋紙鍖呮嫭宸ヤ笟浜ф潈銆佷笓鏈夋妧鏈絳夛級鎵嶈兘姝e父榪涜岀殑錛
6銆佷紒涓氱敓浜х粡钀ヨ喘榪涘師鏉愭枡銆侀浂閰嶄歡絳夛紙鍖呮嫭浠鋒牸鍙婁氦鏄撴潯浠剁瓑錛夋槸鐢卞彟涓浼佷笟鎵鎺у埗鎴栦緵搴旂殑錛
7銆佷紒涓氱敓浜х殑浜у搧鎴栧晢鍝佺殑閿鍞錛堝寘鎷浠鋒牸鍙婁氦鏄撴潯浠剁瓑錛夋槸鐢卞彟涓浼佷笟鎵鎺у埗錛
8銆佸逛紒涓氱敓浜х粡钀ャ佷氦鏄撳叿鏈夊疄闄呮帶鍒剁殑鍏朵粬鍒╃泭涓婄浉鍏寵仈鐨勫叧緋伙紝鍖呮嫭瀹跺涵銆佷翰灞炲叧緋匯
闂棰樹竷錛氫紒涓氭墍寰楃◣騫村害鐢蟲姤緋葷粺 鍏寵仈鍏崇郴琛ㄦ庝箞濉 娌℃湁鍏寵仈鍗曚綅 濡傛灉娌℃湁鍏寵仈鏂癸紝灝卞~鍐欐硶浜猴紝涔嬪悗琛ㄤ腑鐨勪氦鏄撲俊鎮灝遍兘鏄絀虹殑鎴栬呰ˉ闆跺嵆鍙
闂棰樺叓錛歄racle鎬庢牱鍒涘緩鍏崇郴琛ㄤ笌鍏朵粬鐨勪竴涓琛ㄥ叧鑱 渚嬪備笅闈㈣繖涓や釜琛ㄤ腑鍒嗗埆瀛樼殑鏃跺憳宸ョ殑鍩烘湰淇℃伅鍜屽叕鍙哥殑閮ㄩ棬淇℃伅銆傛垜浠涓
create table dept
(deptno number(10) not null,
deptn欏秏e varchar2(30) not null,
constraint pk_dept primary key(deptno));
鍜
create table emp
( empno number(10) not null,
fname varchar2(20) ,
lname varchar2(20) ,
dept number(10) ,
constraint pk_emp primary key(empno));
鐒跺悗鎴戜滑鐜板湪澧炲姞澶栭敭璇曚竴涓媜n delete cascade
alter table emp
add constraint fk_emp_dept foreign key(dept) references dept(deptno) on delete cascade;
鍏堝炲姞澶栭敭銆傜劧鍚庢彃鍏ユ暟鎹銆
insert into dept values(1,鈥欓攢鍞閮ㄢ);
insert into dept values(2,鈥欒儲鍔¢儴鈥);
insert into emp values (2,鈥橫ary鈥,'Song鈥,1);
insert into emp values (3,鈥橪inda鈥,'Liu鈥,2);
insert into emp values (4,鈥橪inlin鈥,'Zhang鈥,1);
鐒跺悗鐜板湪鎴戣佸垹闄ら攢鍞閮錛屼細鏈変粈涔堝悗鏋滃憿錛
delete from dept where deptno = 1;
鎴戜滑鍙戠幇闄や簡dept涓鐨勪竴鏉℃暟鎹琚鍒犻櫎浜嗭紝emp涓涓ゆ潯鏁版嵁涔熻鍒犻櫎浜嗭紝鍏朵腑emp涓鐨勪袱鏉℃暟鎹鏄鍙傜収浜嗛攢鍞閮ㄧ殑榪欐潯鏁版嵁鐨勶紝榪欏氨寰堝規槗鐞嗚Вon delete cascade浜嗐
闂棰樹節錛氫紒涓氭墍寰楃◣鍏寵仈鍏崇郴琛ㄦ庝箞濉 涓鍗庝漢姘戝叡鍜屽浗浼佷笟騫村害鍏寵仈涓氬姟寰鏉ユ姤鍛婅〃濉鎶ヨ存槑 涓銆佹牴鎹銆婁腑鍗庝漢姘戝叡鍜屽浗浼佷笟鎵寰楃◣娉曘嬬鍥涘嶮涓夋潯鐨勮勫畾錛屽埗瀹氭湰鎶ュ憡琛ㄣ 浜屻佹湰鎶ュ憡琛ㄥ寘鎷錛氣滃叧鑱斿叧緋昏〃錛堣〃涓錛夆濄佲滃叧鑱斾氦鏄撴眹鎬昏〃錛堣〃浜岋級鈥濄佲滆喘閿琛錛堣〃涓夛級鈥濄佲滃姵鍔¤〃錛堣〃鍥涳級鈥濄佲滄棤褰㈣祫浜ц〃錛堣〃浜旓級鈥濄佲滃滻瀹氳祫浜ц〃錛堣〃鍏錛夆濄佲滆瀺閫氳祫閲戣〃錛堣〃涓冿級鈥濄佲滃瑰栨姇璧勬儏鍐佃〃錛堣〃鍏錛夆濄佲滃瑰栨敮浠樻鵑」鎯呭喌琛錛堣〃涔濓級鈥濆叡涔濆紶鎶ュ憡琛ㄣ 涓夈佹湰鎶ュ憡琛ㄩ傜敤浜庡疄琛屾煡璐﹀緛鏀剁殑灞呮皯浼佷笟鍜屽湪涓鍥藉冨唴璁劇珛鏈烘瀯銆佸満鎵騫舵嵁瀹炵敵鎶ョ即綰充紒涓氭墍寰楃◣鐨勯潪灞呮皯浼佷笟濉鎶ャ 鍥涖佷紒涓氬悜紼庡姟鏈哄叧鎶ラ佸勾搴︿紒涓氭墍寰楃◣綰崇◣鐢蟲姤琛ㄦ椂錛屽簲闄勯佹湰鎶ュ憡琛ㄣ 浜斻佲滅撼紼庝漢鍚嶇О鈥濓細濉鎶ョ◣鍔$櫥璁拌瘉鎵杞界撼紼庝漢鐨勫叏縐般 鍏銆佲滅撼紼庝漢璇嗗埆鍙封濓細濉鎶ョ◣鍔℃満鍏崇粺涓鏍稿彂鐨勭◣鍔$櫥璁拌瘉鍙風爜銆 鍏寵仈鍏崇郴琛錛堣〃涓錛夛細 涓銆佲滅撼紼庝漢璇嗗埆鍙封濓細濉鎶ュ叧鑱旀柟鎵鍦ㄥ浗瀹舵垨鍦板尯鐢ㄤ簬綰崇◣鐢蟲姤鐨勭撼紼庝漢鍙風爜銆 浜屻佲滃浗瀹訛紙鍦板尯錛夆濓細濉鎶ュ叧鑱旀柟鎵鍦ㄥ浗瀹舵垨鍦板尯鐨勫悕縐般 涓夈佲滃湴鍧鈥濓細濉鎶ュ叧鑱斾紒涓氭敞鍐屽湴鍧鍜屽疄闄呯粡钀ョ$悊鏈烘瀯鎵鍦ㄥ湴鍦板潃鎴栧叧鑱斾釜浜轟綇鎵銆 鍥涖佲滃叧鑱斿叧緋葷被鍨嬧濓細
闂棰樺嶮錛歋QL琛ㄥ叧緋 涓涓鍏崇郴鍥懼唴涓嶇洿鎺ュ叧鑱旂殑涓や釜琛錛屾庝箞鏌ヨ浠栦滑鐨勬暟鎹錛 sql鐨刯oin鏄涓嶄緷璧栦簬澶栭敭鐨勩