问题
I am newbie to sqlserver and i have came across an error which is :
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near ')'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolea
n breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception
, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObj
ect stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,
TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName,
Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSou
rce`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean
asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at KellenTechnology.Program.Main(String[] args) in c:\Users\Mohit\Documents\V
isual Studio 2013\Projects\KellenTechnology\KellenTechnology\Program.cs:line 37
ClientConnectionId:d9ec7a79-87d2-40f9-83f9-dc7b08c05153
And the code for this error cause is the connection string below:
string sqlStatement2 = "CREATE TABLE " + Table2Name + "" +
"(line_id AUTOINCREMENT PRIMARY KEY ," +
"line_full_name CHAR(50) NOT NULL,"+
" network_id INTEGER FOREIGN KEY)";
Could some one please let me know the cause of this problem ? How to fix it ?
回答1:
autoincrement is not a SQL Server keyword. I think you intend:
string sqlStatement2 = "CREATE TABLE " + Table2Name + "" +
"(line_id int not null identity(1, 1) PRIMARY KEY, " +
"line_full_name CHAR(50) NOT NULL," +
" network_id INTEGER FOREIGN KEY REFERENCES network(network_id))";
In addition, FOREIGN KEY requires a table reference.
来源:https://stackoverflow.com/questions/31487453/incorrect-syntax-near-while-creating-table