Hello I am new to MySQL and having trouble creating a table. It says that the types im using are not valid at their position with ‘)’.
Can someone tell me what is wrong with this code snippet?
create table CUSTOMER( CustomerID int AUTO_INCREMENT, LastName varchar, FirstName varchar, Address varchar, City varchar, State varchar, ZIP number, Phone number, EmailAddress varchar, constraint pk_cID primary key(CustomerID));
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Your table should look like:
create table CUSTOMER( CustomerID int not null AUTO_INCREMENT, LastName varchar(100), FirstName varchar(100), Address varchar(100), City varchar(100), State varchar(100), ZIP int, Phone varchar(50), EmailAddress varchar(100), primary key(CustomerID) );
numberis not a datatype in
- When you assign
auto_incrementit should be
not null auto_increment
- You don’t need a constraint for primary key, just add primary key.
- I don’t think the best way of storing Phone numbers is
int, you might have different formatting the best way is to treat numbers as addresses , so
varcharwould be better