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

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

Related

ORA-02290: check constraint violated

I keep getting the message "ORA-02290: check constraint violated" whenever I try to insert values into my table.
Here's the code for the table STORE:
CREATE TABLE STORE
(
StoreID INT PRIMARY KEY,
StoreName VARCHAR2(30) NOT NULL,
City VARCHAR2(30) NOT NULL,
Country VARCHAR2(30) NOT NULL CHECK (Country IN('Singapore','India','United States','Peru','Phillippines','People''s Republic of China','Canada')),
Phone VARCHAR2(30) NOT NULL,
Fax VARCHAR2(30),
Email VARCHAR2(50) UNIQUE,
Contact VARCHAR2(30) NOT NULL,
UNIQUE (StoreName, City)
);
And here's the INSERT statements I am trying to accomplish:
INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
VALUES (1, 'Eastern Sales', 'Singapore', 'Singapore', '65-543-1233', '65-543-1239', 'Sales#EasternSales.com.sg', 'Jeremy');
INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
VALUES (2, 'Eastern Treasures', 'Manila', 'Philippines', '63-2-654-2344', '63-2-654-2349', 'Sales#EasternTreasures.com.ph', 'Gracielle');
INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
VALUES (3, 'Jade Antiques', 'Singapore', 'Singapore', '65-543-3455', '95-543-3459', 'Sales#JadeAntiques.com.sg', 'Swee Lai');
INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
VALUES (4, 'Andes Treasures', 'Lima', 'Peru', '51-14-765-4566', '51-14-765-4569', 'Sales#AndesTreasures.com.pe', 'Juan Carlos');
INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
VALUES (5, 'Eastern Sales', 'Hong Kong', 'People''s Republic of China', '852-876-5677', '852-876-5679', 'Sales#EasternSales.com.hk', 'Sam');
INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
VALUES (6, 'Eastern Treasures', 'New Delhi', 'India', '91-11-987-6788', '91-11-987-6789', 'Sales#EasternTreasures.com.in', 'Deepinder');
INSERT INTO STORE(StoreID, StoreName, City, Country, Phone, Fax, Email, Contact)
VALUES (7, 'European Imports', 'New York City', 'United States', '800-432-8766', '800-432-8769', 'Sales#EuropeanImports.com.sg', 'Marcello');
It has created the 4th, 6th, and 7th values, but not the rest. What is going wrong?
You are violating the CHECK constraint as the values allowed doesn't match with the value you are trying to insert:
CHECK (Country IN('Singapore','India','United States','Peru','Phillippines','People''s Republic of China','Canada'))
VALUES (2, 'Eastern Treasures', 'Manila', 'Philippines', '63-2-654-2344', '63-2-654-2349', 'Sales#EasternTreasures.com.ph', 'Gracielle')
'Phillippines' in the constraint doesn't match with 'Philippines' in the insert statement.
Correct the country name in the CHECK constraint to 'Philippines' and it will work fine:
CREATE TABLE STORE
(
StoreID INT PRIMARY KEY,
StoreName VARCHAR2(30) NOT NULL,
City VARCHAR2(30) NOT NULL,
Country VARCHAR2(30) NOT NULL
CHECK (Country IN(
'Singapore','India','United States','Peru','Philippines','People''s Republic of China','Canada')),
Phone VARCHAR2(30) NOT NULL,
Fax VARCHAR2(30),
Email VARCHAR2(50) UNIQUE,
Contact VARCHAR2(30) NOT NULL,
UNIQUE (StoreName, City)
);

SQL - ORA-00911 - Invalid Character while trying to insert records

