SQL Server check constraint on part of composite primary key - sql

Trying to learn SQL. Can't seem to find an answer to this or if I did I don't know enough SQL to recognize it as such. Can you create a table with a composite primary key and a check constraint on one of the key columns?
To be specific this fails with:
The INSERT statement conflicted with the CHECK constraint "CH_AddressType". The conflict occurred in database "tempdb", table "dbo.#t
If I comment out the check constraint in the table create and uncomment the alter table the insert works.
Do the two ways of creating the table... create the same table? What am I missing?
create table #t
(
entityNo int not null,
addressType char(1) not null,
valid char(1) not null,
address1 varchar(256) not null,
address2 varchar(256) not null,
city varchar(128) not null,
stateCode char(2) not null,
zipCode char(5) not null,
dtCreate datetime not null,
dtUpdate datetime not null
constraint PK_Address_Entity
primary key (entityNo, addressType),
constraint CH_AddressValid
check (valid in ('Y', 'N')),
constraint CH_AddressType
check (valid in ('H', 'V'))
)
go
--alter table #t
-- add constraint CH_Address_Type check ((addressType) in ('H', 'V'))
--go
insert into #t (entityNo, addressType, valid, address1, address2, city, stateCode, zipCode, dtCreate, dtUpdate)
values (100, 'H', 'Y', '100 Some Street', '' , 'Someville', 'PA', '19335', '2016-10-08', '2016-10-08')
select * from #t
go
drop table #t
go

constraint CH_AddressType check (valid in ('H', 'V'))
should be
constraint CH_AddressType check (addressType in ('H', 'V'))

Related

how do i make my foreign key the actual ID instead of it being NULL?

I'm creating two tables and I would like to use UserID in User_info_table as a foreign key in the Trail_info_table, but it keeps showing as NULL.
CREATE TABLE CW2.User_info_table
(
UserID int IDENTITY PRIMARY KEY,
User_name varchar(255),
Email_Address varchar(255) NOT NULL,
User_password varchar(255) NOT NULL,
User_access_level int NOT NULL,
);
INSERT INTO CW2.User_info_table (User_name, Email_Address, User_password, User_access_level)
VALUES ('Grace Hopper', 'grace#plymouth.ac.uk', 'ISAD123!', 1)
INSERT INTO CW2.User_info_table (User_name, Email_Address, User_password, User_access_level)
VALUES ('Tim Berners-Lee', 'tim#plymouth.ac.uk', 'COMP2001!', 1)
INSERT INTO CW2.User_info_table (User_name, Email_Address, User_password, User_access_level)
VALUES ('Ada Lovelace', 'ada#plymouth.ac.uk', 'insecurePassword', 1)
CREATE TABLE CW2.Trail_info_table
(
TrailID int IDENTITY,
Trail_name char(255) NOT NULL,
Trail_owner varchar(255),
Trail_owner_ID int
FOREIGN KEY REFERENCES CW2.User_info_table(UserID),
Trail_difficulty int NOT NULL,
Trail_length int NOT NULL,
CONSTRAINT Trail_primary PRIMARY KEY (TrailID),
);
INSERT INTO CW2.Trail_info_table (Trail_name, Trail_owner, Trail_difficulty, Trail_length)
VALUES ('Spring Sprint', 'Grace Hopper', 1, 10)
INSERT INTO CW2.Trail_info_table (Trail_name, Trail_owner, Trail_difficulty, Trail_length)
VALUES ('Summer Stroll', 'Tim Berners-Lee', 2, 15)
INSERT INTO CW2.Trail_info_table (Trail_name, Trail_owner, Trail_difficulty, Trail_length)
VALUES ('Winter Waltz', 'Ada Lovelace', 3, 20)
I tried to get the UserID (1,2,3) in the Trail_owner_ID column as a foreign key but it keeps showing up as NULL

Foreign key references invalid column error in MS SQL

This is all in MS SQL.
I've seen this issue pop up a lot, and I searched around but I still can't figure out my issue. I'm getting the error telling me my foreign key references in invalid column in an uncreated table. However, I created the table as it shows up on my database table list, so it shows it is created.
I tried to move that said table above the table that references it, yet I'm still receiving the error. Would anyone know how to fix this?
My code:
CREATE SCHEMA usr_in;
go
CREATE TABLE gender_interst (
id int IDENTITY (1,1),
gend_id int
CONSTRAINT gender_interstpk PRIMARY KEY (id)
)
CREATE TABLE gender (
id int IDENTITY (1,1),
gend VARCHAR (20)
CONSTRAINT genderpk PRIMARY KEY (id)
);
SELECT * FROM gender_interst LEFT JOIN gender on gender_interst.id = gender.id;
SELECT * from gender_interst;
CREATE TABLE user_info (
id int PRIMARY KEY IDENTITY (1,1),
usr_name VARCHAR (30) NOT NULL,
f_name VARCHAR (30) NOT NULL,
l_name VARCHAR (30),
b_day DATE,
email VARCHAR (120) NOT NULL,
genderpkid VARCHAR (10) NOT NULL,
CONSTRAINT gender_fk FOREIGN KEY (genderpkid) REFERENCES gender (genderpk),
);
INSERT
INTO user_info
( usr_name, f_name, l_name, b_day, genderpkid, email)
VALUES
('JMAN', 'JOHN', 'DOE', '1990-01-01','M','EX#EMAIL'),
('JAM','JANE', 'DOE', '1995-05-02','F','EX#EMAIL'),
('NMAN','NICK', 'WEBB', '1999-06-22','M','EX#EMAIL'),
('LOBA','LOLA', 'LILLY', '1994-01-08','F','EX#EMAIL'),
('NOTSPMAN','PETER', 'PARKER','1985-11-25','M','EX#EMAIL');
SELECT * FROM user_info;
Your foreign key needs to reference the name of a table column (which is either id or gend) and not the name of the primary key (genderpk).
Therefore the foreign key script (CONSTRAINT gender_fk FOREIGN KEY (genderpkid) REFERENCES gender (genderpk)) should look something like CONSTRAINT gender_fk FOREIGN KEY (genderpkid) REFERENCES gender (id)
However to create the relationship the two columns need to have the same data type. user_info .genderpkid is VARCHAR (10) and user_info.id is int.
The other problem you might encounter is that the insert scripts insert the data into genderpkid column as M or F. Therefore int is not going to work
If you were to use use the values M or F for gender, then you can create a script like:
CREATE TABLE gender (
id VARCHAR (1),
gender VARCHAR (20)
CONSTRAINT gender_pk PRIMARY KEY (id)
);
CREATE TABLE user_info (
id int PRIMARY KEY IDENTITY (1,1),
usr_name VARCHAR (30) NOT NULL,
f_name VARCHAR (30) NOT NULL,
l_name VARCHAR (30),
b_day DATE,
email VARCHAR (120) NOT NULL,
genderId VARCHAR (1) NOT NULL,
CONSTRAINT gender_fk FOREIGN KEY (genderId) REFERENCES gender (id),
);
INSERT INTO gender (id, gender)
VALUES
('F', 'Female'),
('M', 'Male')
INSERT
INTO user_info
( usr_name, f_name, l_name, b_day, genderId, email)
VALUES
('JMAN', 'JOHN', 'DOE', '1990-01-01','M','EX#EMAIL'),
('JAM','JANE', 'DOE', '1995-05-02','F','EX#EMAIL'),
('NMAN','NICK', 'WEBB', '1999-06-22','M','EX#EMAIL'),
('LOBA','LOLA', 'LILLY', '1994-01-08','F','EX#EMAIL'),
('NOTSPMAN','PETER', 'PARKER','1985-11-25','M','EX#EMAIL');
SELECT * FROM user_info;
A better approach could be, to pass the whole phraze (male / female) to the table user_info. The table gender can be used to enforce referential integrity. All your information is then contained in SELECT * FROM user_info
For example:
CREATE TABLE gender (
[name] VARCHAR (20)
CONSTRAINT gender_pk PRIMARY KEY ([name])
);
CREATE TABLE user_info (
id int PRIMARY KEY IDENTITY (1,1),
usr_name VARCHAR (30) NOT NULL,
f_name VARCHAR (30) NOT NULL,
l_name VARCHAR (30),
b_day DATE,
email VARCHAR (120) NOT NULL,
gender VARCHAR (20) NOT NULL,
genderIntrest VARCHAR (20) NOT NULL,
CONSTRAINT gender_fk FOREIGN KEY (gender) REFERENCES gender ([name]),
CONSTRAINT genderIntrest_fk FOREIGN KEY (genderIntrest) REFERENCES gender ([name]),
);
INSERT INTO gender ([name])
VALUES
('Female'),
('Male')
INSERT
INTO user_info
( usr_name, f_name, l_name, b_day, gender, genderIntrest, email)
VALUES
('JMAN', 'JOHN', 'DOE', '1990-01-01','Male','Female', 'EX#EMAIL'),
('JAM','JANE', 'DOE', '1995-05-02','Female','Female', 'EX#EMAIL'),
('NMAN','NICK', 'WEBB', '1999-06-22','Male','Female','EX#EMAIL'),
('LOBA','LOLA', 'LILLY', '1994-01-08','Female','Female','EX#EMAIL'),
('NOTSPMAN','PETER', 'PARKER','1985-11-25','Male','Female','EX#EMAIL');
SELECT * FROM user_info;
You can remove the gender table and let the app that consumes it pass in the data. However for a learning exercises, it's probably better to leave it in

