欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

oracel Alter table 给表增加主键 primary key

程序员文章站 2024-02-19 17:28:04
...

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> --