DLSQL table error getting too many values - sql

I have written a DLSQL Table which draws the parameters from an excel file. I am getting errors such as too many values or the table does not process. The order of tables is not correct on the table as you can see the foreign keys in some of the first tables corrspond to the table below.
Here is the Excel file: https://drive.google.com/file/d/0Bzum6VJXi9lUdzJYa0tZbHhpbUk/view?usp=sharing
BEGIN
EXECUTE IMMEDIATE 'drop table DEPARTMENT cascade constraint';
EXECUTE IMMEDIATE 'drop table EMPLOYEE cascade constraint';
EXECUTE IMMEDIATE 'drop table DEPENDENT cascade constraint';
EXECUTE IMMEDIATE 'drop table DEPT_LOCATION cascade constraint';
EXECUTE IMMEDIATE 'drop table LOCATION cascade constraint';
EXECUTE IMMEDIATE 'drop table STAGING_DEPLOCATION cascade constraint';
EXECUTE IMMEDIATE 'drop table PROJECT cascade constraint';
EXECUTE IMMEDIATE 'drop table WORKS_ON cascade constraint';
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('');
END;
/
CREATE TABLE DEPARTMENT
(DEPT_NO NUMBER(15,0) NOT NULL,
DEPARTMENTNAME VARCHAR2(15) NOT NULL,
MANAGER_SSN NUMBER(9,0) NULL,
MANAGER_STARTDATE DATE NULL,
PRIMARY KEY (DEPT_NO));
/
/
CREATE TABLE EMPLOYEE
(SSN NUMBER(9,0) NOT NULL,
FIRSTNAME VARCHAR2(15) NOT NULL,
MI VARCHAR2(5) NULL,
LASTNAME VARCHAR2(15) NOT NULL,
DOB DATE NULL,
CITY VARCHAR2(20) NULL,
STATE VARCHAR2(20) NULL,
ZIP VARCHAR2(5) NULL,
SEX VARCHAR2(1) NULL,
SALARY NUMBER(15,0) NULL,
SUPERVISOR_SSN NUMBER(9) NULL,
DEPT_NO NUMBER(15,0) NULL,
PRIMARY KEY (SSN),
FOREIGN KEY(DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO));
/
CREATE TABLE DEPENDENT
(DEPENDENT_NO NUMBER(15,0) NOT NULL,
SSN NUMBER(9,0) NOT NULL,
FIRSTNAME VARCHAR2(15) NOT NULL,
LASTNAME VARCHAR2(15) NULL,
DOB DATE NULL,
SEX VARCHAR2(1) NULL,
RELATIONSHIP VARCHAR2(1) NULL,
PRIMARY KEY (DEPENDENT_NO),
FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN));
/
CREATE TABLE DEPT_LOCATION
(DEPT_NO NUMBER(15,0) NOT NULL,
LOCATION_NO NUMBER(15,0) NOT NULL,
ISACTIVE CHAR(10) NULL,
PRIMARY KEY (DEPT_NO, LOCATION_NO),
FOREIGN KEY(DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO)
FOREIGN KEY(LOCATION_NO) REFERENCES LOCATION(LOCATION_NO));
/
CREATE TABLE EMPLOYEE
(SSN NUMBER(9,0) NOT NULL,
FIRSTNAME VARCHAR2(15) NOT NULL,
MI VARCHAR2(5) NULL,
LASTNAME VARCHAR2(15) NOT NULL,
DOB DATE NULL,
CITY VARCHAR2(20) NULL,
STATE VARCHAR2(20) NULL,
ZIP VARCHAR2(5) NULL,
SEX VARCHAR2(1) NULL,
SALARY NUMBER(15,0) NULL,
SUPERVISOR_SSN NUMBER(9) NULL,
DEPT_NO NUMBER(15,0) NULL,
PRIMARY KEY (SSN),
FOREIGN KEY(DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO));
/
CREATE TABLE LOCATION
(LOCATION_NO NUMBER(15,0) NOT NULL,
LOCATION VARCHAR2(15) NULL,
PRIMARY KEY (LOCATION_NO));
/
CREATE TABLE STAGING_DEPLOCATION(
LOCATION VARCHAR2(50) NOT NULL,
DEPARTMENT VARCHAR2(50) NOT NULL,
ISACTIVE CHAR(10) NULL,
PRIMARY KEY (DEPT_NO, LOCATION_NO),
FOREIGN KEY(DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO)
FOREIGN KEY(LOCATION_NO) REFERENCES LOCATION(LOCATION_NO));
/
CREATE TABLE PROJECT
(PROJECT_NO NUMBER(15,0) NOT NULL,
DEPT_NO NUMBER(15,0) NOT NULL,
LOCATION_NO NUMBER(10,0) NULL,
PROJECTNAME VARCHAR2(20) NULL,
PRIMARY KEY (PROJECT_NO),
FOREIGN KEY(DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO),
FOREIGN KEY(LOCATION_NO) REFERENCES LOCATION(LOCATION_NO));
/
CREATE TABLE WORKS_ON
(SSN NUMBER(15,0) NOT NULL,
PROJECT_NO NUMBER(15,0) NOT NULL,
HOURS NUMBER(15,0) NULL,
PRIMARY KEY (SSN, PROJECT_NO));
create sequence dependent_seq
start with 1
increment by 1
nocache
nocycle;
SET DEFINE OFF;
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENTNAME, MANAGER_SSN, MANAGER_STARTDATE) VALUES ('1', 'headquarters', '888665555', '1971-06-19');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENTNAME, MANAGER_SSN, MANAGER_STARTDATE) VALUES ('2', 'administration', '987987987', '1985-01-01');
INSERT INTO DEPARTMENT (DEPT_NO, DEPARTMENTNAME, MANAGER_SSN, MANAGER_STARTDATE) VALUES ('3', 'research', '333445555', '1978-05-22');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('123456789', 'Roberto', 'B', 'Tamburello', '1955-01-09', '731 Fondren', 'Houston', 'TX', '11233'. 'M', '30000', '333445555', '5');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('333445555', 'David', 'T', 'Bradley', '1945-12-08', '38 Voss', 'Houston', 'TX', '11233', 'M', '40000', '888665555', '5');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('453453453', 'Mary', 'A', 'Dempsey', '1962-07-31', '5631 Rice', 'Houston', 'TX', '11233', 'F', '25000', '333445555', '5');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('666884444', 'Ramesh', 'K', 'Narayan', '1952-08-15', '975 Fire Oak', 'Humble', 'TX', '11232', 'M', '38000', '333445555', '5');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('888665555', 'James', 'E', 'Borg', '1991-11-10', '450 Stone', 'Houston', 'TX', '11233', 'M', '55000', '', '1');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('987654321', 'Terry', 'S', 'Duffy', '1990-06-20', '231 Berry', 'Bellaire', 'TX', '11236', 'F', '43000', '888665555', '4');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('987987987', 'Jossef', 'V', 'Goldberg', '1959-03-29', '980 Dallas', 'Houston', 'TX', '11233', 'M', '25000', '987654321', '4');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('999887777', 'Terry', 'J', 'Zelaya', '1958-07-19', '3321 Castle', 'Spring', 'TX', '11239', 'F', '25000', '987654321', '4');
INSERT INTO EMPLOYEE (SSN, FIRSTNAME, MI, LASTNAME, DOB, CITY, STATE, ZIP, SEX, SALARY, SUPERVISOR_SSN, DEPT_NO) VALUES ('999887777', 'John', '', 'Clay', '1938-07-19', '3321 Castle', 'Spring', 'TX', '11239', 'F', '35000', '987654321', '3');
ALTER TABLE DEPARTMENT ADD CONSTRAINT fk_dept FOREIGN KEY (MANAGER_SSN) REFERENCES EMPLOYEE(SSN);
ALTER TABLE EMPLOYEE ADD CONSTRAINT fk_empdept FOREIGN KEY (DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO);
CREATE SEQUENCE dependent_seq START WITH 1;
nsert into DEPENDENT (DEPENDENT_NO,SSN,FIRSTNAME,LASTNAME,DOB,SEX,RELATIONSHIP) VALUES (dependent_seq.nextval,123456789, 'Lili','Tamburello',to_date( '1978-12-31','yyyy-mm-dd'),'F','DAUGHTER');
Insert into DEPENDENT (DEPENDENT_NO,SSN,FIRSTNAME,LASTNAME,DOB,SEX,RELATIONSHIP) VALUES (dependent_seq.nextval,123456789, 'Anna','Tamburello',to_date( '1957-05-05','yyyy-mm-dd'),'F','SPOUSE');
Insert into DEPENDENT (DEPENDENT_NO,SSN,FIRSTNAME,LASTNAME,DOB,SEX,RELATIONSHIP) VALUES (dependent_seq.nextval,123456789, 'Gregory','Tamburello',to_date( '1978-01-01','yyyy-mm-dd'),'M','SON');
Insert into DEPENDENT (DEPENDENT_NO,SSN,FIRSTNAME,LASTNAME,DOB,SEX,RELATIONSHIP) VALUES (dependent_seq.nextval,333445555, 'Alice','Bradley',to_date( '1976-04-05','yyyy-mm-dd'),'F','DAUGHTER');
Insert into DEPENDENT (DEPENDENT_NO,SSN,FIRSTNAME,LASTNAME,DOB,SEX,RELATIONSHIP) VALUES (dependent_seq.nextval,333445555, 'Theodore','Bradley',to_date( '1973-10-25','yyyy-mm-dd'),'M','SON');
Insert into DEPENDENT (DEPENDENT_NO,SSN,FIRSTNAME,LASTNAME,DOB,SEX,RELATIONSHIP) VALUES (dependent_seq.nextval,987654321, 'Abner','Duffy',to_date( '1969-02-28','yyyy-mm-dd'),'M','SPOUSE');
Insert into DEPENDENT (DEPENDENT_NO,SSN,FIRSTNAME,LASTNAME,DOB,SEX,RELATIONSHIP) VALUES (dependent_seq.nextval,987654321, 'Aby','John',to_date( '1970-02-28','yyyy-mm-dd'),'M','SPOUSE');
INSERT INTO DEPT_LOCATION(DEPT_NO, LOCATION_NO, ISACTIVE)
SELECT DEPT_NO, LOCATION_NO, ISACTIVE FROM STAGING_DEPLOCATION A
INNER JOIN LOCATION B ON B.LOCATION = A.LOCATION
INNER JOIN DEPARTMENT D ON D.DEPARTMENTNAME = A.DEPARTMENTNAME;
INSERT INTO DEPT_LOCATION (DEPT_NO, LOCATION_NO, ISACTIVE) VALUES ('headquarters', 'Houston', '');
INSERT INTO DEPT_LOCATION (DEPT_NO, LOCATION_NO, ISACTIVE) VALUES ('administration', 'Stafford', '');
INSERT INTO DEPT_LOCATION (DEPT_NO, LOCATION_NO, ISACTIVE) VALUES ('research', 'Bellaire', '');
INSERT INTO DEPT_LOCATION (DEPT_NO, LOCATION_NO, ISACTIVE) VALUES ('research', 'Houston', '');
INSERT INTO DEPT_LOCATION (DEPT_NO, LOCATION_NO, ISACTIVE) VALUES ('research', 'Sugarland', '');
INSERT INTO LOCATION (LOCATION_NO, LOCATION) VALUES ('1', 'Bellaire');
INSERT INTO LOCATION (LOCATION_NO, LOCATION) VALUES ('2', 'Houston');
INSERT INTO LOCATION (LOCATION_NO, LOCATION) VALUES ('3', 'Stafford');
INSERT INTO LOCATION (LOCATION_NO, LOCATION) VALUES ('4', 'Sugarland');
INSERT INTO PROJECT (PROJECT_NO, DEPT_NO, LOCATION_NO, PROJECTNAME) VALUES ('1', '5', '1', 'ProductX');
INSERT INTO PROJECT (PROJECT_NO, DEPT_NO, LOCATION_NO, PROJECTNAME) VALUES ('2', '5', '4', 'ProductY');
INSERT INTO PROJECT (PROJECT_NO, DEPT_NO, LOCATION_NO, PROJECTNAME) VALUES ('3', '5', '2', 'ProductZ');
INSERT INTO PROJECT (PROJECT_NO, DEPT_NO, LOCATION_NO, PROJECTNAME) VALUES ('10', '4', '3', 'Computerization');
INSERT INTO PROJECT (PROJECT_NO, DEPT_NO, LOCATION_NO, PROJECTNAME) VALUES ('20', '1', '2', 'Reorganization');
INSERT INTO PROJECT (PROJECT_NO, DEPT_NO, LOCATION_NO, PROJECTNAME) VALUES ('30', '4', '3', 'Newbenefits');
INSERT INTO PROJECT (PROJECT_NO, DEPT_NO, LOCATION_NO, PROJECTNAME) VALUES ('1', '5', '1', 'ProductX');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('123456789', '1', '33');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('123456789', '2', '8');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('333445555', '2', '10');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('333445555', '3', '10');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('333445555', '10', '10');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('333445555', '20', '10');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('453453453', '1', '20');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('453453453', '2', '20');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('666884444', '3', '40');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('888665555', '20', '');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('987654321', '20', '15');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('987654321', '30', '20');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('987987987', '10', '35');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('987987987', '30', '5');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('999887777', '10', '10');
INSERT INTO WORKS_ON (SSN, PROJECT_NO, HOURS) VALUES ('999887777', '30', '30');
COMMIT;