I keep getting errors on SQL Server - String & Binary Data truncation, Foreign Key Constraint

I am new to SQL and SQL Server. I am trying to implement a small database. However, I keep getting three errors.
Error #1:
String or binary data would be truncated
Error #2:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Formation__Locat__25869641"
Error #3:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__DATA__Classifica__2B3F6F97".
I've tried a variety of different changes and nothing seems to work. Can someone explain to me what I am doing wrong? Thanks
CREATE TABLE Location
(
LocationID CHAR(5) NOT NULL,
LocationName VARCHAR(75) NOT NULL,
PRIMARY KEY (LocationID)
);
CREATE TABLE Formation
(
FormationID CHAR(5) NOT NULL,
FormationName VARCHAR(75) NOT NULL,
RockType VARCHAR(75) NOT NULL,
LocationID INT NOT NULL,
PRIMARY KEY (FormationID),
FOREIGN KEY (LocationID) REFERENCES Location(LocationID)
);
CREATE TABLE Classification
(
ClassificationID CHAR(5) NOT NULL,
ClassificationType VARCHAR(75) NOT NULL,
ClassificationDescription VARCHAR(75) NOT NULL,
FormationID VARCHAR(5) NOT NULL,
PRIMARY KEY (ClassificationID),
FOREIGN KEY (FormationID) REFERENCES Formation(FormationID)
);
CREATE TABLE DATA
(
FossilID CHAR(5) NOT NULL,
FossilName VARCHAR(75) NOT NULL,
FossilType VARCHAR(75) NOT NULL,
CatalogueDate DATE NOT NULL,
ClassificationID VARCHAR(5) NOT NULL,
PRIMARY KEY (FossilID),
FOREIGN KEY (ClassificationID) REFERENCES Classification(ClassificationID)
);
INSERT INTO Location
VALUES ('001', 'Montana');
INSERT INTO Formation
VALUES ('R01', 'Hell Creek Formation', 'Cretaceous', 001);
INSERT INTO Classification
VALUES ('001', 'Saurischia', 'Brachiosauridae', 'Hell Creek Formation');
INSERT INTO DATA
VALUES ('F01', 'Brachiosaurus', 'Vertebrae', '01/MAY/2017', '001');
INT <> VARCHAR(5) <> CHAR(5). Column should be the same type:
CREATE TABLE Location (
LocationID CHAR(5) NOT NULL,
LocationName VARCHAR(75) NOT NULL,
PRIMARY KEY (LocationID)
);
CREATE TABLE Formation (
FormationID CHAR(5) NOT NULL,
FormationName VARCHAR(75) NOT NULL,
RockType VARCHAR(75) NOT NULL,
LocationID CHAR(5) NOT NULL, -- here
PRIMARY KEY (FormationID),
FOREIGN KEY (LocationID) REFERENCES Location(LocationID)
);
CREATE TABLE Classification (
ClassificationID CHAR(5) NOT NULL,
ClassificationType VARCHAR(75) NOT NULL,
ClassificationDescription VARCHAR(75) NOT NULL,
FormationID CHAR(5) NOT NULL, -- here
PRIMARY KEY (ClassificationID),
FOREIGN KEY (FormationID) REFERENCES Formation(FormationID)
);
CREATE TABLE DATA (
FossilID CHAR(5) NOT NULL,
FossilName VARCHAR(75) NOT NULL,
FossilType VARCHAR(75) NOT NULL,
CatalogueDate DATE NOT NULL,
ClassificationID CHAR(5) NOT NULL,
PRIMARY KEY (FossilID),
FOREIGN KEY (ClassificationID) REFERENCES Classification(ClassificationID)
);
DBFiddleDemo
And your insert statements:
INSERT INTO Location VALUES ('001', 'Montana');
INSERT INTO Formation VALUES ('R01', 'Hell Creek Formation', 'Cretaceous', '001'); --corrected
INSERT INTO Classification VALUES ('001', 'Saurischia', 'Brachiosauridae', 'R01'); --corrected
INSERT INTO DATA VALUES ('F01', 'Brachiosaurus', 'Vertebrae', '01/MAY/2017', '001');
Truncation error 'Hell Creek Formation' cannot fit CHAR(5). You need to refer PK. Also consider using:
INSERT INTO tab(col_name1, col_name2, ...)
VALUES(...)

