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));
Answers:
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.
Method 1
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) );
number
is not a datatype inMySQL
- When you assign
auto_increment
it should benot 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 , sovarchar
would be better
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0