Codeninja
Codeninja

Reputation: 322

What cause SQL syntax error in creating table in database

When creating a table in mysql query I get the error as below.

ERROR 1064 (42000): 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 'String,
last_name String,
email_address String
)' at line 4

I could not understand what is causing this error. The query is as below.

CREATE TABLE employees
(
id long,
first_name String,
last_name String,
email_address String
);

Upvotes: 0

Views: 59

Answers (3)

Anuresh Verma
Anuresh Verma

Reputation: 1058

As much as i know there is no DataType String in Sql Use varchar

See this for More https://www.journaldev.com/16774/sql-data-types

Upvotes: 1

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522396

You appear to be using Java types in your create table statement. Try using proper MySQL types and it should work:

CREATE TABLE employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(55) NOT NULL,
    last_name VARCHAR(55) NOT NULL,
    email_address VARCHAR(255) NOT NULL
);

Upvotes: 2

Syco
Syco

Reputation: 821

String is not a mysql keyword. you need to use varchar, or char, or text, or longtext... depending on your needs.

Here's how it could look:

CREATE TABLE employees
(
id long,
first_name varchar(32),
last_name varchar(32),
email_address varchar(32)
);

Upvotes: 1

Related Questions