')' 附近的语法不正确.创建表时 [英] Incorrect syntax near ')'. while creating table

查看:24
本文介绍了')' 附近的语法不正确.创建表时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 sqlserver 的新手,我遇到了一个错误:

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 ?

推荐答案

autoincrement 不是 SQL Server 关键字.我认为您打算:

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))";

此外,FOREIGN KEY 需要一个表引用.

In addition, FOREIGN KEY requires a table reference.

这篇关于')' 附近的语法不正确.创建表时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