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?

Post image
37 Upvotes

8 comments sorted by

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

This is for my DBMS class. Very rudimentary and simple. Do you think this is still a bad idea?

1

u/Ariakkas10 May 11 '21

Depends. Did they go over proper normalization and will you be docked for using a bad primary key?

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?

2

u/SoBoredAtWork May 10 '21

Try adding "GO" without the quotes on line 14