1
votes

I understand the basics of SQL and databases. However every time I run my script to insert data into a table, I get the following error:

ORA-00001: unique constraint (string.string) violated tips

This is my code:

DROP TABLE Bag;

CREATE TABLE Bag
(
    BranchID varchar2(3),
    HouseName varchar2(16),
    StreetName varchar2(16),
    City varchar2(16),
    Postcode varchar2(6),
    TelephoneNo1 number,
    TelephoneNo2 number,

    PRIMARY KEY(BranchID)
);

INSERT INTO Bag 
VALUES (01, 'Hayway', 'Jay Rd', 'Newcastle', 'N9R5DT', 09088, 09077);
1
There are several issues with the code. But the first insert on an empty table should not be causing this error. - Gordon Linoff
For once, you create the column BranchID as a varchar2(3), but you attempt to insert a number into it... - Jakob Busk Sørensen
BranchID must be a number - YanetP1988
It is, but generally you want to use an integer type for integers. - Jacob H
@Noceo I see what you mean! - Sterling King

1 Answers

2
votes

As per the documentation the correct syntax should be ...

INSERT INTO Bag 
   (BranchID, HouseName, StreetName, City, Postcode, TelephoneNo1, TelephoneNo2)
VALUES 
   ('01', 'Hayway', 'Jay Rd', 'Newcastle', 'N9R5DT', 09088, 09077);

Reference:

https://docs.oracle.com/cd/B12037_01/appdev.101/b10807/13_elems025.htm https://www.techonthenet.com/oracle/insert.php (easier to read)