用Constraint进行Mysql查询,得到错误

时间:2015-05-28 23:30:42

标签: mysql sql

我尝试将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 

有人可以帮我修复此查询吗?

1 个答案:

答案 0 :(得分:1)

试试这个:

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