# MySQL HELP :(



## Mark7805 (Dec 2, 2017)

Hey all!

So I'm working on an assignment and I'm getting an error when I try and load my .SQL file.

https://pastebin.com/4GajJ9MT  <--- here is my code blocks

I get the error l_id doesn't exist when I have it in the limo table.

I'm a real scrub when it comes to this. Please help me **

*Edit:* Fixed qualify and rental up a little by adding q_ to the foreign keys and r_ to the rental foreign keys. Now I'm getting error "Cannot add foreign key constraint"  regarding the rental table create.


----------



## phanbuey (Dec 2, 2017)

the constraint command syntax looks weird to me... (I work mostly with T-SQL but with a google this is what came up for mySQL):

CREATE TABLE Persons (
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (ID)
);

also I usually don't declare width on PKs just leave is as int


----------



## Mindweaver (Dec 2, 2017)

phanbuey said:


> the constraint command syntax looks weird to me... (I work mostly with T-SQL but with a google this is what came up for mySQL):
> 
> CREATE TABLE Persons (
> ID int NOT NULL,
> ...



Yea, I never declare width on PKs or int's in general as well. The biggest issue I seen was not setting the pk to NOT NULL, but I see you fixed that for him in your code.

I would write it like this if I wanted to use the constraint. I would add the constraint after the PK.

```
CREATE TABLE limo (
l_id INT,
l_callsign VARCHAR(15),
l_type VARCHAR(300),
PRIMARY KEY(l_id),
CONSTRAINT limo_l_id_PK
);
```

or create table without the constraint using your code then ALTER the table

```
ALTER TABLE limo
ADD CONSTRAINT limo_l_id_PK;
```


----------

