Home >Database >Mysql Tutorial >oracel Alter table 给表增加主键 primary key

oracel Alter table 给表增加主键 primary key

WBOY
WBOYOriginal
2016-06-07 17:45:532082browse

oracel alter table 给表增加主键 primary key

sql>
sql> create table emp (empno number(4) not null,
  2                    ename varchar2(10),
  3                    job varchar2(9),
  4                    mgr number(4),
  5                    hiredate date,
  6                    sal number(7, 2),
  7                    comm number(7, 2),
  8                    deptno number(2));

table created.

sql>
sql> insert into emp values (7369, 'smith', 'clerk',    7902, to_date('17-dec-1980', 'dd-mon-yyyy'), 800, null, 20);

1 row created.

sql> insert into emp values (7499, 'allen', 'salesman', 7698, to_date('20-feb-1981', 'dd-mon-yyyy'), 1600, 300, 30);

1 row created.

sql> insert into emp values (7521, 'ward',  'salesman', 7698, to_date('22-feb-1981', 'dd-mon-yyyy'), 1250, 500, 30);

1 row created.

sql> insert into emp values (7566, 'jones', 'manager',  7839, to_date('2-apr-1981',  'dd-mon-yyyy'), 2975, null, 20);

1 row created.

sql> insert into emp values (7654, 'martin', 'salesman', 7698,to_date('28-sep-1981', 'dd-mon-yyyy'), 1250, 1400, 30);

1 row created.

sql> insert into emp values (7698, 'blake', 'manager', 7839,to_date('1-may-1981', 'dd-mon-yyyy'), 2850, null, 30);

1 row created.

sql> insert into emp values (7782, 'clark', 'manager', 7839,to_date('9-jun-1981', 'dd-mon-yyyy'), 2450, null, 10);

1 row created.

sql> insert into emp values (7788, 'scott', 'analyst', 7566,to_date('09-dec-1982', 'dd-mon-yyyy'), 3000, null, 20);

1 row created.

sql> insert into emp values (7839, 'king', 'president', null,to_date('17-nov-1981', 'dd-mon-yyyy'), 5000, null, 10);

1 row created.

sql> insert into emp values (7844, 'turner', 'salesman', 7698,to_date('8-sep-1981', 'dd-mon-yyyy'), 1500, 0, 30);

1 row created.

sql> insert into emp values (7876, 'adams', 'clerk', 7788,to_date('12-jan-1983', 'dd-mon-yyyy'), 1100, null, 20);

1 row created.

sql> insert into emp values (7900, 'james', 'clerk', 7698,to_date('3-dec-1981', 'dd-mon-yyyy'), 950, null, 30);

1 row created.

sql> insert into emp values (7902, 'ford', 'analyst', 7566,to_date('3-dec-1981', 'dd-mon-yyyy'), 3000, null, 20);

1 row created.

sql> insert into emp values (7934, 'miller', 'clerk', 7782,to_date('23-jan-1982', 'dd-mon-yyyy'), 1300, null, 10);

1 row created.

sql>
sql>
sql> create table emp_reg
  2  as
  3  * from emp;

sql>
sql> alter table emp_reg add constraint emp_pk primary key(empno);

table altered.

sql>
sql>
sql> drop table emp_reg;

table dropped.

sql> --

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn