ERROR 1005 (HY000): Can't create table 'project2.fulltime' (errno: 150) - mysql

I know you all have answered this question lots of times. Please help if you have the time. It can't create Full Time table or Part Time table. I am getting an error HY000. Tired to fix it reading through the forms still getting the error. thank you for your time.
DROP DATABASE project2;
CREATE DATABASE project2;
Use project2;
drop table if exists Customer;
drop table if exists Employee;
drop table if exists Orders;
drop table if exists BookOrder;
drop table if exists FullTime;
drop table if exists PartTime;
CREATE TABLE Customer (
CustomerID int PRIMARY KEY ,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL ,
Email varchar(50) NULL
);
Insert Into Customer Values(1,'Jhon','Peterson','3265 4th Street','Los Angeles','CA','5625687854','Jhon.Peterson#yahoo.com');
Insert Into Customer Values(2,'Peter','Paker','9587 Church Ave.','Compton','CA','3235687452','Peter.Paker#marvel.com');
Insert Into Customer Values(3,'Yin','May','2354 Bombardier Ave.','New Rochelle','NY','6088565216','Yin.May#hotmail.com');
Insert Into Customer Values(4,'Erick','Ruiz','1234 Franklin Blvd.','Columbus','OH','9065682561','Erick.Ruiz#gmai.com');
Insert Into Customer Values(5,'Alex','Bastidas','5698 Luders Street','Paris','UK','8985354587','Alex.Bastidas#gmail.com');
CREATE TABLE Employee(
EmployeeID int PRIMARY KEY,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL,
SSN varchar (16) NOT NULL
);
Insert Into Employee Values(32,'Juan','Ortiz','5748 Pine Street','Los Angeles','CA','3232587458','608758955');
Insert Into Employee Values(45,'Mark','Marks','5148 Hatteras','Long Beach','CA','2135487632','405734655');
Insert Into Employee Values(50,'Van','Diesel','4784 Sixth Street','Van Nuys','NC','6058569265','702457822');
Insert Into Employee Values(16,'June','Franks','98456 Home Ave.','Ontario','NJ','5624875632','608159555');
Insert Into Employee Values(22,'Adrianna','Ornals','498756 Bronxs Street','Brooklyn','NY','1234567888','123456789');
CREATE TABLE Orders (
OrderID int PRIMARY KEY ,
CustomerID int (50) NULL ,
EmployeeID int (50) NOT NULL
);
Insert Into Orders Values(10,5,32);
Insert Into Orders Values(14,3,45);
Insert Into Orders Values(11,2,16);
Insert Into Orders Values(13,1,50);
Insert Into Orders Values(12,4,22);
CREATE TABLE BookOrder(
BookID int (50) NOT NULL,
OrderID int (50) NOT NULL ,
OrderQuantity int (50) NOT NULL,
CONSTRAINT BookOrderPK PRIMARY KEY(BookID,OrderID)
);
Insert Into BookOrder Values(1,14,7);
Insert Into BookOrder Values(20,10,10);
Insert Into BookOrder Values(34,11,25);
Insert Into BookOrder Values(11,12,31);
Insert Into BookOrder Values(21,13,25);
CREATE TABLE Book(
BookID int PRIMARY KEY,
StockQuantity int (50) NOT NULL ,
BookTitle varchar (50) NOT NULL ,
BookAuthor varchar (50) NOT NULL,
BookPrice decimal(4,2) NOT NULL
);
Insert Into Book Values(22,10,'Literature', 'Mark Patternson', 60.99);
Insert Into Book Values(64,25,'Calculus', 'Gilbert Strang', 187.99);
Insert Into Book Values(87,30,'Java', 'Daniel Liang', 150.99);
Insert Into Book Values(90,40,'Philosophy', 'Marcus Aurelius', 90.99);
Insert Into Book Values(77,5,'Social Engineering', 'Christopher Hadnagy', 100.99);
CREATE TABLE FullTime(
EmployeeID int PRIMARY KEY,
Salary varchar(50) NOT NULL,
SSN varchar (16) NOT NULL,
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (SSN) REFERENCES Employee(SSN)
);
Insert Into FullTime Values(22,'62,990','123456789');
Insert Into FullTime Values(50,'51,730','702457822');
Insert Into FullTime Values(45,'46,990','405734655');
CREATE TABLE PartTime(
EmployeeID int PRIMARY KEY,
HourlyRate decimal(4,2) NOT NULL,
TotalHours int (40) NOT NULL,
SSN varchar (16) NOT NULL,
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (SSN) REFERENCES Employee(SSN)
);
Insert Into PartTime Values(32,32.00,35,'608758955');
Insert Into PartTime Values(16,40.00,38,'608159555');

