解析查询时出错。 [令牌行号]创建表时出现sql错误

发布于 2024-11-07 13:12:06 字数 342 浏览 0 评论 0原文

大家好,我正在尝试在 sql Compact 中创建表。

这是查询:

CREATE TABLE [dbo.A] 
(
    Id nvarchar(37) NOT NULL CONSTRAINT Info_PK PRIMARY KEY,
    ImportDate datetime NOT NULL        
);

CREATE TABLE [dbo.B]
(
    Id uniqueidentifier PRIMARY KEY,
        DeviceId smallint,

);

但它在尝试创建表 B 的行中给出了错误。

Hi guys im tryin to create tables in sql compact.

Here is the query:

CREATE TABLE [dbo.A] 
(
    Id nvarchar(37) NOT NULL CONSTRAINT Info_PK PRIMARY KEY,
    ImportDate datetime NOT NULL        
);

CREATE TABLE [dbo.B]
(
    Id uniqueidentifier PRIMARY KEY,
        DeviceId smallint,

);

But it is giving error in the line where it is tryin to create table B.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一人独醉 2024-11-14 13:12:07

我用 google 搜索了这个,听起来您正在使用 SQL CE (为了将来的参考,最好告诉我们您正在使用的 SQL 实现是什么)。

CE 不支持将括号 [] 作为分隔符。尝试从表名中删除它们。

I googled this and it sounds like you are using SQL CE (for future reference it's always good to tell us what implementation of SQL you are using).

Brackets [] are not supported as delimiters in CE. Try removing those from your table names.

转身以后 2024-11-14 13:12:07

尽管具有多个查询的批处理可以在 SQL Server Management Studio 上运行,但它无法与 SqlCeCommand 一起运行。

您必须将批处理拆分为多个查询(您可以使用事务来确保所有查询都执行或不执行)。我建议使用 ExecuteNonQuery 因为它不使用游标(这可能会在事务中出现一些错误)。

您可以使用以下示例。

Using connexion As New SqlCeConnection(connexionstring)
            connexion.Open()
            Dim transaction As SqlCeTransaction = connexion.BeginTransaction()
            Try
                Dim batch As String = GetCommandText()
                For Each query In batch.Split(";")
                    If Not String.IsNullOrWhiteSpace(query) Then
                        Dim command As New SqlCeCommand(query, connexion, transaction)
                        command.ExecuteNonQuery()
                    End If
                Next
                transaction.Commit()
            Catch ex As Exception
                transaction.Rollback()
                Throw
            End Try
        End Using

Despite the fact a batch with multiple query is working on SQL Server Management Studio, it won't work with SqlCeCommand.

You have to split your batch in multiple query (you can use a transaction to be sur all the query are executed or none). I recommand to use ExecuteNonQuery as it doesn't use cursor (which could make some error in a transaction).

You could use the following sample.

Using connexion As New SqlCeConnection(connexionstring)
            connexion.Open()
            Dim transaction As SqlCeTransaction = connexion.BeginTransaction()
            Try
                Dim batch As String = GetCommandText()
                For Each query In batch.Split(";")
                    If Not String.IsNullOrWhiteSpace(query) Then
                        Dim command As New SqlCeCommand(query, connexion, transaction)
                        command.ExecuteNonQuery()
                    End If
                Next
                transaction.Commit()
            Catch ex As Exception
                transaction.Rollback()
                Throw
            End Try
        End Using
爱的故事 2024-11-14 13:12:06

不要使用dbo。 SQL CE 不支持架构。
并且您可能需要单独执行查询。

这是一个类似的问题和解决方案:
http://social. msdn.microsoft.com/Forums/en-US/sqlce/thread/d6f1db96-8724-4376-990e-3f6da18c2d08/

Don't use dbo. Schemas are not supported in SQL CE.
And you may need execute your queries separately.

Here is a similar problem and the solution:
http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/d6f1db96-8724-4376-990e-3f6da18c2d08/

橘虞初梦 2024-11-14 13:12:06

我会删除 DeviceId Smallint 之后的逗号

CREATE TABLE [dbo.A]
( Id nvarchar(37) NOT NULL CONSTRAINT Info_PK PRIMARY KEY,             
ImportDate datetime NOT NULL
);

CREATE TABLE [dbo.B] ( Id uniqueidentifier PRIMARY KEY, DeviceId smallint
);

I would remove the comma after DeviceId smallint

CREATE TABLE [dbo.A]
( Id nvarchar(37) NOT NULL CONSTRAINT Info_PK PRIMARY KEY,             
ImportDate datetime NOT NULL
);

CREATE TABLE [dbo.B] ( Id uniqueidentifier PRIMARY KEY, DeviceId smallint
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文