Reputation: 33
i'm trying and success to create primary key in Redshif
create table my_table(id int ,
primary key(id));
insert into my_table values
(id),
(1),
(1),
(20);
select count(*) from my_table
3
but it allows me to upload duplicated value ,
as far as i know primary key should contain unique values ,
did i do something wrong?
Upvotes: 3
Views: 291
Reputation: 2013
Create an identity key
which will act as an auto_increment surrogate key. This'll serve both the purpose - to uniquely identify the records in the table and prevent insertion of duplicate values.
Let's create a dummy table:
create table scratchpad.test_1
(id bigint identity(1,1),
name varchar(10));
insert into scratchpad.test_1(name)
values
('a'),('b'),('c'),('d');
select * from scratchpad.test_1;
The id
column acts as a primary key
. Deleting any record from the table does not impact the sequencing of other values and the id column can be used to uniquely identify the subsequent row.
Upvotes: 0
Reputation: 3109
you can find your answer here
one of the answers mention your problem with the primary key
Upvotes: 1