Oracle Live SQL.
I am trying to insert records for a table. The table goes through just fine but in each line of records, I am apparently entering some invalid characters. Of course, this is an extremely vague error. I don't know what's wrong.
I've tried changing the date values, tried removing values individually, but no matter what I get the same error.
CREATE TABLE Employee_Information (
employee varchar2(25) NOT NULL,
Address varchar2(50) NOT NULL,
Phone_number CHAR(10) NOT NULL,
Hire_date date,
Position varchar2(20),
Sales_Numbers varchar2(4),
Salary varchar2(6),
PRIMARY KEY(employee)
);
INSERT INTO Employee_Information (employee, address, phone_number,
hire_date, position, sales_numbers, salary)
VALUES (‘John Smith’, ‘123 1st street’, 5554622919, '2017-11-25', ‘assistant manager’, null, 55000);
INSERT INTO Employee_Information (employee, address, phone_number, hire_date, position, sales_numbers, salary)
VALUES (‘Bob Goldman’, ‘321 2nd street’, 5553392454, '2018-12-13', ‘cashier’, 345, 38000);
INSERT INTO Employee_Information (employee, address, phone_number, hire_date, position, sales_numbers, salary)
VALUES (‘Harry Wilson’, ‘222 3rd street’, 5553457777, '2018-01-10', ‘cashier’, 401, 42000);
INSERT INTO Employee_Information (employee, address, phone_number, hire_date, position, sales_numbers, salary)
VALUES (‘Sarah Adams’, ‘333 4th street’, 5555677654, '2019-03-15', ‘cashier’, 316, 36000);
INSERT INTO Employee_Information (employee, address, phone_number, hire_date, position, sales_numbers, salary)
VALUES (‘Alison Johnson’, ‘777 5th street’, 5559091111, '2017-11-01', ‘manager’, null, 60000);
ORA-00911 for every line of insertion.
try this: (date column you need to convert it to date and use ' chars instead of ‘ and ’)
INSERT INTO Employee_Information (employee, address, phone_number,
hire_date, position, sales_numbers, salary)
VALUES ('John Smith', '123 1st street', 5554622919, to_date('2017-11-25','yyyy-mm-dd') , 'assistant manager', null, 55000);
INSERT INTO Employee_Information (employee, address, phone_number, hire_date, position, sales_numbers, salary)
VALUES ('Bob Goldman', '321 2nd street', 5553392454, to_date('2018-12-13','yyyy-mm-dd'), 'cashier', 345, 38000);
INSERT INTO Employee_Information (employee, address, phone_number, hire_date, position, sales_numbers, salary)
VALUES ('Harry Wilson', '222 3rd street', 5553457777, to_date('2018-01-10','yyyy-mm-dd'), 'cashier', 401, 42000);
INSERT INTO Employee_Information (employee, address, phone_number, hire_date, position, sales_numbers, salary)
VALUES ('Sarah Adams', '333 4th street', 5555677654, to_date('2019-03-15','yyyy-mm-dd'), 'cashier', 316, 36000);
INSERT INTO Employee_Information (employee, address, phone_number, hire_date, position, sales_numbers, salary)
VALUES ('Alison Johnson', '777 5th street', 5559091111, to_date('2017-11-01','yyyy-mm-dd'), 'manager', null, 60000);

Selecting data across mulitple tables in Oracle SQL

I am new to SQL and I am trying to lists all organizations by name in ascending order with the maximum salary across all employees who belong to the organization. I have the Schema Below. Can anyone offer any help? I am also trying to lists all employees by name and if the employee is a manager of at least one organization, provide a row in the results with the name
of each org he/she manages else null.
SELECT Org.name, MAX(Employee.salary) AS "Highest salary"
From Org, Employee
GROUP BY Org.name;
The above code gets me a list of all the Org Names with the global max salary, but I am looking for the max of each Org. I think I may need to use some joins but I am not very familiar.
CREATE TABLE Employee
(
employeeId numeric(9) not null,
name varchar2(100) unique,
salary numeric(9) not null,
CONSTRAINT employeeId_pk PRIMARY KEY (employeeId)
);
CREATE TABLE Org
(
orgId numeric(9) not null,
name varchar2(100) not null unique,
managerId numeric(9) not null,
CONSTRAINT orgId_pk PRIMARY KEY (orgId),
CONSTRAINT managerId_fk FOREIGN KEY (managerId)
REFERENCES Employee(employeeId)
);
CREATE TABLE EmployeeOrg
(
employeeId numeric(9) not null,
orgId numeric(9) not null,
CONSTRAINT employeeId_orgId_pk PRIMARY KEY (employeeId, orgId),
CONSTRAINT employeeId_fk FOREIGN KEY (employeeId)
REFERENCES Employee(employeeId),
CONSTRAINT orgId_fk FOREIGN KEY (orgId)
REFERENCES Org(orgId)
);
INSERT ALL
INTO Employee (employeeId, name, salary) VALUES (123, 'Jim', 123)
INTO Employee (employeeId, name, salary) VALUES (456, 'Bill', 1456)
INTO Employee (employeeId, name, salary) VALUES (789, 'Frank', 456)
INTO Employee (employeeId, name, salary) VALUES (987, 'Sara', 45668)
INTO Employee (employeeId, name, salary) VALUES (654, 'Liz', 4456)
INTO Employee (employeeId, name, salary) VALUES (321, 'Morgan', 4556)
SELECT * FROM dual;
INSERT ALL
INTO Org (orgId, name, managerId) VALUES (1, 'Sales', 123)
INTO Org (orgId, name, managerId) VALUES (2, 'HR', 789)
INTO Org (orgId, name, managerId) VALUES (3, 'E Suite', 987)
INTO Org (orgId, name, managerId) VALUES (4, 'Marketing', 654)
SELECT * FROM dual;
INSERT ALL
INTO EmployeeOrg (employeeId, orgId) VALUES (123, 1)
INTO EmployeeOrg (employeeId, orgId) VALUES (789, 2)
INTO EmployeeOrg (employeeId, orgId) VALUES (987, 3)
INTO EmployeeOrg (employeeId, orgId) VALUES (654, 4)
INTO EmployeeOrg (employeeId, orgId) VALUES (123, 4)
INTO EmployeeOrg (employeeId, orgId) VALUES (456, 1)
INTO EmployeeOrg (employeeId, orgId) VALUES (321, 2)
INTO EmployeeOrg (employeeId, orgId) VALUES (789, 4)
INTO EmployeeOrg (employeeId, orgId) VALUES (456, 2)
SELECT * FROM dual;
EDIT (from OP's comment)
The below code gets me a list of all the Org Names with the global max salary, but I am looking for the max of each Org. I think I may need to use some joins but I am not very familiar.
SELECT Org.name, MAX(Employee.salary) AS "Highest salary"
From Org, Employee
GROUP BY Org.name
select o.orgId, min(o.name) as orgName, max(e.salary) as maxSalary
from Org o
inner join EmployeeOrg eo on eo.orgId = o.orgId
inner join Employee e on e.employeeId = eo.employeeId
group by o.orgId
order by orgName;
select e.name as empName, o.name as orgName
from Employee e left outer join Org o on o.managerId = e.employeeId
order by empName, orgName;

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;

How to insert multiple rows in Microsoft Access tables?

I have tried every way I can find with Google to insert multiple rows in Access with queries.
None of the these are working for me:
INSERT INTO MyTable (fld02, fld02, fld03)
SELECT '1','2','3'
UNION SELECT '4','5','6'
UNION SELECT '7','8','9'
INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('a','b','Male','January 15, 1955','4202 E Fowler Ave','Tampa','813-974-2268','50000','Computer Engineering');
VALUES ('c','d','Male','October 22, 1948','4202 E Fowler Ave','Tampa','813-974-1538','80000','Computer Engineering');
VALUES ('e','f','Male','May 15, 1933','4202 E Fowler Ave','Tampa','813-974-4425','120000','Computer Engineering');
VALUES ('g','h','Female','December 3, 1960','4202 E Fowler Ave','Tampa','813-974-1276','60000','Computer Engineering');
VALUES ('i','j','Female','November 17, 1962','4202 E Fowler Ave','Tampa','813-974-2154','62000','Computer Engineering');
INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('a','b','Male','January 15, 1955','4202 E Fowler Ave','Tampa','813-974-2268','50000','Computer Engineering');
INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('c','d','Male','October 22, 1948','4202 E Fowler Ave','Tampa','813-974-1538','80000','Computer Engineering');
INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('e','f','Male','May 15, 1933','4202 E Fowler Ave','Tampa','813-974-4425','120000','Computer Engineering');
INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('g','h','Female','December 3, 1960','4202 E Fowler Ave','Tampa','813-974-1276','60000','Computer Engineering');
INSERT INTO faculty1 (first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise)
VALUES ('i','j','Female','November 17, 1962','4202 E Fowler Ave','Tampa','813-974-2154','62000','Computer Engineering');
I even tried a single entry, and didn't work either.
INSERT INTO faculty1 ( first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise )
VALUES ('a', 'b', 'Male', 'January 15, 1955', '4202 E Fowler Ave', 'Tampa', '813-974-2268', '50000', 'Computer Engineering');
Is there something wrong with my CREATE statement?
CREATE TABLE faculty1
(
facultynumber int PRIMARY KEY,
first_name CHAR(20),
last_name CHAR(20),
gender CHAR(10),
birthdate CHAR(25),
address CHAR(50),
city CHAR(20),
phone CHAR(20),
salary INTEGER,
area_of_expertise CHAR(20)
);
http://www.pixhost.org/show/1360/23620036_access_error.jpg
This surprisingly works. Is Access not able to handle you not giving a primary key? I thought this was optional.
http://www.w3schools.com/sql/sql_insert.asp
INSERT INTO faculty1 ( facultynumber, first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise )
VALUES ('5', 'a', 'b', 'Male', 'January 15, 1955', '4202 E Fowler Ave', 'Tampa', '813-974-2268', '50000', 'Computer Engineering');
Salary is defined as an integer but you are trying to insert it with quotes. Also you have to either provide a faculty number or make it identity / counter
INSERT INTO faculty1 (facultynumber, first_name, last_name, gender, birthdate, address, city, phone, salary, area_of_expertise )
VALUES (1, 'a', 'b', 'Male', 'January 15, 1955', '4202 E Fowler Ave', 'Tampa', '813-974-2268', 50000, 'Computer Engineering');
If you want the primary key to be automatically generated, you need to define the column as an Autonumber type.
CREATE TABLE faculty1
(
facultynumber PRIMARY KEY AUTOINCREMENT,
...
More Detail in this thread: https://stackoverflow.com/a/1072938/2712185