You need to make SSN in employee table a unique key, which is one in real life any way, so that it can be referenced as a foreign key:
CREATE TABLE Employee(
EmployeeID int PRIMARY KEY,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL ,
Address varchar (60) NULL ,
City varchar (25) NULL ,
State varchar (15) NULL ,
Phone varchar (16) NULL,
SSN varchar (16) NOT NULL,
unique(SSN)
);

Related

SQL-query error date

why does MySQL give me #1063 - Wrong column specification for column 'Date' error if I want to import this query? What I need to have in that row is Date with format: YYYY/MM/DD. Can someone help me and explain whats wrong and why this is wrong so I can learn :) Thank you!
CREATE TABLE Employee (
Employee_number INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Lastname VARCHAR (255) NOT NULL,
Firstname VARCHAR (255) NOT NULL,
Residence VARCHAR (255) NOT NULL,
Skilllevel TINYINT NOT NULL,
Salary DECIMAL NOT NULL
);
CREATE TABLE Direct_hours (
Date DATE AUTO_INCREMENT PRIMARY KEY,
FOREIGN KEY Employee_number INT NOT NULL REFERENCES Employee (Employee_number),
FOREIGN KEY Project_number INT NOT NULL REFERENCES Project (Project_number)
);
CREATE TABLE Indirect_hours (
Date DATE NOT NULL AUTO_INCREMENT PRIMARY KEY,
FOREIGN KEY Employee_number INT NOT NULL REFERENCES Employee (Employee_number),
Type VARCHAR (255) NOT NULL,
Number INT NOT NULL
);
CREATE TABLE Customer (
Customer_number INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Client_name VARCHAR (255) NOT NULL,
Residence VARCHAR (255) NOT NULL
);
CREATE TABLE Skilllevel (
Levels TINYINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
FOREIGN KEY Employee_number INT NOT NULL REFERENCES Employee (Employee_number),
Description VARCHAR (255) NOT NULL,
Hourly_rate TINYINT NOT NULL
);
CREATE TABLE Project (
Project_number INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
FOREIGN KEY Employee_number INT NOT NULL REFERENCES Employee (Employee_number),
FOREIGN KEY Customer_number INT NOT NULL REFERENCES Customer (Customer_number),
Hourly_rate TINYINT NOT NULL
);

MySQL - Nonsense Syntax Errors

