日期:2014-05-16 浏览次数:20451 次
oracle淇敼琛ㄥ悕 alter tabletable_name rename to new_table_name; oracle鏍规嵁鏌ヨ鎻掑叆鏁版嵁 Insert鏄疶-sql涓父鐢ㄨ鍙ワ紝Insert INTO table(field1,field2,...) values(value1,value2,...)杩欑褰㈠紡鐨勫湪搴旂敤绋嬪簭寮€鍙戜腑蹇呬笉鍙皯銆備絾鎴戜滑鍦ㄥ紑鍙戙€佹祴璇曡繃绋嬩腑锛岀粡甯镐細閬囧埌闇€瑕佽〃澶嶅埗鐨勬儏鍐碉紝濡傚皢涓€涓猼able1鐨勬暟鎹殑閮ㄥ垎瀛楁澶嶅埗鍒皌able2涓紝鎴栬€呭皢鏁翠釜table1澶嶅埗鍒皌able2涓紝杩欐椂鍊欐垜浠氨瑕佷娇鐢⊿ELECT INTO 鍜?INSERT INTO SELECT 琛ㄥ鍒惰鍙ヤ簡銆? 1.INSERT INTO SELECT璇彞 璇彞褰㈠紡涓猴細Insert into Table2(field1,field2,...) select value1,value2,... from Table1 瑕佹眰鐩爣琛═able2蹇呴』瀛樺湪锛岀敱浜庣洰鏍囪〃Table2宸茬粡瀛樺湪锛屾墍浠ユ垜浠櫎浜嗘彃鍏ユ簮琛═able1鐨勫瓧娈靛锛岃繕鍙互鎻掑叆甯搁噺銆傜ず渚嬪涓嬶細 INSERT INTO SELECT璇彞澶嶅埗琛ㄦ暟鎹? Sql浠g爜 1.1.鍒涘缓娴嬭瘯琛? 2. create TABLE Table1 3. ( 4. a varchar(10), 5. b varchar(10), 6. c varchar(10), 7. CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED 8. ( 9. a ASC 10. ) 11. ) ON [PRIMARY] 12. 13. create TABLE Table2 14. ( 15. a varchar(10), 16. c varchar(10), 17. d int, 18. CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED 19. ( 20. a ASC 21. ) 22. ) ON [PRIMARY] 23. GO 24. --2.鍒涘缓娴嬭瘯鏁版嵁 25. Insert into Table1 values('璧?,'asds','90') 26. Insert into Table1 values('閽?,'asds','100') 27. Insert into Table1 values('瀛?,'asds','80') 28. Insert into Table1 values('鏉?,'asds',null) 29. GO 30. select * from Table2 31. 32. --3.INSERT INTO SELECT璇彞澶嶅埗琛ㄦ暟鎹? 33. Insert into Table2(a, c, d) select a,c,5 from Table1 34. GO 35. 36. --4.鏄剧ず鏇存柊鍚庣殑缁撴灉 37. select * from Table2 38. GO 39. --5.鍒犻櫎娴嬭瘯琛? 40. drop TABLE Table1 41. drop TABLE Table2 1.鍒涘缓娴嬭瘯琛? create TABLE Table1 ( a varchar(10), b varchar(10), c varchar(10), CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED ( a ASC ) ) ON [PRIMARY] create TABLE Table2 ( a varchar(10), c varchar(10), d int, CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED ( a ASC ) ) ON [PRIMARY] GO --2.鍒涘缓娴嬭瘯鏁版嵁 Insert into Table1 values('璧?,'asds','90') Insert into Table1 values('閽?,'asds','100') Insert into Table1 values('瀛?,'asds','80') Insert into Table1 values('鏉?,'asds',null) GO select * from Table2 --3.INSERT INTO SELECT璇彞澶嶅埗琛ㄦ暟鎹? Insert into Table2(a, c, d) select a,c,5 from Table1 GO --4.鏄剧ず鏇存柊鍚庣殑缁撴灉 select * from Table2 GO --5.鍒犻櫎娴嬭瘯琛? drop TABLE Table1 drop TABLE Table2 2.SELECT INTO FROM璇彞 璇彞褰㈠紡涓猴細SELECT vale1, value2 into Table2 from Table1 瑕佹眰鐩爣琛═able2涓嶅瓨鍦紝鍥犱负鍦ㄦ彃鍏ユ椂浼氳嚜鍔ㄥ垱寤鸿〃Table2锛屽苟灏員able1涓寚瀹氬瓧娈垫暟鎹鍒跺埌Table2涓€傜ず渚嬪涓嬶細 SELECT INTO FROM鍒涘缓琛ㄥ苟澶嶅埗琛ㄦ暟鎹? Sql浠g爜 1.1.鍒涘缓娴嬭瘯琛? 2. create TABLE Table1 3. ( 4. a varchar(10), 5. b varchar(10), 6. c varchar(10), 7. CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED 8. ( 9. a ASC 10. ) 11. ) ON [PRIMARY] 12. GO 13. 14. --2.鍒涘缓娴嬭瘯鏁版嵁 15. Insert into Table1 values('璧?,'asds','90') 16. Insert into Table1 values('閽?,'asds','100') 17. Insert into Table1 values('瀛?,'asds','80') 18. Insert into Table1 values('鏉?,'asds',null) 19. GO 20. 21. --3.SELECT INTO FROM璇彞鍒涘缓琛═able2骞跺鍒舵暟鎹? 22. select a,c INTO Table2 from Table1 23. GO 24. 25. --4.鏄剧ず鏇存柊鍚庣殑缁撴灉 26. select * from Table2 27. GO 28. --5.鍒犻櫎娴嬭瘯琛? 29. drop TABLE Table1 30. drop TABLE Table2