0

Can I use VARCHAR to store this GVC/AK/CR/1/2017/001?

CREATE TABLE clients 
(
    client_id INT AUTO_INCREMENT ,
    name VARCHAR (50),
    phone_no INT (11),
    plan_no VARCHAR (20),
    job_remark VARCHAR (12),
    quater INT,
    year DATE,
    PRIMARY KEY (client_id)
);

INSERT INTO clients (name, phone_no, plan_no, job_remark, quater, year,) 
VALUES (name= 'UAE GEO', phone_no= 07037695328, plan_no= 'GVC/AK/CR/1/2017/001', job_remark= 'revalidation', quater= 1, year= '2017-03-28');

I'm getting an error:

ER_PARSE_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 ') VALUES ('UAE GEO', 07037695328, 'GVC/AK/CR/1/2017/001', 'revalidation', 1, '20' at line 1

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    That's most likely because of the last, unnecessary comma in the `INSERT INTO` clause - after the `year`, just before the closing `)`.... – marc_s Apr 15 '20 at 16:52
  • If You declare your columns you don't need asiggn it again – JsMoreno Apr 15 '20 at 16:55

1 Answers1

0

You have an error in your insert statement. You don't need to provide the column names inside the Values () section. Also you have an extra trailing , in the columns section. The statement below should work:

INSERT INTO clients (name, phone_no, plan_no, job_remark, quater, year) VALUES ( 'UAE GEO',  07037695328, 'GVC/AK/CR/1/2017/001', 'revalidation', 1, '2017-03-28')

EDIT

As the phone number column will throw a Out of range error because of reasons you can find here. You can instead use the phone_no also as a VARCHAR to fix that.

CREATE TABLE clients 
(
    client_id INT AUTO_INCREMENT ,
    name VARCHAR (50),
    phone_no VARCHAR (11),
    plan_no VARCHAR (20),
    job_remark VARCHAR (12),
    quater INT,
    year DATE,
    PRIMARY KEY (client_id)
);

Please read the doc for this MySQL statement