gpt4 book ai didi

带约束的 Mysql 查询出现错误

转载 作者:行者123 更新时间:2023-11-29 12:11:56 24 4
gpt4 key购买 nike

我尝试将 MSSQL 查询转换为 MySQL,但是,由于我缺乏经验,我在这里遇到了麻烦。

查询如下

CREATE TABLE Appointments (
`UniqueID` int AUTO_INCREMENT NOT NULL ,
`Type` int NULL ,
`StartDate` Datetime NULL ,
`EndDate` Datetime NULL ,
`AllDay` Tinyint NULL ,
`Subject` nvarchar (50) NULL ,
`Location` nvarchar (50) NULL ,
`Description` Longtext NULL ,
`Status` int NULL ,
`Label` int NULL ,
`ResourceID` int NULL ,
`ResourceIDs` Longtext NULL ,
`ReminderInfo` Longtext NULL ,
`RecurrenceInfo` Longtext NULL ,
`CustomField1` Longtext NULL
CONSTRAINT [PK_Appointments] PRIMARY KEY
(
`UniqueID` ASC
)
); TEXTIMAGE_ON `PRIMARY`

GO

CREATE TABLE Resources (
`UniqueID` int AUTO_INCREMENT NOT NULL ,
`ResourceID` int NOT NULL ,
`ResourceName` nvarchar (50) NULL ,
`Color` int NULL ,
`Image` Longblob NULL ,
`CustomField1` Longtext NULL
CONSTRAINT [PK_Resources] PRIMARY KEY
(
`UniqueID` ASC
)
); TEXTIMAGE_ON `PRIMARY`

GO

SET IDENTITY_INSERT `dbo`.`Resources` ON
INSERT [dbo].[Resources] (`UniqueID`, `ResourceID`, `ResourceName`, `Color`, `Image`, `CustomField1`) SELECT (1, 1, N'Resource One', NULL, NULL, NULL)
INSERT [dbo].[Resources] (`UniqueID`, `ResourceID`, `ResourceName`, `Color`, `Image`, `CustomField1`) SELECT (2, 2, N'Resource Two', NULL, NULL, NULL)
INSERT [dbo].[Resources] (`UniqueID`, `ResourceID`, `ResourceName`, `Color`, `Image`, `CustomField1`) SELECT (3, 3, N'Resource Three', NULL, NULL, NULL)
SET IDENTITY_INSERT `dbo`.`Resources` OFF

GO

这是我尝试运行此查询时的结果。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT [PK_Appointments] PRIMARY KEY 
(
`UniqueID` ASC
)
)' at line 20

有人可以帮我解决这个查询吗?

最佳答案

试试这个:

   CREATE TABLE Appointments (
`UniqueID` int AUTO_INCREMENT NOT NULL ,
`Type` int NULL ,
`StartDate` Datetime NULL ,
`EndDate` Datetime NULL ,
`AllDay` Tinyint NULL ,
`Subject` varchar (50) NULL ,
`Location` varchar (50) NULL ,
`Description` Longtext NULL ,
`Status` int NULL ,
`Label` int NULL ,
`ResourceID` int NULL ,
`ResourceIDs` Longtext NULL ,
`ReminderInfo` Longtext NULL ,
`RecurrenceInfo` Longtext NULL ,
`CustomField1` Longtext NULL,
PRIMARY KEY (`UniqueID`)


);

CREATE TABLE Resources (
`UniqueID` int AUTO_INCREMENT NOT NULL ,
`ResourceID` int NOT NULL ,
`ResourceName` varchar (50) NULL ,
`Color` int NULL ,
`Image` Longblob NULL ,
`CustomField1` Longtext NULL,
PRIMARY KEY(`UniqueID`)
);

INSERT into Resources(`UniqueID`, `ResourceID`, `ResourceName`, `Color`, `Image`, `CustomField1`) values (1, 1, 'Resource One', NULL, NULL, NULL);
INSERT into Resources(`UniqueID`, `ResourceID`, `ResourceName`, `Color`, `Image`, `CustomField1`) values (2, 2, 'Resource Two', NULL, NULL, NULL);
INSERT into Resources(`UniqueID`, `ResourceID`, `ResourceName`, `Color`, `Image`, `CustomField1`) values (3, 3, 'Resource Three', NULL, NULL, NULL);

关于带约束的 Mysql 查询出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30518745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com