0

HELP PLS: Qu CREATE TABLE SQL

Hi, I'm not sure why one query worked and the other doesn't. [Works] CREATE TABLE test ( id INTEGER PRIMARY KEY, a INTEGER, b TEXT ); INSERT INTO test ( a,b ) VALUES ( 10, 'a'); INSERT INTO test ( a,b ) VALUES ( 11, 'b'); INSERT INTO test ( a,b ) VALUES ( 12, 'c'); SELECT * FROM test; [Doesn't work=says "Columns don't exist] CREATE TABLE test ( id INTEGER PRIMARY KEY, a TEXT, b INTEGER ); INSERT INTO test ( a,b ) VALUES ( a, '11'); INSERT INTO test ( a,b ) VALUES ( b, '12'); INSERT INTO test ( a,b ) VALUES ( c, '13'); SELECT * FROM test; ---------------------------------- The schema is swapped around, but other than that I would have thought that both queries would have generated the table just with the values swapped around. Can someone please explain what I am missing? TIA

20th Feb 2017, 4:55 AM
DeeLite2072
DeeLite2072 - avatar
2 odpowiedzi
+ 1
I am not sure if there is s typo in your second schema, but what i see is that: a is a column for text and b is a column for integer meaning number. But you are trying to insert string number into b, and the values a,b,c are supposed to be enclosed with ' ' because they are supposed to be strings. Probably the system afterwards could not find the correct column to slot them in, thus creating an error
20th Feb 2017, 4:59 AM
Deddy Tandean
0
Thank you!...I'll have to get my head around 'strings'. It worked... :)
20th Feb 2017, 5:06 AM
DeeLite2072
DeeLite2072 - avatar