I'm new to programming, and cannot understand the syntax errors that I'm getting.
CREATE SCHEMA IF NOT EXISTS donutsrus;
CREATE TABLE IF NOT EXISTS DONUT (
Donut_ID INT NOT NULL, UNIQUE
Donut_Name VARCHAR (20) NOT NULL, UNIQUE
Description VARCHAR (20) NOT NULL, UNIQUE
Unit_Price NUMERIC (4,2) NOT NULL
PRIMARY KEY (Donut_ID));
CREATE TABLE IF NOT EXISTS SALES_ORDER (
Sales_Order_ID INT NOT NULL, UNIQUE
Sales_Order_Date DATE NOT NULL
Sales_Order_Notes VARCHAR (100)
Customer_ID INT NOT NULL, UNIQUE
PRIMARY KEY (Sales_Order_ID)
FOREIGN KEY (Customer_ID));
CREATE TABLE IF NOT EXISTS CUSTOMER (
Customer_ID INT NOT NULL, UNIQUE
Last_Name VARCHAR (20) NOT NULL
First_Name VARCHAR (20) NOT NULL
Address VARCHAR (50) NOT NULL
Apt VARCHAR (5)
City VARCHAR (20) NOT NULL
State CHAR (2) NOT NULL
Zip NUMBER (5) NOT NULL
Home_Phone NUMBER (10)
Mobile_Phone NUMBER (10)
Other_Phone NUMBER (10)
PRIMARY KEY (Customer_ID));
CREATE TABLE IF NOT EXISTS ORDER_LINE_ITEM (
Donut_ID INT NOT NULL, UNIQUE
Sales_Order_ID INT NOT NULL, UNIQUE
Quantity INT NOT NULL
PRIMARY KEY (Donut_ID, Sales_Order_ID)
FOREIGN KEY (Donut_ID, Sales_Order_ID));
On the Donut table, I get Syntax error: extraneous input found - expected 'opening parenthesis', at the VARCHAR after Donut_Name. At the closing paren after the succeeding 20, I get Syntax error: extraneous input found - expected 'closing parenthesis'.
On the Order Line Item table I get, Syntax Error: 'INT' (int) is not valid input at this position, after the Sales_Order_ID. I also don't understand why it's okay on other lines of code, but not this one.
All the commas before UNIQUE are wrong. Commas are used to separate the columns, not to separate options for a specific column.
CREATE TABLE IF NOT EXISTS DONUT (
Donut_ID INT NOT NULL UNIQUE,
Donut_Name VARCHAR (20) NOT NULL UNIQUE,
Description VARCHAR (20) NOT NULL UNIQUE,
Unit_Price NUMERIC (4,2) NOT NULL,
PRIMARY KEY (Donut_ID));
CREATE TABLE IF NOT EXISTS CUSTOMER (
Customer_ID INT NOT NULL UNIQUE,
Last_Name VARCHAR (20) NOT NULL,
First_Name VARCHAR (20) NOT NULL,
Address VARCHAR (50) NOT NULL,
Apt VARCHAR (5),
City VARCHAR (20) NOT NULL,
State CHAR (2) NOT NULL,
Zip NUMBER (5) NOT NULL,
Home_Phone NUMBER (10),
Mobile_Phone NUMBER (10),
Other_Phone NUMBER (10),
PRIMARY KEY (Customer_ID));
CREATE TABLE IF NOT EXISTS SALES_ORDER (
Sales_Order_ID INT NOT NULL UNIQUE,
Sales_Order_Date DATE NOT NULL,
Sales_Order_Notes VARCHAR (100),
Customer_ID INT NOT NULL,
PRIMARY KEY (Sales_Order_ID),
FOREIGN KEY (Customer_ID) REFERENCES CUSTOMER (Customer_ID));
CREATE TABLE IF NOT EXISTS ORDER_LINE_ITEM (
Donut_ID INT NOT NULL,
Sales_Order_ID INT NOT NULL,
Quantity INT NOT NULL,
PRIMARY KEY (Donut_ID, Sales_Order_ID),
FOREIGN KEY (Donut_ID) REFERENCES DONUT (Donut_ID),
FOREIGN KEY (Sales_Order_ID) REFERENCES SALES_ORDER (Sales_Order_ID));
BTW, the UNIQUE option is not necessary for primary keys, they're automatically made unique. And in ORDER_LINE_ITEM, if the primary key is (Donut_ID, Sales_Order_ID) you probably don't want to make each of those columns unique by themselves. This prevents the same donut from being in multiple orders, or an order having more than one donut type. Similarly, Customer_ID should not be unique in SALES_ORDER; a customer can obviously have more than one order.
Your FOREIGN KEY lines were missing the references of the foreign keys. And the tables with the foreign keys need to be created after the tables they reference, so I moved SALES_ORDER down to after CUSTOMER.

