-1

In my Navicat Premium:

I run the below code in Query Editor:

CREATE TABLE employee(
    id INT AUTO_INCREMENT PRIMARY KEY,
    empName VARCAHR(20),
    deptName VARCAHR(20)  
);

But I get the error:

Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AUTO_INCREASE PRIMARY KEY, empName VARCAHR(20), deptName VARCAHR(20)
)' at line 2

enter image description here

lme
  • 59
  • 3
  • 17

3 Answers3

0

use this:

CREATE TABLE employee (
    id INT(11) unsigned NOT NULL AUTO_INCREMENT,
    empName VARCHAR(20),
    deptName VARCHAR(20),
    PRIMARY KEY (id)
);
Bernd Buffen
  • 14,525
  • 2
  • 24
  • 39
0

You have syntax error cause it is AUTO_INCREMENT not AUTO_INCREASE Change this:

CREATE TABLE employee(
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    empName VARCHAR(20),
    deptName VARCHAR(20)  
);

You can also create table and involve primary key second way

CREATE TABLE employee(
    id INT NOT NULL AUTO_INCREMENT ,
    empName VARCHAR(20),
    deptName VARCHAR(20),PRIMARY KEY(id)
);
aircraft
  • 25,146
  • 28
  • 91
  • 166
denny
  • 2,084
  • 2
  • 15
  • 19
0

Try this

CREATE TABLE MyStudents
(
   id    INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
   name  VARCHAR(30) NOT NULL,
   email VARCHAR(50)
);
Joe McMahon
  • 3,266
  • 21
  • 33
v6661
  • 1
  • Please explain why you think using `UNSIGNED` is better. Why is your tablename `MyStudents`? Why should `name` be `NOT NULL`? And can you format your SQL in a codeblock, please? – Scratte Apr 20 '20 at 15:58