I have a table A with columns Aname , Work
create table A(Aname varchar(40) , Work varchar(40) )
The table already has the below data inserted:
INSERT INTO A VALUES ('GREAME ','PLAYER')
Aname || Work
GREAME PLAYER
now i want that when i insert a new record, Aname–GREAME , Work—SALESMAN, then it is
inserted , but if i insert this : Aname–GREAME Work–PLAYER again, then it is not inserted
I want this:
Aname || Work
GREAME PLAYER
GREAME PLAYER — COULD NOT BE INSERTED
GREAME SALESMAN — COULD BE INSERTED
That is , the Work column checks for uniqueness when the to be inserted value of Aname
already exists.
How do i implement this? Please help with code.
EDIT——
in the insert query, the Aname column would be picked up from another table B
then how do i do it?
A unique constraint or a primary key will prevent you from insert with an error/exception. This insert will just not insert the row it it already exists.