Getting errors with my SQL database

I'm having trouble getting my SQL table to work. It keeps giving me an error that it cannot drop tables due to not permission or not exisiting. And it's telling me that there's an invalid table as well.
I currently have:
drop table Orders
drop table Item
drop table Supplier
drop table Staff
drop table Customers
drop table Ingredient
CREATE TABLE Supplier(
SupplierNo CHAR(7) PRIMARY KEY,
SupplierName CHAR(25),
SupplierAddress VARCHAR(25),
SupplierPhone CHAR(10),
SupplierContactPerson CHAR (35)
)
go
CREATE TABLE Item (
ItemNo CHAR(7) PRIMARY KEY,
ItemName CHAR(10),
ItemType CHAR(10),
Price DEC(3,2),
IngredientCode CHAR (5),
FOREIGN KEY(IngredientCode) REFERENCES Ingredient(IngredientCode)
)
go
CREATE TABLE Staff (
EmployeeID CHAR(3) PRIMARY KEY,
FirstName CHAR(10),
LastName CHAR(10),
PostalAddress VARCHAR(MAX),
ContactNumber CHAR (10),
RateOfPay MONEY,
EmployementStatus CHAR(25)
)
CREATE TABLE Customers (
CustomerID CHAR(4) PRIMARY KEY,
CustomerFN CHAR(25),
CustomerLN CHAR(25),
CustomerPhN CHAR(11),
CAddress VARCHAR (25)
)
go
CREATE TABLE Ingredient(
IngredientCode CHAR (5) PRIMARY KEY,
IngredientName CHAR(25),
IngredientDesc VARCHAR(max),
CurrentStockLevel CHAR(3),
PreviousStockLevel CHAR(3),
SuggestedStockLevel CHAR(3),
SupplierNo CHAR(7),
Supplied DATE(),
FOREIGN KEY(SupplierNo) REFERENCES Supplier(SupplierNo)
)
CREATE TABLE Orders(
OrderNo CHAR(7),
OrderDate DATE(),
CustomerNo CHAR(4) FOREIGN KEY,
EmployeeID CHAR(3) FOREIGN KEY,
ItemNo CHAR(7) FOREIGN KEY,
TypeOfOrder CHAR(10),
TotalAmount MONEY(),
PaymentMethod CHAR(10),
OrderStatus CHAR(10)
FOREIGN KEY CustomerNo, EmployeeID, ItemNo
REFERENCES Customer(CustomerNo), Staff(EmployeeID), Item(ItemNo)
)
It seems like a very simple problem to have, but I'm not even sure what it means with me having no permission or the table not existing at all...
You create constraint, before create table Ingredient
FOREIGN KEY(IngredientCode) REFERENCES Ingredient(IngredientCode)

data truncation error and int data types

