In oracle I would like to create table from existing table with the primary key of the existing table. I know I can create people1
then alter people1
to have the primary key. Is there a way to modify create table people1 as (select * from people);
to have id int primary key
as the primary key?
<code>CREATE TABLE people(
id int primary key,
name varchar(55),
status int,
phone varchar(55)
);
INSERT INTO people VALUES
(1, 'John', 1, '214-444-1234'),
(2, 'John', 1, '214-444-1234'),
(3, 'Mary', 0, '555-111-1234'),
(4, 'Mary', 0, '555-111-1234'),
(5, 'Jeff', 0, '214-222-1234'),
(6, 'Jeff', 0, '214-222-1234'),
(7, 'Bill', 1, '817-333-1234'),
(8, 'Bill', 1, '817-333-1234'),
(9, 'Bob' , 1, '214-555-1234'),
(10, 'Bob' , 1, '214-555-1234');
create table people1 as (select * from people);
ALTER TABLE people1
ADD CONSTRAINT people1_pk PRIMARY KEY (id);
</code>
<code>CREATE TABLE people(
id int primary key,
name varchar(55),
status int,
phone varchar(55)
);
INSERT INTO people VALUES
(1, 'John', 1, '214-444-1234'),
(2, 'John', 1, '214-444-1234'),
(3, 'Mary', 0, '555-111-1234'),
(4, 'Mary', 0, '555-111-1234'),
(5, 'Jeff', 0, '214-222-1234'),
(6, 'Jeff', 0, '214-222-1234'),
(7, 'Bill', 1, '817-333-1234'),
(8, 'Bill', 1, '817-333-1234'),
(9, 'Bob' , 1, '214-555-1234'),
(10, 'Bob' , 1, '214-555-1234');
create table people1 as (select * from people);
ALTER TABLE people1
ADD CONSTRAINT people1_pk PRIMARY KEY (id);
</code>
CREATE TABLE people(
id int primary key,
name varchar(55),
status int,
phone varchar(55)
);
INSERT INTO people VALUES
(1, 'John', 1, '214-444-1234'),
(2, 'John', 1, '214-444-1234'),
(3, 'Mary', 0, '555-111-1234'),
(4, 'Mary', 0, '555-111-1234'),
(5, 'Jeff', 0, '214-222-1234'),
(6, 'Jeff', 0, '214-222-1234'),
(7, 'Bill', 1, '817-333-1234'),
(8, 'Bill', 1, '817-333-1234'),
(9, 'Bob' , 1, '214-555-1234'),
(10, 'Bob' , 1, '214-555-1234');
create table people1 as (select * from people);
ALTER TABLE people1
ADD CONSTRAINT people1_pk PRIMARY KEY (id);
https://dbfiddle.uk/cEiJ2ZqF