Msg 2627, occured while using IDENT_CURRENT()

DDL:
CREATE TABLE OSOBA
(
id INT PRIMARY KEY not null IDENTITY,
imie VARCHAR(30) not null,
nazwisko VARCHAR(40) not null,
zawod VARCHAR(30) not null,
dataUrodzenia DATE,
plec BIT not null,
narodowosc VARCHAR(30) not null,
);
CREATE TABLE OSOBISTOSCI
(
nazwaMiasta VARCHAR(30) not null,
id INT not null,
adres VARCHAR(50),
czy BIT,
PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES OSOBA,
FOREIGN KEY (nazwaMiasta) REFERENCES MIASTA,
);
CREATE TABLE ARCHITEKCI
(
id INT not null,
uprawnienia VARCHAR(30) UNIQUE,
styl VARCHAR(30) not null,
liczba INT not null,
PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES OSOBA,
);
And I have these insert statements:
-- these work fine
INSERT INTO OSOBA (imie,nazwisko,zawod,dataUrodzenia,plec,narodowosc) VALUES ('Lech', 'Wałęsa', 'Elektryk', '19430129', 1, 'Polak');
INSERT INTO OSOBISTOSCI (nazwaMiasta, id, adres, czy) VALUES ('Gdańsk', IDENT_CURRENT('OSOBA'), 'ul. Polanki', 0);
-- these throw the below error message
INSERT INTO OSOBA (imie,nazwisko,zawod,dataUrodzenia,plec,narodowosc) VALUES ('Marcia','Frank','Architekt','19570720','0','Niemiec');
INSERT INTO ARCHITEKCI (id,styl,liczba) VALUES (IDENT_CURRENT('OSOBA'),'Nowoczesny',8);
Error:
Msg 2627, Level 14, State 1, Line 124
Violation of UNIQUE KEY constraint 'UQ_ARCHITEK_982D973E2BA18BE7'. Cannot insert duplicate key in object 'dbo.ARCHITEKCI'. The duplicate key value is ().
As Aaron mentioned the IDENT_CURRENT is not very reliable. It would be better to use an OUTPUT clause. See the following example:
DECLARE #LatestID TABLE (ID INT);
INSERT INTO #OSOBA (imie,nazwisko,zawod,dataUrodzenia,plec,narodowosc)
OUTPUT INSERTED.ID INTO #LatestID
VALUES ('Marcia','Frank','Architekt','19570720','0','Niemiec');
INSERT INTO #ARCHITEKCI (id,styl,liczba) VALUES ((SELECT ID FROM #LatestID),'Nowoczesny',8);

difficulty inserting values in database

