CREATE TABLE IF NOT EXISTS 'test'(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`campaincode` VARCHAR( 100 ) NOT NULL ,
`description` VARCHAR( 100 ) NOT NULL ,
`paymentplantype` VARCHAR( 100 ) NOT NULL ,
`contractlength` INT NOT NULL ,
`monthlyannuityfactor` DOUBLE NOT NULL ,
`initialfee` DOUBLE NOT NULL ,
`notificationfee` DOUBLE NOT NULL ,
`interestratepercentage` INT NOT NULL ,
`interestfreemonths` INT NOT NULL ,
`paymentfreemonths` INT NOT NULL ,
`fromamount` DOUBLE NOT NULL ,
`toamount` DOUBLE NOT NULL ,
`timestamp` INT UNSIGNED NOT NULL ,
`storeid` INT NOT NULL
)
答案 0 :(得分:1)
您应该从表名中删除'
个字符,如下所示
CREATE TABLE IF NOT EXISTS test(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`campaincode` VARCHAR( 100 ) NOT NULL ,
`description` VARCHAR( 100 ) NOT NULL ,
`paymentplantype` VARCHAR( 100 ) NOT NULL ,
`contractlength` INT NOT NULL ,
`monthlyannuityfactor` DOUBLE NOT NULL ,
`initialfee` DOUBLE NOT NULL ,
`notificationfee` DOUBLE NOT NULL ,
`interestratepercentage` INT NOT NULL ,
`interestfreemonths` INT NOT NULL ,
`paymentfreemonths` INT NOT NULL ,
`fromamount` DOUBLE NOT NULL ,
`toamount` DOUBLE NOT NULL ,
`timestamp` INT UNSIGNED NOT NULL ,
`storeid` INT NOT NULL
)
答案 1 :(得分:0)
表名有引号,它应该有后缀。试试这个:
CREATE TABLE IF NOT EXISTS `test`(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`campaincode` VARCHAR( 100 ) NOT NULL ,
`description` VARCHAR( 100 ) NOT NULL ,
`paymentplantype` VARCHAR( 100 ) NOT NULL ,
`contractlength` INT NOT NULL ,
`monthlyannuityfactor` DOUBLE NOT NULL ,
`initialfee` DOUBLE NOT NULL ,
`notificationfee` DOUBLE NOT NULL ,
`interestratepercentage` INT NOT NULL ,
`interestfreemonths` INT NOT NULL ,
`paymentfreemonths` INT NOT NULL ,
`fromamount` DOUBLE NOT NULL ,
`toamount` DOUBLE NOT NULL ,
`timestamp` INT UNSIGNED NOT NULL ,
`storeid` INT NOT NULL
)
应始终使用一些有用的信息,反引号。但是有一些原因可能导致团队不愿意使用它们。
优点:
缺点:
答案 2 :(得分:-1)
您的SQL存在一些问题
下面是检查表是否存在的代码,如果我不存在则创建它
/* CHECK IF THE TABLE EXISTS IN sys.objects*/
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = object_id(N'[dbo].[Table]') AND type in (N'U'))
BEGIN -- If it dont create the table
CREATE TABLE [VI].[dbo].[Table]
(
id INT NOT NULL identity(1,1) PRIMARY KEY
, campaincode VARCHAR( 100 ) NOT NULL
, [description] VARCHAR( 100 ) NOT NULL --if you want to use keywords that SQL uses like description it is best practise to wrap them in []
, paymentplantype VARCHAR( 100 ) NOT NULL
, contractlength INT NOT NULL
, monthlyannuityfactor decimal(18, 0) NOT NULL -- when using decimal you must also type in the amount of numbers you want before the .(decimal place) and the amount you want after the decimal place
-- i have set this to 18 before the . and 0 after this is the deafult when creating tables
, initialfee decimal(18, 0) NOT NULL
, notificationfee decimal(18, 0) NOT NULL
, interestratepercentage INT NOT NULL
, interestfreemonths INT NOT NULL
, paymentfreemonths INT NOT NULL
, fromamount decimal(18, 0) NOT NULL
, toamount decimal(18, 0) NOT NULL
, [timestamp] INT NOT NULL
, storeid INT NOT NULL
)
END
如果您需要更多帮助信息,我也不要忘记如果答案是完整的,请将答案标记为完整