Search code examples
c#sqlsql-server-ce

C#/SQLCE CREATE TABLE programmatically (Auto increment + Primary key)


I am trying to create a table in a SQL CE database programmatically. Currently, I am using the following query - though I am getting an error;

string command = @"CREATE TABLE CONNECTION(" +
                  "connection_id INTEGER IDENTITY(1,1) PRIMARY KEY, " +
                  "host NVARCHAR(255), port INT, key NVARCHAR(50), " +
                  "last_used NVARCHAR(15));";

The error I am getting is:

There was an error parsing the query. [ Token line number = 1, Token line offset = 104, Token in error = key ]

I can't seem to figure out what I am doing wrong. I am used to MySQL and the queries are slightly different.


Solution

  • try enclosing key in a brackets

    string command = @"CREATE TABLE CONNECTION(" +
                            "connection_id INTEGER IDENTITY(1,1) PRIMARY KEY, " +
                            "host NVARCHAR(255), port INT, [key] NVARCHAR(50), " +
                            "last_used NVARCHAR(15));";