Below is my script to create a table. I keep getting a syntax error.
CREATE TABLE products ( id int(11) NOT NULL auto_increment, product_name varchar(255) NOT NULL, price varchar(16) NOT NULL, details text NOT NULL, stock int() NOT NULL, category varchar(16) NOT NULL, subcategory varchar(16) NOT NULL, date_added date NOT NULL, PRIMARY KEY (id), UNIQUE KEY product_name (product_name) ) ;
The is the syntax error I get. 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 ‘) NOT NULL, category varchar(16) NOT NULL, subcategory varchar(16) N’ at line 6.
Can someone please tell me what I am doing wrong. I don’t see it. And reading the error message obviously isn’t helping.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Here’s the correct code:
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`productname` varchar(255) NOT NULL,
`price` varchar(16) NOT NULL,
`details` text NOT NULL,
`stock` int(11) NOT NULL,
`category` varchar(16) NOT NULL,
`subcategory` varchar(16) NOT NULL,
`dateadded` date NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `productname` (`productname`)
);
stock column needs a length
(I presume the other answerer is pointing out the same thing…)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.