CREATE TABLE Customer (
customerid varchar(10) NOT NULL,
FirstName varchar(20) NOT NULL,
LastName varchar(20) NOT NULL,
StreetAddress varchar (30) NOT NULL,
City varchar (20)NOT NULL,
State varchar (20) NOT NULL,
Zip int(5) NOT NULL,
Hphone int (10) NOT NULL,
Mphone int (10) NOT NULL,
Ophone int (10) NOT NULL,
PRIMARY KEY (customerid));
CREATE TABLE OrderTable (
donutorderid varchar(10) NOT NULL,
customerid varchar (10) NOT NULL,
oderdate datetime (6) NOT NULL,
PRIMARY KEY (donutorderid)
);
CREATE TABLE Donut (
donutid varchar(10),
donutname varchar(20),
description varchar(30),
unitprice numeric,
PRIMARY KEY (donutid)
);
CREATE TABLE OrderLine (
donutorderid varchar (30),
donutid varchar (30),
qty int (10),
PRIMARY KEY (donutorderid,donutid)
);
ALTER TABLE OrderTable ADD INDEX checks (customerid),
ADD CONSTRAINT checks FOREIGN KEY (customerid) REFERENCES Customer (customerid);
ALTER TABLE OrderLine ADD INDEX has (donutorderid),
ADD CONSTRAINT has FOREIGN KEY (donutorderid) REFERENCES OrderTable (donutorderid);
ALTER TABLE OrderLine ADD INDEX available_in (donutid),
ADD CONSTRAINT available_in FOREIGN KEY (donutid) REFERENCES Donut (donutid);
create view CustInfo
AS Select customerid, concat(FirstName,LastName) as FullName from customer;
insert into customer
(customerid, FirstName, LastName, StreetAddress,
City, State, Zip, Hphone, Mphone, Ophone)
values ('123','John','Doe', 'one hoover lane', 'las vegas',
'nevada', 89104, 702555122, 702441111, 702332222);
Data truncation: Out of range value for column 'Hphone' at row 1
When I have 9 digits in my telephone e.g. 702551212 vs 7025551212 it works and Hphone, Mphone, Ophone all have int (10).
You have declared your phone numbers to be integers. That is a very, very bad idea. Declare them to be strings:
CREATE TABLE Customer (
customerid varchar(10) NOT NULL,
FirstName varchar(20) NOT NULL,
LastName varchar(20) NOT NULL,
StreetAddress varchar (30) NOT NULL,
City varchar (20)NOT NULL,
State varchar (20) NOT NULL,
Zip char(5) NOT NULL,
Hphone varchar(32) NOT NULL,
Mphone varchar(32) NOT NULL,
Ophone varchar(32) NOT NULL,
PRIMARY KEY (customerid)
);
It is unclear to me why the phone numbers -- and other columns -- are declared NOT NULL. Not everyone has three phone numbers. In fact, some people have fewer and some more, suggesting that the phone numbers should really be in a separate table.
I also made the zip code a string. After all, leading zeros are very important for zip codes.
But, for your immediate problem, then use single quotes to put the numbers in as strings:
insert into customer(customerid, FirstName, LastName, StreetAddress,
City, State, Zip, Hphone, Mphone, Ophone)
values ('123','John','Doe', 'one hoover lane', 'las vegas',
'nevada', '89104', '702555122', '702441111', '702332222');

Having trouble in Online Movie ticketing database design

