Question

create table S (SNO text, SNAME text, STATUS number, CITY text)
insert into S values('S1','Smith','20','London')
insert into S values('S2','Jones','10','Paris')
insert into S values('S3','Blake','30','Paris')
insert into S values('S4','Clark','20','London')
insert into S values('S5','Adams','30','Athens')

Im having a hard time figuring out why this is not a valid SQL query, I have tried googling for answers but to no avail.

I have tried to query an Sqlite database with JDBC and i have also tried inserting it into phpMyAdmins query field. This is the error message presented by phpMyAdmin,

#1064 - 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 'number, CITY text) insert into S values('S1','Smith','20','London') insert int' at line 1

Was it helpful?

Solution

CREATE TABLE `S` (`SNO` TEXT, `SNAME` TEXT, `STATUS` INT, `CITY` TEXT);

START TRANSACTION;

BEGIN;
INSERT INTO `S` VALUES ('S1', 'Smith', 20, 'London');
INSERT INTO `S` VALUES ('S2', 'Jones', 10, 'Paris');
INSERT INTO `S` VALUES ('S3', 'Blake', 30, 'Paris');
INSERT INTO `S` VALUES ('S4', 'Clark', 20, 'London');
INSERT INTO `S` VALUES ('S5', 'Adams', 30, 'Athens');
COMMIT;

Try this one out.

Edits:

  • Changed number to INT
  • Added semicolons (As Gabe mentioned)
  • Added backticks around the table and column names
  • Added Transaction (Speeds up INSERT queries, optional)
  • Removed quotes around the numbers (As christiandev mentioned)

OTHER TIPS

The type you were looking for may be NUMERIC rather than NUMBER. Also, you need to put a semicolon ; between statements in MySQL.

You don't need quotes around the number

create table S (SNO text, SNAME text, STATUS number, CITY text)
insert into S values('S1','Smith',20,'London')

EDIT: From my fiddle

CREATE TABLE s
    (
      SNO VARCHAR(35) ,
      SNAME VARCHAR(35) ,
      STATUS INT ,
      CITY VARCHAR(35)
    ) ;
INSERT  INTO s
VALUES  ( 'S1', 'Smith', 20, 'London' ) ;
INSERT  INTO s
VALUES  ( 'S2', 'Jones', 10, 'Paris' )

SELECT  *
FROM    s

Also, should number be one of these types?

STATUS is reserved:

http://dev.mysql.com/doc/refman/5.1/de/show-table-status.html

Use

 create table S (SNO text, SNAME text, `STATUS` int, CITY text)

instead

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top