yuki
yuki

Reputation: 65

How can I fix this ERROR MESSAGE" unique constraint"?

create table Store_Owner1
(
    phone_number number(10) not null,
    f_name varchar(10),
    last_name varchar(10),
    OwnerID number(10) primary key,
    Email varchar(10) 
);

insert into Store_Owner1 (phone_number, f_name, last_name, OwnerID, Email) 
values (0258744169, 'WAFA', 'ALOUFI', 0563224789, '[email protected]');

ALTER table Store_Owner1
MODIFY Email varchar (35);

select * from Store_Owner1;
------------------------------------------------

RUN
PHONE_NUMBER    F_NAME  LAST_NAME   OWNERID       EMAIL
258744169        WAFA    ALOUFI    563224789    [email protected]

Everything is okay when I do "select" but when I run the insert statement, I got an error

ORA-00001: unique constraint

Everything Bidou is in its correct place, but I do not know why this error appears

Upvotes: 0

Views: 960

Answers (1)

Greg Finley
Greg Finley

Reputation: 61

primary key implies that column needs to be unique. If you tried to insert the same OwnerId again, it will throw that error.

If it is in fact valid to have duplicate for OwnerId in this table, you can make some new primary key; it can even be an auto-generated uuid in many databases.

Upvotes: 1

Related Questions