I am trying to create a table but keep getting this Syntax error: unexpected NULL_SYM, expecting '(' error.
CREATE TABLE `project` (
`project_id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`project_name` varchar NULL,
`location` varchar NULL,
`date` datetime NULL,
`status` varchar NULL,
`specifier` varchar NULL,
`supplier` varchar NULL,
`cost` float NULL,
`sales_amount` float NULL,
`estimate_qty` float NULL,
`unit` varchar NULL,
`proposed_office` varchar NULL,
`proposed_person` int NULL,
`followed_office` varchar NULL,
`followed_person` int NULL,
`remark` varchar NULL,
PRIMARY KEY (`project_id`)
);
The error is at 'project_name' varchar NULL,
You need to specify the length of your varchar columns. Example
`project_name` varchar(100) NULL
It could look like this
CREATE TABLE `project`
(
`project_id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`project_name` varchar(100) NULL,
`location` varchar(100) NULL,
`date` datetime NULL,
`status` varchar(10) NULL,
`specifier` varchar(100) NULL,
`supplier` varchar(100) NULL,
`cost` decimal NULL,
`sales_amount` decimal NULL,
`estimate_qty` decimal NULL,
`unit` varchar(10) NULL,
`proposed_office` varchar(100) NULL,
`proposed_person` int NULL,
`followed_office` varchar(100) NULL,
`followed_person` int NULL,
`remark` varchar(200) NULL,
PRIMARY KEY (`project_id`)
);
Related
I am using MySQL Query Browser.
I have tried this code:
CREATE TABLE `something`.`payment_something` (
`firstName` varchar(15) NOT NULL,
`lastName` varchar(15) NOT NULL,
`inputEmail` varchar(55) NOT NULL,
`genderRadios` varchar(15) NOT NULL,
`monthh` varchar(10) NOT NULL,
`dayy` varchar(10) NOT NULL,
`yearr` varchar(10) NOT NULL,
`postalAddress` varchar(15) NOT NULL,
`phoneNumber` varchar(15) NOT NULL,
`ZipCode` varchar(15) NOT NULL,
`CreditCard` varchar(15) NOT NULL,
`expireMonth` varchar(10) NOT NULL,
`expireYear` varchar(10) NOT NULL,
`Institution` varchar(25) NOT NULL,
`textinput` varchar(15) NOT NULL,
`radios` varchar(10) NOT NULL,
PRIMARY KEY ()
) ENGINE=InnoDB DEFAULT CHARSET=greek;
of course it shows error in the PRIMARY KEY line. Any idea?
EDIT Better solution
CREATE TABLE `something`.`payment_something` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`firstName` varchar(15) NOT NULL,
`lastName` varchar(15) NOT NULL,
`inputEmail` varchar(55) NOT NULL,
`genderRadios` varchar(15) NOT NULL,
`monthh` varchar(10) NOT NULL,
`dayy` varchar(10) NOT NULL,
`yearr` varchar(10) NOT NULL,
`postalAddress` varchar(15) NOT NULL,
`phoneNumber` varchar(15) NOT NULL,
`ZipCode` varchar(15) NOT NULL,
`CreditCard` varchar(15) NOT NULL,
`expireMonth` varchar(10) NOT NULL,
`expireYear` varchar(10) NOT NULL,
`Institution` varchar(25) NOT NULL,
`textinput` varchar(15) NOT NULL,
`radios` varchar(10) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=greek;
It shows wrong in the PRIMARY KEY line why?
Simply exclude the problematic line:
PRIMARY KEY ()
You don't need to have that line, if you are not actually defining a key. In your example, you will also have to remove the comma directly preceding this line, of course.
UPDATE:
In your updated example, just take the '' off of 'id' when you declare it. Use the backtick (`), instead of the apostrophe:
PRIMARY KEY (`id`)
I created table as follows:
CREATE TABLE IF NOT EXISTS `products` (
`ID` tinyint(3) NOT NULL AUTO_INCREMENT,
`SKU` varchar(30) NOT NULL,
`Title` varchar(100) NOT NULL,
`Description` text NOT NULL,
`Price` decimal(3,2) NOT NULL,
`Image1` varchar(100) NOT NULL,
`Image2` varchar(100) NOT NULL,
`Keywords` varchar(150) NOT NULL,
`Shop` tinyint(2) NOT NULL,
`lmlCat` tinyint(3) NOT NULL,
`VinylCat` tinyint(3) NOT NULL,
`FancyCat` tinyint(3) NOT NULL,
`Active` tinyint(1) NOT NULL,
`SizeDescription` varchar(50) NOT NULL,
`Size` varchar(250) NOT NULL,
PRIMARY KEY (`ID`)
);
When importing data from CSV, it imports 127 lines then I get this error:
#1062 - Duplicate entry '127' for key 'PRIMARY'
You made the ID column a tinyint which can only take values from -127 to 127, larger values are truncated. Make it a regular int and things will work.
I have this table
CREATE TABLE `inventario` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cla` varchar(100) NOT NULL,
`des` varchar(500) NOT NULL,
`lin` varchar(3) NOT NULL,
`cal` varchar(20) NOT NULL,
`uen` varchar(20) NOT NULL,
`can` double NOT NULL,
`fei` varchar(10) NOT NULL,
`fec` varchar(10) NOT NULL,
`obs` varchar(500) NOT NULL,
`ppu` double NOT NULL,
`pl1` double NOT NULL,
`pl2` double NOT NULL,
`pl3` double NOT NULL,
`pl4` double NOT NULL,
`prm` double NOT NULL,
`pr1` varchar(50) NOT NULL,
`pr2` varchar(50) NOT NULL,
`mnm` double NOT NULL,
`max` double NOT NULL,
`dias` int(10) NOT NULL DEFAULT '1',
`categoria` varchar(50) NOT NULL,
PRIMARY KEY (`id`,`cla`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
Id and cla are primary keys, but I need to keep the integrity and this structure allows duplicate "cla" values: F/e:
Id | Cla
01 | ADI001
02 | ADI001
And I need to avoid repeating the "cla" value in spite of the "id" value, how can I do that? Thanks.
Create a unique index on cla. Add the line:
unique key cla
Below is my mysql query
SELECT
opensalesorder.so_number,
items.VendorName,
opensalesorder.item_number,
items_custom_fields.FieldValue AS `Stock Item`,
vendor_custom_fields.FieldValue AS `Paid Freight Allowance`,
items.QuantityOnHand,
items.ReorderPoint,
items.MaxQty,
SUM(opensalesorder.quantity_on_order),
items.PurchaseCost,
items.VendorName,
items.VendorName,
items.PurchaseCost,
opensalesorder.status,
items.ItemType
FROM
vendor,
`opensalesorder`
inner join items
on opensalesorder.item_number = items.ItemName
JOIN items_custom_fields
ON items_custom_fields.ItemName = items.ItemName
JOIN vendor_custom_fields
ON vendor_custom_fields.VName = vendor.VName
WHERE opensalesorder.item_number = items.ItemName
and items_custom_fields.FieldName ='Stock Item'
and vendor_custom_fields.FieldName ='Paid Freight Allowance'
and opensalesorder.status NOT LIKE 'on po'
AND opensalesorder.so_number NOT IN ('2','3')
AND items.VendorName NOT IN ('Access')
AND opensalesorder.item_number NOT IN ('018-0001')
group by opensalesorder.item_number
LIMIT 100
on executing this query I am getting error like
#1054 - Unknown column 'vendor.VName' in 'on clause'
But I have included the vendor table in FROM clause.
Is this right way to include a table in JOIN ?
So whats wrong is with this query ?
EDIT:
SHOW CREATE TABLE FOR opensalesorder
CREATE TABLE `opensalesorder` (
`so_number` decimal(10,0) NOT NULL,
`item_number` varchar(20) NOT NULL,
`quantity_on_order` int(11) NOT NULL,
`quantity_to_order` int(11) NOT NULL,
`status` varchar(20) NOT NULL,
`editsequence` text NOT NULL,
`TxnLineID` text NOT NULL,
`TxnID` text NOT NULL,
`dateCreated` date NOT NULL,
`shipDate` date NOT NULL,
`customer` text NOT NULL,
`itemclass` text NOT NULL,
UNIQUE KEY `unique_mapping` (`so_number`,`item_number`),
KEY `so_number` (`so_number`),
KEY `item_number` (`item_number`),
KEY `status` (`status`)
)
SHOW CREATE TABLE FOR items
CREATE TABLE `items` (
`ItemName` varchar(30) NOT NULL,
`VendorName` varchar(40) DEFAULT NULL,
`QuantityOnHand` int(11) DEFAULT NULL,
`QuantityOnSalesOrder` int(11) DEFAULT NULL,
`ReorderPoint` int(11) DEFAULT NULL,
`PurchaseCost` double DEFAULT NULL,
`AverageCost` double DEFAULT NULL,
`SalesPrice` double DEFAULT NULL,
`PurchaseDesc` varchar(200) DEFAULT NULL,
`SalesDesc` varchar(200) DEFAULT NULL,
`ItemType` varchar(30) DEFAULT NULL,
`FreeCode` int(11) DEFAULT NULL,
`SubGroup` varchar(10) DEFAULT NULL,
`DateNewItem` date DEFAULT NULL,
`Notes` text,
`MaxQty` int(11) DEFAULT NULL,
`QuantityOnPO` int(11) DEFAULT NULL,
PRIMARY KEY (`ItemName`),
KEY `ItemName` (`ItemName`),
KEY `VendorName` (`VendorName`)
)
SHOW CREATE TABLE FOR vendor_custom_fields
CREATE TABLE `vendor_custom_fields` (
`VName` text NOT NULL,
`FieldName` text NOT NULL,
`FieldValue` text NOT NULL,
`FieldType` text NOT NULL,
PRIMARY KEY (`VName`(120),`FieldName`(120)),
FULLTEXT KEY `VName_index` (`VName`)
)
SHOW CREATE TABLE FOR vendor
CREATE TABLE `vendor` (
`VName` varchar(60) NOT NULL,
`CompanyName` varchar(100) NOT NULL,
`Address1` varchar(120) NOT NULL,
`Address2` varchar(120) NOT NULL,
`City` varchar(40) NOT NULL,
`State` varchar(50) NOT NULL,
`PostalCode` varchar(13) NOT NULL,
`Phone` varchar(13) NOT NULL,
`Fax` varchar(13) NOT NULL,
`AlternatePhone` varchar(13) NOT NULL,
`AlternateContact` varchar(30) NOT NULL,
`Email` varchar(40) NOT NULL,
`AccountNumber` varchar(30) NOT NULL,
`Balance` double NOT NULL,
`RepEmail` varchar(40) NOT NULL,
`FreightAllowance` double DEFAULT NULL,
`MinimumPOLimit` double DEFAULT NULL,
`Notes` text NOT NULL,
PRIMARY KEY (`VName`)
)
I think the problem is mixing the implied join with the (unimplied) 'stated' joins. When I put 'vendor' in as a regular join the query was fine.
(I had to comment out references to 'items_custom_fields' as you didn't include the table definition)
Here's a fiddle.
I created a table in a MySQL database via the following:
CREATE TABLE `newsubscriptions_orderspecification` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`display_name` varchar(256) NOT NULL,
`sub_def_id` integer UNSIGNED NOT NULL,
`source_code_id` integer UNSIGNED NOT NULL,
`order_code_id` integer UNSIGNED NOT NULL,
`rate` numeric(5, 2) NOT NULL,
`type` varchar(4) NOT NULL,
`region` varchar(4) NOT NULL,
`term` varchar(4) NOT NULL,
`buyer_type` varchar(4) NOT NULL,
`is_active` bool NOT NULL,
UNIQUE (`sub_def_id`, `buyer_type`, `rate`, `is_active`)
)
;
How can I remove the uniqueness constraint?
use this:
ALTER TABLE `newsubscriptions_orderspecification` DROP INDEX `sub_def_id`