"column not allowed here" error in INSERT statement

john picture john · May 8, 2012 · Viewed 160.9k times · Source

I created this table called LOCATION by doing this:

CREATE TABLE LOCATION(
POSTCODE VARCHAR(10) PRIMARY KEY,
STREET_NAME VARCHAR(20),
CITY VARCHAR(20));

and when I try to add some date within the table it doesn’t work saying there is an error

INSERT INTO LOCATION VALUES(PQ95VM,'HAPPY_STREET','FRANCE');

error is saying

column not allowed here

Answer

skaffman picture skaffman · May 8, 2012

You're missing quotes around the first value, it should be

INSERT INTO LOCATION VALUES('PQ95VM', 'HAPPY_STREET', 'FRANCE');

Incidentally, you'd be well-advised to specify the column names explicitly in the INSERT, for reasons of readability, maintainability and robustness, i.e.

INSERT INTO LOCATION (POSTCODE, STREET_NAME, CITY) VALUES ('PQ95VM', 'HAPPY_STREET', 'FRANCE');