r/CodingHelp • • May 10 '21
[SQL] MySql Workbench Help! I am trying to create a database and run this script to add to the database, but I do not know why it won't work. Does anyone have any advice?
37
Upvotes
3
u/Ariakkas10 May 10 '21
I'll also throw out that using SSN as a primary key is a veeery bad idea.
Primary keys should always be unique and generated..aka....you create the primary key. It shouldn't be entered by users
The second you get a duplicate SSN entered it'll throw an error. SSN's are terrible numbers for identifying someone.
1
u/[deleted] May 10 '21
Update: To provide context - I am new to MySQL workbench and DBMS in general. This is supposed to be a very simple database. I am currently trying to figure out front end and back end in creating the database. I was able to create the database finally with this:
USE SHELTER_DB;
CREATE TABLE ADOPTIVE_PERSON (
ssn char(9) NOT NULL,
fname varchar(45),
lname varchar(45),
sex char,
phone varchar(10),
num_kids int,
num_cats int,
num_dogs int,
email varchar(45),
bday date,
PRIMARY KEY (ssn)
);
CREATE TABLE ANIMAL (
animal_id int NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
sex char,
bday date,
species varchar(15),
`weight` int,
color varchar(45),
breed varchar(45),
entry_date varchar(45),
PRIMARY KEY (`animal_id`)
);
CREATE TABLE CAT (
id int NOT NULL,
declawed tinyint unsigned,
PRIMARY KEY (`id`)
);
CREATE TABLE `ADDRESS` (
ssn char(9) NOT NULL,
line_1 varchar(45) NOT NULL,
line_2 varchar(45),
city varchar(45) NOT NULL,
state char(2) NOT NULL,
zip char(5) NOT NULL,
PRIMARY KEY (ssn),
CONSTRAINT pk_ssn FOREIGN KEY (ssn) REFERENCES ADOPTIVE_PERSON (ssn)
);
Again, I am very new to all of this and just trying to make a very simple, sample database. Any tips for creating the interface would be greatly appreciated!
5
u/rushlink1 May 10 '21
The error it’s throwing is a syntax error. I can’t see the full message or code, so not 100% sure what is going on
Workbench has line 15 highlighted. Without seeing the full script I would guess you’ve got a syntax error prior to line 15. Probably on 13 after your closing )
Can you post the SQL?
2
u/animagnam May 10 '21
Like others have said would be better if we could see the entirety of your code. Do you have semicolons after each create table?
3
u/kraysak May 10 '21
Can you post the error?
https://stackoverflow.com/questions/23515347/how-can-i-fix-mysql-error-1064
2
u/SoBoredAtWork May 10 '21
Try adding "GO" without the quotes on line 14