sql - 错误:“无法绑定多部分”
问题描述
我对错误有疑问:“无法绑定多部分”。查了一下并告诉我做我在第一个 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’);`
解决方案
为什么不在 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 建议使用相同的解决方案来使用该序列并提供完整的代码示例。
推荐阅读
- java - 后缀的中缀,没有循环内的循环
- sql-server - Minikube Pod 连接到外部数据库
- flutter - 通过 Navigator Flutter 传递 BlocProvider
- java - 我不知道为什么它会为另一个数组抛出异常?
- javascript - 降低 if elseif 条件的复杂性
- c# - 如何最好地处理访问同一个互斥锁的多个任务?
- apache-kafka-streams - KStreams:使用处理器 API 实现会话窗口
- spring-boot - Spring Boot 与 mysql workbecnch 的连接
- python - 如何在 Python 中更改此心形图案?
- node.js - 如何使用 React.js 和 Node.js 仅将所需资源加载到客户端浏览器