#J2D8T i have done few changes in my code please tell if its correct also is it properly normalized? thanks in advance.
use [fadi1]
create table Customer (
Cnic varchar (17) primary key not null,
name varchar (30) not null,
Cpassword varchar (30) not null,
email varchar (40) ,
contactno varchar (15) ,
city varchar (30)
);
create table Adimn (
Anic varchar (17) primary key not null,
name varchar (30) not null,
Cpassword varchar (30) not null,
email varchar (40) ,
contactno varchar (15) ,
city varchar (30)
);
create table Movie (
M_id int primary key not null,
name varchar(25) not null,
Mdescription varchar(500) not null,
imagename varchar (100) not null,
Actors varchar (100) not null,
);
create table Venue(
V_id int primary key not null,
V_Name varchar(25) not null,
Maxcapacity int not null,
);
create table Shows (
showid int primary key IDENTITY(1,1) not null,
V_id int not null,
M_id int not null ,
date_time datetime not null unique,
remaining_tickets int not null,
foreign key (v_id) references Venue(v_id),
foreign key (M_id) references Movie(M_id),
);
create table Tickets(
showid int not null,
Seat_no int not null, -- (maxcap-remaining tickets)+1 from capacity table of given pk of that table
T_id int primary key IDENTITY(1,1) not null, --(p.k)
price int not null,
foreign key (showid) references Shows(showid)
);
create table Booking (
showid int not null,
T_id int not null unique,
Cnic varchar(17) not null,
booking_time datetime not null,
foreign key (showid) references Shows(showid),
foreign key (T_id) references Tickets(T_id),
foreign key (Cnic) references Customer(Cnic),
constraint pk_IDBooking primary key(T_id,showid),
);
please inform me as soon as possible because i am not quite far from the deadline :D
At a minimum, there is no password data type in SQL Server. Since you have provided no details about how you're storing data, I converted it to varchar(50).
SQLFiddle
create table Customer (
Cnic varchar (17) primary key not null,
name varchar (30) not null,
Cpassword varchar(50) not null,
email varchar (40) ,
contactno varchar (15) ,
city varchar (30) ,
)
create table Adimn (
Anic varchar (17) primary key not null,
name varchar (30) not null,
Cpassword varchar(50) not null,
email varchar (40) ,
contactno varchar (15) ,
city varchar (30) ,
)
create table Movie (
M_id int not null,
name varchar(25) not null,
Mdescription varchar(500) not null,
imagename varchar (100) not null,
primary key (M_id)
);
create table Actors(
actor_id varchar(25) primary key not null ,
actor varchar(30)not null,
M_id int not null,
Act_role varchar (10)not null,
amountspent int ,
foreign key (M_id) REFERENCES Movie(M_id)
);
create table Venue(
V_id int primary key not null,
M_id int not null,--F.k
V_Name varchar(25)not null
);
create table Capacity(
M_id int not null,
v_id int not null,
date_time varchar (15) not null,
remaining_tickets int not null,
max_capacity int not null,
primary key (M_id, v_id ,date_time )
);
create table Booking (
v_id int not null, --key
T_id int not null,
M_id int not null,--key
Cnic varchar(30) primary key not null,--(p.k))
date_time varchar (15) not null, -- (f.k )
);
create table Tickets(
Seat_no int primary key not null, -- (p.k))
T_id int not null,
M_id int not null, --(f.k)
price int not null,
);
I edited the answer to include only the code with some comments hope this solves your problem.
Edit from your original post:
create table Customer (
Cnic varchar (17) primary key not null,
name varchar (30) not null,
Cpassword password not null,
email varchar (40) ,
contactno varchar (15) ,
city varchar (30)
);
create table Adimn (
Anic varchar (17) primary key not null,
name varchar (30) not null,
Cpassword varchar (30) not null, // changed to varchar
email varchar (40) ,
contactno varchar (15) ,
city varchar (30)
);
create table Movie (
M_id int primary key not null,
name varchar(25) not null,
Mdescription varchar(500) not null,
imagename varchar (100) not null
);
create table Actors(
actor_id varchar(25) primary key not null ,
actor varchar(30)not null,
M_id int not null,
Act_role varchar (10)not null,
amountspent int ,
foreign key (M_id) REFERENCES Movie(M_id)
);
create table Venue(
V_id int primary key not null,
M_id int not null,--F.k
V_Name varchar(25) not null,
foreign key (M_id) references Movie(M_id)
);
create table Capacity(
v_id int not null, // FK
M_id int not null unique, //FK
date_time varchar (15) not null unique,
remaining_tickets int not null,
max_capacity int not null,
foreign key (v_id) references Venue(v_id),
foreign key (M_id) references Movie(M_id),
constraint pk_IDCapacity PRIMARY KEY (M_id,v_id,date_time) // this will create composite key
);
create table Tickets(
Seat_no int primary key not null, -- (p.k))
T_id int not null,
M_id int not null, --(f.k)
price int not null,
foreign key (M_id) references Capacity(M_id)
);
create table Booking (
v_id int not null, //FK
T_id int not null, //FK
M_id int not null,//FK
Cnic varchar(30) primary key not null // Will this stil be neccessary
date_time varchar (15) not null, //FK
foreign key (v_id) references Venue(v_id),
foreign key (M_id) references Movie(M_id),
foreign key (date_time) references Capacity(date_time),
foreign key (T_id) references Tickets(T_id),
constraint pk_IDBooking primary key(v_id,M_id,T_id,date_time) //Can be in any order the PK's
);
Could probably be more compacted with normalization but it should work based on the code you have provided.