I have created my tables as shown below (I am using Oracle XE). The problem that occurs is that when I try to insert values into the tables, I get an error because the value of one's foreign key, has not been entered as a primary key of the other. For example, see tables DEPARTMENT and EMPLOYEE. Below, along with table creation code, is also the data inserting part. How to bypass that problem?
CREATE TABLE DEPARTMENT
(
DNAME VARCHAR(10),
DEPTID INTEGER NOT NULL,
MNG_IDNO INTEGER NOT NULL,
PRIMARY KEY (DEPTID)
);
CREATE TABLE EMPLOYEE
(
IDNO INTEGER NOT NULL,
FNAME VARCHAR(10) NOT NULL,
LNAME VARCHAR(10) NOT NULL,
GENDER VARCHAR(6) NOT NULL,
CITY VARCHAR(20),
AREA VARCHAR(20),
STREET VARCHAR(50),
HOUSENO VARCHAR(4),
ZIPCODE INTEGER,
BIRTHDAY DATE,
SALARY INTEGER,
IBAN VARCHAR(34),
DEPT_ID INTEGER NOT NULL,
PRIMARY KEY (IDNO)
);
CREATE TABLE CUSTOMER
(
IDNO INTEGER NOT NULL,
FNAME VARCHAR(10) NOT NULL,
LNAME VARCHAR(10) NOT NULL,
GENDER VARCHAR(6) NOT NULL,
CITY VARCHAR(20),
AREA VARCHAR(20),
STREET VARCHAR(50),
HOUSENO VARCHAR(4),
ZIPCODE INTEGER,
BIRTHDAY DATE,
PRIMARY KEY (IDNO)
);
CREATE TABLE CAR
(
VIN INTEGER NOT NULL,
BRAND VARCHAR(10) NOT NULL,
MODEL VARCHAR(10) NOT NULL,
COLOR VARCHAR(10) NOT NULL,
TRANTYPE VARCHAR(10) NOT NULL,
FUELTYPE VARCHAR(10) NOT NULL,
ENGCC INTEGER NOT NULL,
ENTRYDATE DATE,
PRICE INTEGER NOT NULL,
PAYMENTMETHOD VARCHAR(10) NOT NULL,
DEPT_ID INTEGER NOT NULL,
CUST_IDNO INTEGER NOT NULL,
PRIMARY KEY (VIN)
);
CREATE TABLE CAR_PARTS
(
PARTNUM VARCHAR(25) NOT NULL,
PARTNAME VARCHAR(25) NOT NULL,
COST INTEGER NOT NULL,
PRIMARY KEY (PARTNUM)
);
CREATE TABLE USED_CAR
(
CAR_VIN INTEGER NOT NULL,
MILEAGE INTEGER NOT NULL,
REGDATE DATE NOT NULL,
PRIMARY KEY (CAR_VIN)
);
CREATE TABLE SERVICE
(
DUE_DATE DATE,
ARR_DATE DATE,
COST INTEGER NOT NULL,
SERVICE_NUM INTEGER NOT NULL,
CUST_IDNO INTEGER NOT NULL,
PAYMENTMETHOD VARCHAR(10) NOT NULL,
CAR_VIN INTEGER NOT NULL,
PRIMARY KEY (SERVICE_NUM)
);
CREATE TABLE CUST_PHONUMBER
(
PHONE_NUM INTEGER NOT NULL,
CUST_IDNO INTEGER NOT NULL,
PHONE_TYPE VARCHAR(10),
PRIMARY KEY (CUST_IDNO, PHONE_NUM)
);
CREATE TABLE CAR_DEFECTS
(
DEFECTS VARCHAR(100) NOT NULL,
CAR_VIN VARCHAR(100) NOT NULL,
PRIMARY KEY (DEFECTS, CAR_VIN)
);
CREATE TABLE EMPLOYEE_PHONUMBER
(
PHONENUM INTEGER NOT NULL,
EMPL_IDNO INTEGER NOT NULL,
PRIMARY KEY (PHONENUM, EMPL_IDNO)
);
CREATE TABLE SERVICE_DETAILS
(
SERVICENUM INTEGER NOT NULL,
PROBLEMS VARCHAR(100) NOT NULL,
SOLUTION VARCHAR(100),
PRIMARY KEY (PROBLEMS, SERVICENUM)
);
CREATE TABLE HAS
(
PART_NUM VARCHAR(25) NOT NULL,
CAR_VIN INTEGER NOT NULL,
PRIMARY KEY (PART_NUM, CAR_VIN)
);
CREATE TABLE USES
(
PART_NUM VARCHAR(25) NOT NULL,
SERVICE_NUM INTEGER NOT NULL,
PRIMARY KEY (PART_NUM, SERVICE_NUM)
);
ALTER TABLE DEPARTMENT ADD FOREIGN KEY (MNG_IDNO) REFERENCES EMPLOYEE(IDNO);
ALTER TABLE EMPLOYEE ADD FOREIGN KEY (DEPT_ID) REFERENCES DEPARTMENT(DEPTID);
ALTER TABLE CAR ADD FOREIGN KEY (DEPT_ID) REFERENCES DEPARTMENT(DEPTID);
ALTER TABLE CAR ADD FOREIGN KEY (CUST_IDNO) REFERENCES CUSTOMER(IDNO);
ALTER TABLE SERVICE ADD FOREIGN KEY (CUST_IDNO) REFERENCES CUSTOMER(IDNO);
ALTER TABLE SERVICE ADD FOREIGN KEY (CAR_VIN) REFERENCES CAR(VIN);
ALTER TABLE USED_CAR ADD FOREIGN KEY (CAR_VIN) REFERENCES CAR(VIN);
ALTER TABLE HAS ADD FOREIGN KEY (PART_NUM) REFERENCES CAR_PARTS(PARTNUM);
ALTER TABLE HAS ADD FOREIGN KEY (CAR_VIN) REFERENCES CAR(VIN);
ALTER TABLE USES ADD FOREIGN KEY (PART_NUM) REFERENCES CAR_PARTS(PARTNUM);
ALTER TABLE USES ADD FOREIGN KEY (SERVICE_NUM) REFERENCES SERVICE(SERVICE_NUM);
ALTER TABLE CUSTOMER_PHONUMBER ADD FOREIGN KEY (CUST_IDNO) REFERENCES CUSTOMER(IDNO);
ALTER TABLE EMPLOYEE_PHONUMBER ADD FOREIGN KEY (EMPL_IDNO) REFERENCES EMPLOYEE(IDNO);
ALTER TABLE SERVICE_DETAILS ADD FOREIGN KEY (SERVICENUM) REFERENCES SERVICE(SERVICE_NUM);
Data Insert:
INSERT INTO EMPLOYEE VALUES (1234,'ANTREAS','GEORGIOU','MALE','NICOSIA','STROVOLOS','PANAYIAS','12',2682,TO_DATE('01.01.1989', 'DD.MM.YYYY'),5000,9999999,1);
INSERT INTO EMPLOYEE VALUES (1235,'KOSTAS', 'KOSTA', 'MALE', 'NICOSIA','STROVOLOS','VIZANTIOU','12',2064,TO_DATE('01.02.1980', 'DD.MM.YYYY'),5000,9999998,2);
INSERT INTO EMPLOYEE VALUES (1236,'MARIA', 'ANTREOU', 'FEMALE', 'NICOSIA','EGKOMI','TSAROU','12',2522,TO_DATE('05.05.1988', 'DD.MM.YYYY'),5000,9999995,3);
INSERT INTO EMPLOYEE VALUES (1237,'GEORGIA', 'ANTREOU', 'FEMALE', 'NICOSIA','EGKOMI','TSAROU','13',2522,TO_DATE('05.05.1978', 'DD.MM.YYYY'),5000,9999996,4);
INSERT INTO DEPARTMENT VALUES ('SERVICE',1,1234);
INSERT INTO DEPARTMENT VALUES ('SALES',2,1235);
INSERT INTO DEPARTMENT VALUES ('ACCOUNTING',3,1236);
INSERT INTO DEPARTMENT VALUES ('MANAGEMENT',4,1237);
INSERT INTO CUSTOMER VALUES (4321, 'ANTREAS', 'ANTREOU','MALE','PAFOS','GEROSKIPOU','VIZANTIOU','3',2525,TO_DATE('04.04.1954','DD.MM.YYYY'));
INSERT INTO CUSTOMER VALUES (4322, 'MARIA', 'ANTREOU','FEMALE','PAFOS','GEROSKIPOU','VIZANTIOU','7',2525,TO_DATE('03.03.1953','DD.MM.YYYY'));
INSERT INTO CUSTOMER VALUES (4323, 'KOSTAS', 'ANTREOU','MALE','PAFOS','GEROSKIPOU','VIZANTIOU','3',2525,TO_DATE('04.04.1970','DD.MM.YYYY'));
INSERT INTO CUSTOMER VALUES (4324, 'ELENA', 'ANTREOU','MALE','PAFOS','GEROSKIPOU','VIZANTIOU','3',2252,TO_DATE('04.04.1985','DD.MM.YYYY'));
INSERT INTO CUSTOMER VALUES (4325, 'MARIOS', 'ANTREOU','MALE','PAFOS','GEROSKIPOU','VIZANTIOU','3',2525,TO_DATE('04.04.1987','DD.MM.YYYY'));
INSERT INTO CAR VALUES (1111111111, 'MAZDA', '3', 'BLUE', 'MANUAL', 'PETROL', 1600, TO_DATE('08.01.2013','DD.MM.YYYY'), 5000, 'CASH', 2, 4321);
INSERT INTO CAR VALUES (2222222222, 'TOYOTA', 'COROLLA','BLACK', 'MANUAL','PETROL',1600,TO_DATE('08.01.2013','DD.MM.YYYY'),7000,'FINANCE',2,4322);
INSERT INTO CAR VALUES (3333333333, 'TOYOTA', 'HILUX', 'GRAY', '4X4', 'DIESEL', 2500, TO_DATE('08.01.2013','DD.MM.YYYY'), 10000, 'CASH', 2 , 4325);
INSERT INTO CAR VALUES (4444444444, 'HONDA', 'CIVIC', 'BLACK', 'MANUAL', 'PETROL', 1300, TO_DATE('08.01.2013','DD.MM.YYYY'), 3000,'CASH', 2, 4323);
INSERT INTO CAR VALUES (5555555555, 'HONDA', 'INSIGHT', 'WHITE', 'AUTO', 'PETROL', 1500, TO_DATE('08.01.2013','DD.MM.YYYY'), 20000, 'FINANCE', 2, 4324);
INSERT INTO CAR_PARTS VALUES ('A20005B', 'RIGHT FRONT AXLE', 200);
INSERT INTO CAR_PARTS VALUES ('C15220C', 'AIR FILTER', 50);
INSERT INTO CAR_PARTS VALUES ('V99T', 'ENGINE GASKET', 80);
INSERT INTO CAR_PARTS VALUES ('A20004B', 'LEFT FRONT AXLE', 200);
INSERT INTO CAR_PARTS VALUES ('U9P002', 'INTAKE MANIFOLD', 300);
INSERT INTO USED_CAR VALUES (4444444444, 25000, TO_DATE('02.02.2000','DD.MM.YYYY'));
INSERT INTO USED_CAR VALUES (5555555555, 122000, TO_DATE('05.08.2003','DD.MM.YYYY'));
INSERT INTO SERVICE VALUES (TO_DATE('12.01.2013','DD.MM.YYYY'), TO_DATE('01.01.2013','DD.MM.YYYY'), 300, 0001, 4321, 'CASH', 1111111111);
INSERT INTO CUST_PHONUMBER VALUES (99123456, 4321, 'MOBILE');
INSERT INTO CUST_PHONUMBER VALUES (99849563, 4322, 'MOBILE');
INSERT INTO CUST_PHONUMBER VALUES (22568988, 4323, 'LANDLINE');
INSERT INTO CUST_PHONUMBER VALUES (25698974, 4324, 'LANDLINE');
INSERT INTO CUST_PHONUMBER VALUES (97584692, 4325, 'MOBILE');
INSERT INTO CAR_DEFECTS VALUES ('BROKEN SIDE MIRRORS|OIL LEAKS', 4444444444);
INSERT INTO CAR_DEFECTS VALUES ('RUSTY PAINT|WORN-OUT CLUTCH', 5555555555);
INSERT INTO EMPLOYEE_PHONUMBER VALUES (97989565, 1234);
INSERT INTO EMPLOYEE_PHONUMBER VALUES (97585858, 1235);
INSERT INTO EMPLOYEE_PHONUMBER VALUES (96525263, 1236);
INSERT INTO EMPLOYEE_PHONUMBER VALUES (97484852, 1237);
INSERT INTO SERVICE_DETAILS VALUES (0001, 'BROKEN FRONT RIGHT AXLE', 'REPLACED FRONT RIGHT AXLE');
INSERT INTO HAS VALUES ('A20005B', 1111111111);
INSERT INTO HAS VALUES ('A20004B', 1111111111);
INSERT INTO USES VALUES ('A20005B', 0001);