首页 > 解决方案 > 错误:“无法绑定多部分”

问题描述

我对错误有疑问:“无法绑定多部分”。查了一下并告诉我做我在第一个 Insert INTO Value 中所做的事情,但它给了我一个语法错误。我应该怎么做才能解决这个问题?我在下面留下了代码和图片。

CREATE DATABASE [dbo]. [tCostumes](
[CostumeID] [int],
[Characters] [nchar] (50),
[Price] [int],
[DateNeeded] [nchar] (60)

CREATE SEQUENCE orderNumber
start with 1
increment by 1
minvalue 0
maxvalue 100
cycle;

INSERT INTO tCostume 
VALUES ((CostumeID = orderNumber.nextval), ‘Okabe’, 30, ‘Oct 31 2020’); 



INSERT INTO tCostume 
VALUES (orderNumber.nextval, ‘Batman’, 20, ‘Oct 30 2020’);

INSERT INTO tCostume 
VALUES (orderNumber.nextval, ‘Accelerator’, 75, May 24 2021’);`

一些图像

标签: sqlsql-server

解决方案


为什么不在 ID 列上使用 IDENTITY 规范?您可能还想创建一个表而不是数据库。

CREATE TABLE [dbo]. [tCostumes](
[CostumeID] [int] IDENTITY(1, 1) NOT NULL,
[Characters] [nchar] (50),
[Price] [int],
[DateNeeded] [nchar] (60))

INSERT INTO tCostumes (Characters, Price, DateNeeded)
VALUES ('Okabe', 30, 'Oct 31 2020')

或者,如果您真的想使用序列,这可能会起作用:

INSERT INTO tCostumes (Characters, Price, DateNeeded)
VALUES ((SELECT NEXT VALUE FOR orderNumber), 'Okabe', 30, 'Oct 31 2020'); 

来源:创建序列

编辑:在我编辑答案时,@DavidP 建议使用相同的解决方案来使用该序列并提供完整的代码示例。


推荐阅读