How to rename an oracle table and copy table information

Source: Internet
Author: User

Oracle renaming tables and operations on copying table information Java code oracle modifying table name alter table_name rename to new_table_name; www.2cto.com oracle Inserting Data Based on queries Insert is a common statement in T-SQL, insert INTO table (field1, field2 ,...) values (value1, value2 ,...) this form is essential for application development. However, during the development and testing processes, we often encounter situations where table replication is required, such as copying some of the data fields of Table 1 to table 2 or copying the entire table 1 to table 2, in this case, we need to use the select into and insert into select table copy statements. 1. insert into select statement format: Insert into Table2 (field1, field2 ,...) select value1, value2 ,... from Table1 requires that the target table Table2 must exist. Because the target table Table2 already exists, We can insert constants in addition to the fields in the source table table1. Example: www.2cto.com insert into select statement to copy table data SQL code 1. 1. create test table 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. create test data 25. insert into Table1 values ('zhao ', 'asds', '90') 26. insert into Table1 values ('money', 'asds ', '123') 27. insert into Table1 values ('sun', 'asds ', '80') 28. insert into Table1 values ('lil', 'asds ', null) 29. GO 30. select * from Table2 31. 32. -- 3. insert into select statement to copy table data 33. insert into Table2 (a, c, d) select a, c, 5 from Table1 34. GO 35. 36. -- 4. display the updated result 37. select * from Table2 38. GO 39. -- 5. delete Test Table 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. create test data Insert into Table1 values ('zhao ', 'asds', '90') Insert Table1 values ('money', 'asds ', '000000') Insert into Table1 values ('sun', 'asds', '80 ') insert into Table1 values ('lil', 'asds ', null) GO select * from Table2 -- 3. insert into select statement to copy table data Insert into Table2 (a, c, d) select a, c, 5 from Table1 GO -- 4. show the updated result select * from Table2 GO -- 5. delete test TABLE drop TABLE Table1 drop TABLE Table2 2. select into from statement Syntax: SELECT vale1, value2 into Table2 from Table1 requires that the target table Table2 does not exist because Table 2 is automatically created during insertion, and the specified field data in table 1 is copied to table 2. Example: select into from: Create a table and copy the table data. SQL code 1. 1. create test table 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. create test data 15. insert into Table1 values ('zhao ', 'asds', '90') 16. insert into Table1 values ('money', 'asds ', '123') 17. insert into Table1 values ('sun', 'asds ', '80') 18. insert into Table1 values ('lil', 'asds ', null) 19. GO 20. 21. -- 3. select into from statement to Create Table 2 and copy data 22. select a, c INTO Table2 from Table1 23. GO 24. 25. -- 4. the updated result 26 is displayed. select * from Table2 27. GO 28. -- 5. delete Test Table 29. drop TABLE Table1 30. drop TABLE Table2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.