Add a primary key column to a table

Source: Internet
Author: User

SQL> drop table T1 purge;

The table has been deleted.

SQL> Create Table T1 as select * from EMP;

The table has been created.

SQL> ALTER TABLE T1 Add a varchar2 (20 );

The table has been changed.

SQL> select * from T1;

Empno ename job Mgr hiredate Sal comm deptno
-------------------------------------------------------------------------------------------------------
7369 Smith clerk 7902-12-80 800 20
7499 Allen salesman 7698 20-2 month-81 1600 300 30
7521 ward salesman 7698 22-2 month-81 1250 500 30
7566 Jones manager 7839 2975-81 20
7654 Martin salesman 7698 28-9 month-81 1250 1400 30
7698 Blake manager 7839 01-5 months-81 2850 30
7782 Clark manager 7839-81 2450 10
7839 King President 17-11 month-81 5000 10
7844 Turner salesman 7698 month-81 1500 0 30
7900 James Clerk 7698 03-12 months-81 950 30
7902 Ford analyst 7566 03-12 months-81 3000 20

Empno ename job Mgr hiredate Sal comm deptno
-------------------------------------------------------------------------------------------------------
7934 Miller clerk 7782 23-1 month-82 1300 10

12 rows have been selected.

SQL> Update T1 set a = ('zjs' | '000000' | to_char (rownum, 'fm000000000 '));

12 rows have been updated.

SQL> select * from T1;

Empno ename job Mgr hiredate Sal comm deptno
-------------------------------------------------------------------------------------------------------
7369 Smith clerk 7902-12 month-80 800 20 zjs2012010000000001
7499 Allen salesman 7698 20-2 month-81 1600 300 30 zjs2012010000000002
7521 ward salesman 7698 22-2 month-81 1250 500 30 zjs2012010000000003
7566 Jones manager 7839 2975-81 20 zjs2012010000000004
7654 Martin salesman 7698 28-9 month-81 1250 1400 30 zjs2012010000000005
7698 Blake manager 7839 01-5 month-81 2850 30 zjs2012010000000006
7782 Clark manager 7839 09-6 month-81 2450 10 zjs2012010000000007
7839 King President 17-11 month-81 5000 10 zjs201201020.00008
7844 Turner salesman 7698 month-81 1500 0 30 zjs201201020.00009
7900 James Clerk 7698 03-12 month-81 950 30 zjs2012010000000010
7902 Ford analyst 7566 03-12 month-81 3000 20 zjs2012010000000011

Empno ename job Mgr hiredate Sal comm deptno
-------------------------------------------------------------------------------------------------------
7934 Miller clerk 7782 23-1 month-82 1300 10 zjs2012010000000012

12 rows have been selected.

 

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.