Richard Nagle wrote:
fastmac:/applications/sqlite rn$ ./sqlite contacts SQLite version 2.8.13 Enter ".help" for instructions sqlite> Create Table Company ( ...> Company Name Character (50) NOT NULL, ...> Contact Name Character (35), ...> Address1 Character (30), ...> Address2 Character (30), ...> City Character (30), ...> State Character (2), ...> Zip Character (10), ...> Phone1 Character (13), ...> Phone2 Character (13), ...> Fax Character (13) ) ; SQL error: near ".": syntax error sqlite>
It would appear, the sqlite does not follow the sql rules of syntax ? or is there something I'm doing wrong?
TKS - Rick
Richard,
Your statement doesn't generate the same syntax error in newer versions of SQLite, so you should probably upgrade.
However it doesn't do what you want either. You need to quote the column names that contain spaces. The table_info pragma will show you the column names of a table. As you can see, your Company Name and Contact Name columns are not being created as you expect.
SQLite version 3.1.1beta
Enter ".help" for instructions
sqlite> Create Table Company (
...> Company Name Character (50) NOT NULL,
...> Contact Name Character (35),
...> Address1 Character (30),
...> Address2 Character (30),
...> City Character (30),
...> State Character (2),
...> Zip Character (10),
...> Phone1 Character (13),
...> Phone2 Character (13),
...> Fax Character (13) ) ;
sqlite> pragma table_info('Company');
cid name type notnull dflt_value pk
---------- ---------- ----------------- ---------- ---------- ----------
0 Company NameCharacter(50) 99 0
1 Contact NameCharacter(35) 0 0
2 Address1 Character(30) 0 0
3 Address2 Character(30) 0 0
4 City Character(30) 0 0
5 State Character(2) 0 0
6 Zip Character(10) 0 0
7 Phone1 Character(13) 0 0
8 Phone2 Character(13) 0 0
9 Fax Character(13) 0 0
sqlite>
The correct way to define these columns is with double quotes as shown below.
sqlite> Create Table Company ( ...> "Company Name" Character (50) NOT NULL, ...> "Contact Name" Character (35), ...> Address1 Character (30), ...> Address2 Character (30), ...> City Character (30), ...> State Character (2), ...> Zip Character (10), ...> Phone1 Character (13), ...> Phone2 Character (13), ...> Fax Character (13) ) ; sqlite> pragma table_info('Company'); cid name type notnull dflt_value pk ---------- ------------ ------------- ---------- ---------- ---------- 0 Company Name Character(50) 99 0 1 Contact Name Character(35) 0 0 2 Address1 Character(30) 0 0 3 Address2 Character(30) 0 0 4 City Character(30) 0 0 5 State Character(2) 0 0 6 Zip Character(10) 0 0 7 Phone1 Character(13) 0 0 8 Phone2 Character(13) 0 0 9 Fax Character(13) 0 0 sqlite>
HTH Dennis Cote