1

So I wrote up some SQL statements and as I went to test them I was greeted with the following error. Why is it rejecting this?

CREATE TABLE Student 
(stud_id INT unsigned NOT NULL, 
stud_name VARCHAR NOT NULL, 
stud_phone INT(10) unsigned NOT NULL, 
stud_date_of_birth DATE NOT NULL,
stud_city VARCHAR NOT NULL,
stud_address VARCHAR NOT NULL,
stud_postcode INT(4) unsigned NOT NULL,
PRIMARY KEY (stud_id, stud_phone)
);

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL, stud_phone INT(10) unsigned NOT NULL, stud_date_of_birth DATE NOT ' at line 3

Francisco
  • 10,918
  • 6
  • 34
  • 45
Joshua Nguyen
  • 153
  • 1
  • 8
  • 2
    You need to add a length to the each of the `VARCHAR` column definitions, like `VARCHAR(256)`. – Michael Berkowski Sep 21 '17 at 23:30
  • INT may not be the best choice for a telephone number. See also https://stackoverflow.com/questions/24353778/which-is-best-data-type-for-phone-number-in-mysql-and-what-should-java-type-mapp – Michael Berkowski Sep 21 '17 at 23:32

1 Answers1

2

You have to specify the length to the VARCHAR datatype like VARCHAR(100). This is the only thing with your query.

Your modified query looks like as below.

CREATE TABLE Student 
(stud_id INT unsigned NOT NULL, 
stud_name VARCHAR(100) NOT NULL, 
stud_phone INT(10) unsigned NOT NULL, 
stud_date_of_birth DATE NOT NULL,
stud_city VARCHAR(100) NOT NULL,
stud_address VARCHAR(100) NOT NULL,
stud_postcode INT(4) unsigned NOT NULL,
PRIMARY KEY (stud_id, stud_phone)
);

After correction this if the error still showing in you phpMyadmin then you have to remove Delimiter from the Delimiter textbox in your phpmyadmin place at the bottom of you query filed.

enter image description here

Jino Shaji
  • 1,097
  • 14
  • 27