Because, when you are trying to INSERT INTO EMPLOYEE where you have mentioned 12 columns, but you are passing 13 values.
You need to pass exactly same number of values, which you have specific after INSERT INTO EMPLOYEE

Related

parent key not found ORA-06512: at "SYS.DBMS_SQL"

Can't figure out the problem, and will appreciate the help. There was no problem while defining the tables and alterations. For some reason it can't figure out the parent key reference in another table/ in the same table. What could be the possible solution for such problems?
Problem is caused by the EMP table constraint.
create table DPT (
DNO varchar2(3) constraint pri_key primary key,
DNAME varchar2(10) constraint unq unique,
constraint sta_letr check(DNO like 'D%')
);
create table PROJECTS (
DNO varchar2(3) constraint dno_fork references DPT(DNO) constraint dno_nullState not null,
PRJ_NO varchar2(5) constraint rgexCheck check(PRJ_NO like 'P%') constraint prj_nullState not null,
PRJ_NAME varchar2(10),
PRJ_CREDITS number(2) constraint credRange check(PRJ_CREDITS between 1 and 10),
START_DATE date,
END_DATE date,
constraint prKey primary key(DNO, PRJ_NO),
constraint dateChecker check(END_DATE > START_DATE)
);
create table EMP (
EMPNO number(4),
ENAME varchar2(10),
EJOB varchar2(9) default 'CLRK' constraint jobCheck check(EJOB in('CLRK', 'A.MGR', 'MGR', 'GM', 'CEO')),
MGR_ID number(4),
BIRTH_DATE date,
SAL number(7,2) default 20001 constraint salCheck check(SAL > 20000),
COMM number(7,2) default 1000,
DEPTNO varchar2(3) constraint deptFk references DPT(DNO),
PRJ_ID varchar2(9) default 'P1',
DATE_OF_JOIN date,
constraint supervisor foreign key(MGR_ID) references EMP(EMPNO),
constraint pri_ky primary key(EMPNO)
);
--Insertion, Modifications and Alterations
alter table EMP modify PRJ_ID varchar2(5);
alter table EMP drop constraint deptFk;
alter table EMP add constraint deptRef foreign key(DEPTNO, PRJ_ID) references PROJECTS(DNO, PRJ_NO);
alter table DPT add LOCATIONS varchar2(9);
alter table DPT modify LOCATIONS default 'BNG';
alter table DPT add constraint oth_val check(LOCATIONS in ('BNG', 'MNG', 'MUB', 'HYD', 'CHN'));
alter table DPT modify DNAME varchar2(15);
insert into DPT (DNO, DNAME, LOCATIONS) values ('D1', 'Marketing', 'CHN');
insert into DPT (DNO, DNAME, LOCATIONS) values ('D2', 'Research', 'MNG');
insert into DPT (DNO, DNAME, LOCATIONS) values ('D3', 'Administrator', 'BNG');
insert into DPT (DNO, DNAME, LOCATIONS) values ('D4', '', 'BNG');
insert into DPT (DNO, DNAME, LOCATIONS) values ('D5', 'IT', 'BNG');
insert into DPT (DNO, DNAME, LOCATIONS) values ('D6', 'Corporate', 'HYD');
select * from DPT;
insert into PROJECTS (DNO, PRJ_NO, PRJ_NAME, PRJ_CREDITS) values ('D1', 'P1', '', 2);
insert into PROJECTS (DNO, PRJ_NO, PRJ_NAME, PRJ_CREDITS) values ('D2', 'P1', '', 2);
insert into PROJECTS (DNO, PRJ_NO, PRJ_NAME, PRJ_CREDITS) values ('D3', 'P2', '', 7);
insert into PROJECTS (DNO, PRJ_NO, PRJ_NAME, PRJ_CREDITS) values ('D1', 'P3', '', 5);
insert into PROJECTS (DNO, PRJ_NO, PRJ_NAME, PRJ_CREDITS) values ('D4', 'P2', '', 7);
select * from PROJECTS;
--Statement where the problem is occurring.
insert into EMP (EMPNO, ENAME, EJOB, MGR_ID, BIRTH_DATE, SAL, DEPTNO, PRJ_ID, DATE_OF_JOIN) values (100, 'Ravi', 'MGR', 111, to_date('10-10-1985', 'dd-mm-yyyy'), 32000, 'D1', 'P1', to_date('2-10-2001', 'dd-mm-yyyy'));
Error Code: ORA-02291: integrity constraint (SQL_OZPTHTLYAAVUSNISLXUTJKQNF.SUPERVISOR) violated - parent key not found ORA-06512: at "SYS.DBMS_SQL", line 1721
You must insert the records in the EMP table in the order of the hierarchy, e.g. first the manager, than the employee
Your first insert of the employee 100 complains that the manager with EMPNO 111 does not exists...
insert into EMP (EMPNO, ENAME, EJOB, MGR_ID, ...
values (100, 'Ravi', 'MGR', 111, ...

Oracle SQL Unique Constraint Violated

I need to create tables and input values. All but two rows when inserted give me an error, Unique Constraint Violated. The last row in DEPT_LOCATIONS table and the second to the last row in DEPENDENT table. I'm not sure why these rows aren't being added because other rows in the same table are.
Here's my code so far:
/*Create Employee Table/*
create table EMPLOYEE(FNAME varchar(30), MINIT varchar(5), LNAME varchar(30), SSN varchar(10) PRIMARY KEY, BDATE varchar(30), ADDRESS varchar(30), SEX varchar(5), SALARY NUMERIC(10,0),
SUPERSSN varchar(30),DNO varchar(30));
/*Insert values into Employee Table/*
insert into EMPLOYEE values('John','B','Smith','123456789','1965-01-09','731 Fonden, Houston, TX','M', 30000,'333445555','5');
insert into EMPLOYEE values('Franklin','T','Wong','333445555','1955-12-08','638 Voss, Houston, TX','M', 40000,'888665555','5');
insert into EMPLOYEE values('Alice','J','Zelaya','999887777','1968-01-19','3321 Castle, Spring, TX','F', 25000,'987654321','4');
insert into EMPLOYEE values('Jennifer','S','Walace','987654321','1941-06-20','291 Berry, Bellaire, TX','F', 43000,'888665555','4');
insert into EMPLOYEE values('Ramesh','K','Narayan','666884444','1962-09-15','975 Fire Oak, Humble, TX','M', 38000,'333445555','5');
insert into EMPLOYEE values('Joyce','A','English','453453453','1972-07-31','5631 Rice, Houston, TX','F', 25000,'333445555','5');
insert into EMPLOYEE values('Ahmed','V','Jabbar','987987987','1969-03-29','980 Dallas, Houston, TX','M', 25000,'987654321','4');
insert into EMPLOYEE values('James','E','Bong','888665555','1937-11-10','450 Stone, Houston, TX','M', 55000,'null','1');
/*Create Department Table*/
create table DEPARTMENT(DNAME varchar(30), DNUMBER varchar(30) PRIMARY KEY, MGRSSN varchar(30), MGRSTARTDATE varchar(30));
/*Insert values into Department Table*/
insert into DEPARTMENT values('Research', '5', '333445555', '1988-05-22');
insert into DEPARTMENT values('Administration', '4', '987654321', '1995-01-01');
insert into DEPARTMENT values('Headquarters', '1', '888665555', '1981-06-19');
/*Create Department Location Table*/
create table DEPT_LOCATIONS(DNUMBER varchar(30) REFERENCES DEPARTMENT(DNUMBER), DLOCATION varchar(30) PRIMARY KEY);
/*Insert values into Department Location Table*/
insert into DEPT_LOCATIONS values('1', 'Houston');
insert into DEPT_LOCATIONS values('4', 'Stafford');
insert into DEPT_LOCATIONS values('5', 'Bellarire');
insert into DEPT_LOCATIONS values('5', 'Sugarland');
insert into DEPT_LOCATIONS values('5', 'Houston');
/*Create Project Table*/
create table PROJECT(PNAME varchar(30), PNUMBER varchar(30) PRIMARY KEY, PLOCATION varchar(30), DNUM varchar(30) REFERENCES DEPARTMENT(DNUMBER));
/*Insert values into Project Table*/
insert into PROJECT values('ProductX', '1', 'Bellaire', '5');
insert into PROJECT values('ProductY', '2', 'Sugarland', '5');
insert into PROJECT values('ProductZ', '3', 'Houston', '5');
insert into PROJECT values('Computerization', '10', 'Stafford', '4');
insert into PROJECT values('Reorganization', '20', 'Houston', '1');
insert into PROJECT values('Newbenefits', '30', 'Stafford', '4');
/*Create Works On table*/
create table WORKS_ON(ESSN varchar(30) REFERENCES EMPLOYEE(SSN), PNO varchar(30) REFERENCES PROJECT(PNUMBER), HOURS numeric(5, 1));
/*Insert values into Works on Table*/
insert into WORKS_ON values('123456789', '1', 32.5);
insert into WORKS_ON values('123456789', '2', 7.5);
insert into WORKS_ON values('666884444', '3', 40.0);
insert into WORKS_ON values('453453453', '1', 20.0);
insert into WORKS_ON values('453453453', '2', 20.0);
insert into WORKS_ON values('333445555', '2', 10.0);
insert into WORKS_ON values('333445555', '3', 10.0);
insert into WORKS_ON values('333445555', '10', 10.0);
insert into WORKS_ON values('333445555', '20', 10.0);
insert into WORKS_ON values('999887777', '30', 30.0);
insert into WORKS_ON values('999887777', '10', 10.0);
insert into WORKS_ON values('987987987', '10', 35.0);
insert into WORKS_ON values('987987987', '30', 5.0);
insert into WORKS_ON values('987654321', '30', 20.0);
insert into WORKS_ON values('987654321', '20', 15.0);
insert into WORKS_ON values('888665555', '20', null);
/*Create Dependent table*/
create table DEPENDENT(ESSN varchar(30) REFERENCES EMPLOYEE(SSN), DEPENDENT_NAME varchar(30) PRIMARY KEY, SEX varchar(30), BDATE varchar(30), RELATIONSHIP varchar(30));
/*Insert values into Dependent Table*/
insert into DEPENDENT values('333445555', 'Alice', 'F', '1986-04-05', 'Daughter');
insert into DEPENDENT values('333445555', 'Theodore', 'M', '1983-10-25', 'Son');
insert into DEPENDENT values('333445555', 'Joy', 'F', '1958-05-03', 'Spouse');
insert into DEPENDENT values('987654321', 'Abner', 'M', '1942-02-28', 'Spouse');
insert into DEPENDENT values('123456789', 'Michael', 'M', '1988-01-04', 'Son');
insert into DEPENDENT values('123456789', 'Alice', 'F', '1988-12-30', 'Daughter');
insert into DEPENDENT values('123456789', 'Elizabeth', 'F', '1967-05-05', 'Spouse');
The tables should look like this:
enter image description here
enter image description here
Could someone please help me understand what is going on?
Thank you
DLOCATION varchar(30) PRIMARY KEY
insert into DEPT_LOCATIONS values('1', 'Houston');
insert into DEPT_LOCATIONS values('5', 'Houston');
The DLOCATION column is a primary key, but you are trying to insert duplicate values 'Houston' into the table. Therefore it throws unique constraint violated error. To overcome this, you could create it as a composite primary key with DNUMBER and DLOCATION together as:
CONSTRAINT pk_num_loc PRIMARY KEY (DNUMBER, DLOCATION)
DDL & inserts:
/*Create Department Location Table*/
CREATE TABLE dept_locations (
dnumber VARCHAR(30)
REFERENCES department ( dnumber ),
dlocation VARCHAR(30),
CONSTRAINT pk_num_loc PRIMARY KEY ( dnumber, dlocation ));
insert into DEPT_LOCATIONS values('1', 'Houston');
insert into DEPT_LOCATIONS values('4', 'Stafford');
insert into DEPT_LOCATIONS values('5', 'Bellarire');
insert into DEPT_LOCATIONS values('5', 'Sugarland');
insert into DEPT_LOCATIONS values('5', 'Houston');
SELECT * FROM dept_locations;
Output:
DNUMBER DLOCATION
------- ------------------------------
1 Houston
4 Stafford
5 Bellarire
5 Houston
5 Sugarland
Similarly, you need to do the same for rest of the tables which are failing due to unique constraint error.
In both cases you violated the primary key of the table, which must be unique. "Houston" is repeated for DEPT_LOCATIONS, as is "Alice" for DEPENDENTS.

INSERT ALL error ORA-02291 integrity constraint but PK is referenced

I'm creating a basic sales and inventory DB for a class.
I've successfully created the tables necessary with where I want my PK and FK's to be.
The issue I'm running into now is when I try to perform a multiple insert into my employees table.
Here's what has been created and inserted so far:
CREATE TABLE location (
zipcode int CONSTRAINT zipcode_pk PRIMARY KEY,
city varchar2 (50)
)
;
CREATE TABLE employees (
employeeid int CONSTRAINT employeeid_pk PRIMARY KEY,
firstname varchar2 (50),
lastname varchar2 (50),
street varchar2 (50),
state varchar2 (2),
zipcode int REFERENCES location (zipcode),
datehired date,
phonenum int,
salaryhr number
)
;
CREATE TABLE customer (
customerponum int CONSTRAINT customerponum_pk PRIMARY KEY,
firstname varchar2 (50),
lastname varchar2 (50),
street varchar2 (50),
zipcode int REFERENCES location (zipcode)
)
;
CREATE TABLE products (
productid int CONSTRAINT productid_pk PRIMARY KEY,
productname varchar2 (50),
price number (*,2),
costpercent int
)
;
CREATE TABLE inventory (
productid int REFERENCES products (productid),
unitonhand int,
CONSTRAINT productid_pkt PRIMARY KEY (productid)
)
;
CREATE TABLE sales (
ordernum int CONSTRAINT ordernum_pk PRIMARY KEY,
customerponum int REFERENCES customer (customerponum),
productid int REFERENCES products (productid),
employeeid int REFERENCES employees (employeeid),
saledate date,
unitssold int
)
;
INSERT ALL
INTO location (zipcode, city) VALUES (77095, 'Houston')
INTO location (zipcode, city) VALUES (77451, 'Dallas')
INTO location (zipcode, city) VALUES (77114, 'Austin')
INTO location (zipcode, city) VALUES (77369, 'Lubbock')
INTO location (zipcode, city) VALUES (75451, 'El Paso')
SELECT * FROM dual
;
INSERT ALL
INTO customer (customerponum, firstname, lastname, street, zipcode) VALUES (101, 'Josh', 'Smith', '100 Baker St',77095)
INTO customer (customerponum, firstname, lastname, street, zipcode) VALUES (102, 'John', 'Doe', '12 Yankee Ave',77451)
INTO customer (customerponum, firstname, lastname, street, zipcode) VALUES (103, 'Brandon', 'Markle', '1 Longhorn Blvd',77114)
INTO customer (customerponum, firstname, lastname, street, zipcode) VALUES (104, 'Mary', 'Eglin', '223 Aggie St',77369)
INTO customer (customerponum, firstname, lastname, street, zipcode) VALUES (105, 'Sue', 'Fields', '91 Patriot',75451)
SELECT * FROM dual
;
'''
---Oracle liveSQL this is the statement that I receive the error
---
INSERT ALL
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (1, 'Jason', 'Wayne', '103 Brown St', 'TX', 77453, '14-may-13', 2814441304, 13)
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (2, 'Jacob', 'Dutch', '14 Yawn Rd', 'TX', 77096, '12-july-11', 8325472222, 10)
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (3, 'Susan', 'Anthony', '1 Patronas Ln', 'TX', 77231, '08-jan-17', 2819993547, 9)
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (4, 'David', 'Lane', '888 Madrid Blvd', 'TX', 78113, '27-dec-18', 8321119876, 8)
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (5, 'Anthony', 'Barnard', '21 Adiom Cl', 'TX', 79448, '13-nov-17', 2814558008, 10)
SELECT * FROM dual
;
When I run the statement INSERT ALL INTO employees I get this error:
"ORA-02291: integrity constraint (SQL_NCBYEZZVAYRPDIJSWAZMSKRHK.SYS_C0016383126) violated - parent key not found ORA-06512: at "SYS.DBMS_SQL", line 1721"
The zip code values in your insert into the employees table don't match the ones you created in the location table, so the error is valid and expected.
Either change the employees zip codes to match the locations you already have, or more likely - since you already use those for customers - add new locations for the zip codes you are trying to use:
INSERT ALL
INTO location (zipcode, city) VALUES (77453, 'Lane City')
INTO location (zipcode, city) VALUES (77096, 'Houston')
INTO location (zipcode, city) VALUES (77231, 'Houston')
INTO location (zipcode, city) VALUES (78113, 'Falls City')
INTO location (zipcode, city) VALUES (79448, 'Richland')
SELECT * FROM dual
;
5 rows inserted.
INSERT ALL
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (1, 'Jason', 'Wayne', '103 Brown St', 'TX', 77453, '14-may-13', 2814441304, 13)
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (2, 'Jacob', 'Dutch', '14 Yawn Rd', 'TX', 77096, '12-july-11', 8325472222, 10)
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (3, 'Susan', 'Anthony', '1 Patronas Ln', 'TX', 77231, '08-jan-17', 2819993547, 9)
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (4, 'David', 'Lane', '888 Madrid Blvd', 'TX', 78113, '27-dec-18', 8321119876, 8)
INTO employees (employeeid, firstname, lastname, street, state, zipcode, datehired, phonenum, salaryhr) VALUES (5, 'Anthony', 'Barnard', '21 Adiom Cl', 'TX', 79448, '13-nov-17', 2814558008, 10)
SELECT * FROM dual
;
5 rows inserted.
db<>fiddle

Why is my sql query returning no records?

Schema:
created table dept
CREATE table dept
(dept_id varchar (20) default 'department' NOT NULL,
locat varchar (25) default 'location' NOT NULL,
nme varchar (20) default 'name' NOT NULL);
inserting values
INSERT INTO dept(dept_id, locat, nme)
VALUES (1, 'dublin', 'payroll');
INSERT INTO dept(dept_id, locat, nme)
VALUES (2, 'galway', 'manufacturing');
INSERT INTO dept(dept_id, locat, nme)
VALUES (3, 'cork', 'sales');
created table emp
create table emp
(emp_id varchar (20) default 'id' NOT NULL,
NME varchar (20) default 'name' NOT NULL,
job_title varchar (25) default 'job' NOT NULL,
HIRE_DATE DATE,
SALARY INT (25) default '0' NOT NULL,
dept_id varchar (20) default 'dept' NOT NULL);
inserting values
INSERT INTO emp
VALUES (123, 'byrne', 'clerical', DATE ('2012-06-12'), 28000, 1);
INSERT INTO emp
VALUES (124, 'barry', 'operater', DATE ('11-07-11'), 33000,2);
INSERT INTO emp
VALUES (125, 'hynes', 'senior_operator', DATE ('26-09-13'), 36500,2);
INSERT INTO emp
VALUES (126, 'WILLIAMS', 'manager', DATE ('30-10-13'), 51000,3);
THE FOLLOWING QUERY IS RETURNING NO RECORDS
SELECT NME FROM emp
where HIRE_DATE between ('01-01-10') AND ('01-01-14');
How to change the code to get the desired output.
You proper date formats. In Oracle, you can introduce constants with the date keyword:
INSERT INTO emp (emp_id, NME, job_title , HIRE_DATE, SALARY, dept_id)
VALUES (123, 'byrne', 'clerical', DATE '2012-06-12', 28000, 1);
INSERT INTO emp (emp_id, NME, job_title , HIRE_DATE, SALARY, dept_id)
VALUES (124, 'barry', 'operater', DATE '2011-07-11', 33000, 2);
INSERT INTO emp (emp_id, NME, job_title , HIRE_DATE, SALARY, dept_id)
VALUES (125, 'hynes', 'senior_operator', DATE '2013-09-26', 36500, 2);
INSERT INTO emp (emp_id, NME, job_title , HIRE_DATE, SALARY, dept_id)
VALUES (126, 'WILLIAMS', 'manager', DATE '2013-10-30', 51000, 3);
select NME
from emp
where HIRE_DATE between date '2010-01-01' and date '2014-01-01';
I thought 2-digit years when out in 1999. Oracle might not be interpreting two-digit years the same way that you do.
Also, include the column list when doing an insert.

SQL program Permission Errors

I am trying to create a table and drop foreign keys and tables in the beginning. If I do not drop Foreign Keys, It works fine, but when I add the code, it gives me the error, saying that I do not have permission to the database. Can someone please check/tweak my SQL code? It might be an issue of re arranging the foreign key statements, but I have tried different combinations with no result.
USE master ;
GO
CREATE DATABASE Prop1;
GO
USE Prop1;
GO
ALTER TABLE LEASE DROP CONSTRAINT FK_LEASE_CLIENT
ALTER TABLE LEASE DROP CONSTRAINT FK_LEASE_PROPERTY_FOR_RENT
ALTER TABLE property_for_rent DROP CONSTRAINT FK_PROPERTY_FOR_RENT_BRANCH
ALTER TABLE property_for_rent DROP CONSTRAINT FK_PROPERTYFORRENTPRIVATEOWNER
ALTER TABLE registration DROP CONSTRAINT FK_REGISTRATION_BRANCH
ALTER TABLE registration DROP CONSTRAINT FK_REGISTRATION_CLIENT
ALTER TABLE registration DROP CONSTRAINT FK_REGISTRATION_STAFF
ALTER TABLE staff DROP CONSTRAINT FK_STAFF_BRANCH
ALTER TABLE viewing DROP CONSTRAINT FK_VIEWING_CLIENT
ALTER TABLE viewing DROP CONSTRAINT FK_VIEWING_PROPERTY_FOR_RENT
IF OBJECT_ID('dbo.viewing') IS NOT NULL
DROP TABLE dbo.viewing
IF OBJECT_ID('dbo.lease') IS NOT NULL
DROP TABLE dbo.lease
IF OBJECT_ID('dbo.property_for_rent') IS NOT NULL
DROP TABLE dbo.property_for_rent
IF OBJECT_ID('dbo.registration') IS NOT NULL
DROP TABLE dbo.registration
IF OBJECT_ID('dbo.staff') IS NOT NULL
DROP TABLE dbo.staff
IF OBJECT_ID('dbo.private_owner') IS NOT NULL
DROP TABLE dbo.private_owner
IF OBJECT_ID('dbo.client') IS NOT NULL
DROP TABLE dbo.client
IF OBJECT_ID('dbo.branch') IS NOT NULL
DROP TABLE dbo.branch
CREATE TABLE branch(
branchno varchar(5) NOT NULL,
street varchar(100) NULL,
city varchar(20) NULL,
postcode varchar(10) NULL,
PRIMARY KEY ( branchno )) ;
CREATE TABLE client(
clientno varchar(5) NOT NULL,
fname varchar(8) NULL,
lname varchar(8) NULL,
address varchar(35) NULL,
tel_no varchar(14) NULL,
pref_type char(6) NULL,
max_rent int NULL,
PRIMARY KEY ( clientno )) ;
CREATE TABLE lease(
lease_no varchar(6) NOT NULL,
property_no varchar(5) NULL,
client_no varchar(5) NULL,
rent int NULL,
payment_method char(7) NULL,
deposit int NULL,
paid char(1) NULL,
rent_start date NULL,
rent_finish date NULL,
duratn bigint NULL,
PRIMARY KEY ( lease_no ));
CREATE TABLE private_owner(
ownerno varchar(5) NOT NULL,
fname varchar(20) NULL,
lname varchar(20) NULL,
address varchar(50) NULL,
tel_no varchar(14) NULL,
PRIMARY KEY ( ownerno ));
CREATE TABLE property_for_rent(
propertyno varchar(5) NOT NULL,
street varchar(15) NULL,
city varchar(10) NULL,
postcode varchar(6) NULL,
type char(7) NULL,
rooms tinyint NULL,
rent int NULL,
ownerno varchar(5) NULL,
staffno varchar(5) NULL,
branchno varchar(5) NULL,
PRIMARY KEY ( propertyno )) ;
CREATE TABLE registration(
clientno varchar(5) NOT NULL,
branchno varchar(5) NOT NULL,
staffno varchar(5) NOT NULL,
datejoined date NULL,
PRIMARY KEY ( clientno , branchno , staffno )) ;
CREATE TABLE staff(
staffno varchar(5) NOT NULL,
fname varchar(15) NULL,
lname varchar(15) NULL,
position varchar(15) NULL,
sex char(1) NULL,
dob date NULL,
salary decimal(7, 2) NULL,
branchno varchar(5) NULL,
PRIMARY KEY ( staffno ));
CREATE TABLE viewing(
clientno varchar(5) NOT NULL,
propertyno varchar(5) NOT NULL,
viewdate date NULL,
comments varchar(200) NULL,
PRIMARY KEY ( clientno , propertyno )) ;
BEGIN TRANSACTION
INSERT INTO branch (branchno, street, city, postcode) VALUES ('B008', '12 Paul St', 'Preston', 'PR30JB');
INSERT INTO branch (branchno, street, city, postcode) VALUES ('B009', '32 Elizabeth St', 'Burmingham', 'BB17JE');
INSERT INTO branch (branchno, street, city, postcode) VALUES ('B010', '24 Koleen Dr', 'Manchester', 'KM41SA');
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR78', 'George', 'Clinto', '55 St Louis Dr London JW10FR', '0121-773-3325', 'House ', 500);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR79', 'Muhammad', 'Aslam', '10 Queens Rd London KW40FM', '0171-213-2625', 'House ', 700);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR80', 'Sea', 'Hampto', '69 Rosco St Burmingham BI21KL', '0565-773-3032', 'Flat ', 300);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR81', 'Cyrus', 'Azarbod', '6 Skyline Dr London IN15ZZ', '0181-362-9325', 'House ', 800);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR82', 'Leo', 'Russel', '214 Terrible Dr Glasgow GW18PR', '0891-448-5569', 'Flat ', 450);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR83', 'Sameul', 'Sutto', '16 Moscut St Preston PC18JK', '0607-524-4532', 'Flat ', 500);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR84', 'Lyndi', 'Clinto', '50 Ceasar Bld London JZ10LR', '0171-793-7325', 'House ', 750);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR85', 'Kathree', 'Joshue', '77 Hoffman Dr Manchester MN48NB', '0525-854-4178', 'House ', 900);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR86', 'Julia', 'Roberts', '707 Rockford Dr London LK51VD', '0420-568-8544', 'House ', 1500);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR87', 'Michael', 'Jackso', '14 Madona Dr Preston DW11FY', '0414-552-6632', 'House ', 1200);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR88', 'George', 'Simpso', '25 Charles Dr London YN10BR', '0181-798-7325', 'Flat ', 850);
INSERT INTO client (clientno, fname, lname, address, tel_no, pref_type, max_rent) VALUES ('CR89', 'Fredo', 'Sati', '7 Nitro Dr London JK89YE', '0181-507-5151', 'Flat ', 550);
INSERT INTO lease (lease_no, property_no, client_no, rent, payment_method, deposit, paid, rent_start, rent_finish, duratn) VALUES ('10087', 'PG76', 'CR78', 400, 'Cheque ', 800, 'Y','1995-03-02', '1999-10-31', NULL);
INSERT INTO lease (lease_no, property_no, client_no, rent, payment_method, deposit, paid, rent_start, rent_finish, duratn) VALUES ('10088', 'PG76', 'CR83', 400, 'Master ', 800, 'Y', '1999-11-01', '2002-09-30',NULL);
INSERT INTO lease (lease_no, property_no, client_no, rent, payment_method, deposit, paid, rent_start, rent_finish, duratn) VALUES ('10091', 'PG58', 'CR83', 500, 'Cash ', 900, 'Y', '2002-10-15','2003-01-15',NULL);
INSERT INTO lease (lease_no, property_no, client_no, rent, payment_method, deposit, paid, rent_start, rent_finish, duratn) VALUES ('10093', 'PG74', 'CR79', 600, 'Master ', 1200, 'Y', '1998-01-01', '1999-09-30',NULL);
INSERT INTO lease (lease_no, property_no, client_no, rent, payment_method, deposit, paid, rent_start, rent_finish, duratn) VALUES ('10095', 'PG15', 'CR84', 700, 'Cheque ', 1400, 'Y', '1995-04-15', '2003-03-15',NULL);
INSERT INTO lease (lease_no, property_no, client_no, rent, payment_method, deposit, paid, rent_start, rent_finish, duratn) VALUES ('10096', 'PG57', 'CR81', 750, 'Visa ', 1500, 'Y', '1996-01-01','2001-05-30',NULL);
INSERT INTO lease (lease_no, property_no, client_no, rent, payment_method, deposit, paid, rent_start, rent_finish, duratn) VALUES ('10100', 'PG56', 'CR87', 1200, 'Cash ', 2400, '', '2001-12-01', '2003-02-28',NULL);
INSERT INTO lease (lease_no, property_no, client_no, rent, payment_method, deposit, paid, rent_start, rent_finish, duratn) VALUES ('10101', 'PG59', 'CR86', 1400, 'Visa ', 3000, 'Y', '1997-11-01', '2001-11-30',NULL);
INSERT INTO private_owner (ownerno, fname, lname, address, tel_no) VALUES ('CO51', 'Blair', 'Steve', '2 Style Dr London JZ43KL', '0181-750-2551');
INSERT INTO private_owner (ownerno, fname, lname, address, tel_no) VALUES ('CO63', 'Kare', 'Salem', '14 Janet St Bristol BR43KL', '0121-750-6513');
INSERT INTO private_owner (ownerno, fname, lname, address, tel_no) VALUES ('CO64', 'Teetz', 'Alle', '2 Lookup Dr Manchester GA43', '0131-730-4002');
INSERT INTO private_owner (ownerno, fname, lname, address, tel_no) VALUES ('CO65', 'Leo', 'Russel', '15 Cicero St Bristol BR21UT', '0121-631-6262');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG15', '11 Arago', 'Manchester', 'SA32DC', 'House ', 4, 700, 'CO51', 'SG17', 'B008');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG56', '1 Jackson Ht', 'Manchester', 'MA32DC', 'House ', 6, 1200, 'CO51', 'SA81', 'B009');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG57', '10 Hamilton DR', 'Manchester', 'LO32VC', 'Flat ', 5, 700, 'CO64', 'SL61', 'B008');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG58', '65 Lori St', 'Burmingham', 'BR22DZ', 'Flat ', 3, 500, 'CO63', 'SL51', 'B010');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG59', '25 River Dr', 'Londo', 'YZ32DC', 'House ', 8, 1400, 'CO63', 'SA10', 'B009');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG71', '23 Lori St', 'Burmingham', 'BR22DZ', 'Flat ', 3, 500, 'CO63', 'SL51', 'B010');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG74', '304 Michelle St', 'Burmingham', 'BR29ZS', 'House ', 3, 600, 'CO51', 'SL51', 'B010');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG76', '7 Dracula St', 'Londo', 'OP32DC', 'Flat ', 3, 400, 'CO64', 'SA8', 'B008');
INSERT INTO property_for_rent (propertyno, street, city, postcode, type, rooms, rent, ownerno, staffno, branchno) VALUES ('PG78', '9 Thames Dr', 'Londo', 'JA32DC', 'House ', 4, 700, 'CO64', 'SG17', 'B010');
INSERT INTO staff (staffno, fname, lname, position, sex, dob, salary, branchno) VALUES ('SA10', 'Bria', 'Sothe', 'Supervisor', 'M', '1964-12-30', 17000.00, 'B008');
INSERT INTO staff (staffno, fname, lname, position, sex, dob, salary, branchno) VALUES ('SA5', 'Mark', 'Smith', 'Assistant', 'M', '1974-11-23',10000.00, 'B008');
INSERT INTO staff (staffno, fname, lname, position, sex, dob, salary, branchno) VALUES ('SA8', 'Jake', 'Austi', 'Assistant', 'M', '1979-01-03', 9000.00, 'B009');
INSERT INTO staff (staffno, fname, lname, position, sex, dob, salary, branchno) VALUES ('SG15', 'Angila', 'Jolee', 'Assistant', 'F', '1976-09-23', 12000.00, 'B010');
INSERT INTO staff (staffno, fname, lname, position, sex, dob, salary, branchno) VALUES ('SG16', 'Fredo ', 'Satin ', 'Supervisor', 'M', '1973-04-13', 16000.00, 'B010');
INSERT INTO staff (staffno, fname, lname, position, sex, dob, salary, branchno) VALUES ('SG17', 'Gyneth', 'Paltrow', 'Assistant', 'F', '1980-01-07', 11000.00, 'B010');
INSERT INTO staff (staffno, fname, lname, position, sex, dob, salary, branchno) VALUES ('SL51', 'Maria', 'Bria', 'Assistant', 'F', '1976-10-15', 13000.00, 'B009');
INSERT INTO staff (staffno, fname, lname, position, sex, dob, salary, branchno) VALUES ('SL61', 'Sheela', 'Johnso', 'Manager', 'F', '1969-02-20',33000.00, 'B009');
TRUNCATE TABLE viewing ;
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR78', 'PG71', '1993-06-01', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR78', 'PG57', '1985-02-01', 'We will go for it');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR79', 'PG57', '2002-01-01', 'Wonderful');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR79', 'PG76', '2002-10-01', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR79', 'PG74', '1999-10-01','Wonderful');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR79', 'PG15', '1995-06-01','Can you change the color');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR83', 'PG15', '2000-12-01','Wonderful');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR78', 'PG59', '1999-10-01', 'It is good');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR78', 'PG76', '1995-03-02', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR79', 'PG59', '1998-01-01', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR80', 'PG58', '1979-12-01', 'It is good');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR80', 'PG15', '1985-01-01', 'Let us think about it');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR81', 'PG15', '1996-01-01', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR81', 'PG59', '2001-06-01', 'I want to rent it ASAP');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR82', 'PG58', '2001-01-15', 'I like the kitchen the most');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR83', 'PG58', '2002-10-15', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR83', 'PG56', '1999-11-01', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR84', 'PG15', '1995-04-15', 'It is good');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR85', 'PG15', '2002-06-01', 'I like the kitchen the most');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR85', 'PG59', '2001-11-01', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR86', 'PG59', '1997-11-01', NULL);
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR87', 'PG56', '2001-12-01', 'I want to rent it ASAP');
INSERT INTO viewing (clientno, propertyno, viewdate, comments) VALUES ('CR87', 'PG59', '1999-04-01', 'I like the kitchen the most');
ALTER TABLE LEASE ADD CONSTRAINT FK_LEASE_CLIENT FOREIGN KEY(CLIENT_NO)
REFERENCES CLIENT (CLIENTNO)
;
ALTER TABLE LEASE ADD CONSTRAINT FK_LEASE_PROPERTY_FOR_RENT FOREIGN KEY(PROPERTY_NO)
REFERENCES PROPERTY_FOR_RENT (PROPERTYNO)
;
ALTER TABLE PROPERTY_FOR_RENT ADD FOREIGN KEY(BRANCHNO)
REFERENCES BRANCH (BRANCHNO);
ALTER TABLE PROPERTY_FOR_RENT ADD CONSTRAINT FK_PROPERTYFORRENTPRIVATEOWNER FOREIGN KEY(OWNERNO)
REFERENCES PRIVATE_OWNER (OWNERNO)
;
ALTER TABLE REGISTRATION ADD CONSTRAINT FK_REGISTRATION_BRANCH FOREIGN KEY(BRANCHNO)
REFERENCES BRANCH (BRANCHNO)
;
ALTER TABLE REGISTRATION ADD CONSTRAINT FK_REGISTRATION_CLIENT FOREIGN KEY(CLIENTNO)
REFERENCES CLIENT (CLIENTNO)
;
ALTER TABLE REGISTRATION ADD CONSTRAINT FK_REGISTRATION_STAFF FOREIGN KEY(STAFFNO)
REFERENCES STAFF (STAFFNO)
;
ALTER TABLE STAFF ADD FOREIGN KEY(BRANCHNO)
REFERENCES BRANCH (BRANCHNO)
;
ALTER TABLE VIEWING ADD CONSTRAINT FK_VIEWING_CLIENT FOREIGN KEY(CLIENTNO)
REFERENCES CLIENT (CLIENTNO)
;
ALTER TABLE VIEWING ADD CONSTRAINT FK_VIEWING_PROPERTY_FOR_RENT FOREIGN KEY(PROPERTYNO)
REFERENCES PROPERTY_FOR_RENT (PROPERTYNO)
;
COMMIT;