Hello im trying to run a query in phpmyadmin but im getting this error
#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 'ADD `Sabrina` INT( 2 ) NOT NULL DEFAULT '0' ADD `Janine` INT( 2 ) NOT NULL DEFAU' at line 3
Here is my query
ALTER TABLE `users` ADD `Misty` INT( 2 ) NOT NULL DEFAULT '0',
ADD `Erika` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Sabrina` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Janine` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Blaine` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Giovanni` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Cissy` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Danny` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Rudy` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Luana` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Drake` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Drake` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Falkner` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Bugsy` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Whitney` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Morty` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Chuck` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Jasmine` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Pryce` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Clair` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Roxanne` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Brawly` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Wattson` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Flannery` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Norman` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Winona` INT( 2 ) NOT NULL DEFAULT '0'
ADD `LizaandTate` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Wallace` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Roark` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Gardenia` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Maylene` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Wake` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Fantina` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Byron` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Candice` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Volkner` INT( 2 ) NOT NULL DEFAULT '0'
ADD `ChiliCilanandCress` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Lenora` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Burgh` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Elesa` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Clay` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Skyla` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Brycen` INT( 2 ) NOT NULL DEFAULT '0'
ADD `DraydenandIris` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Will` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Koga` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Bruno` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Karen` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Sidney` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Phoebe` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Glacia` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Drake` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Aaron` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Bertha` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Flint` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Lucian` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Shauntal` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Grimsley` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Caitlin` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Marshal` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Blue` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Lance` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Steven` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Cynthia` INT( 2 ) NOT NULL DEFAULT '0'
ADD `Alder` INT( 2 ) NOT NULL DEFAULT '0'
It does a few but keeps getting stuck on Janine ???
There's a lot of problems with your query:
You need to add a comma after every line except for the last line (e.g. ADD `Sabrina` INT( 2 ) NOT NULL DEFAULT '0',
You have two columns named Drake -- column names must be unique
Your table structure makes me think that you might be misunderstanding how relational tables are meant to be used. You should probably have a ROW for each name, not a COLUMN. What information are you trying to store?
Edit: Given the information in your comment, you only need two columns: name and badge. Then add a row for every user. This allows you to have as many users as you want.
You only have a comma after the first entry, you need one after every one except the last one:
ALTER TABLE `users` ADD `Misty` INT( 2 ) NOT NULL DEFAULT '0',
ADD `Erika` INT( 2 ) NOT NULL DEFAULT '0',
ADD `Sabrina` INT( 2 ) NOT NULL DEFAULT '0',
ADD `Janine` INT( 2 ) NOT NULL DEFAULT '0',
...
Related
This question already has answers here:
Set NOW() as Default Value for datetime datatype?
(13 answers)
Closed 7 years ago.
I have a query:
CREATE TABLE IF NOT EXISTS `o7xn5_tbl_service` (
`ID` int( 11 ) NOT NULL AUTO_INCREMENT ,
`firstname` varchar( 20 ) NOT NULL ,
`lastname` varchar( 20 ) NOT NULL ,
`idnumber` varchar( 15 ) NOT NULL ,
`position` varchar( 50 ) NOT NULL ,
`phone` varchar( 13 ) NOT NULL ,
`email` varchar( 50 ) NOT NULL ,
`building` varchar( 50 ) NOT NULL ,
`department` varchar( 50 ) NOT NULL ,
`problemtype` varchar( 100 ) NOT NULL ,
`description` varchar( 500 ) NOT NULL ,
`regdate` datetime DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( `ID` )
) ENGINE = InnoDB DEFAULT CHARSET = latin1 AUTO_INCREMENT = 19;
MySQL gives an error:
Documentation #1067 - Invalid default value for 'regdate'
What does it mean?
A datetime column cannot have a CURRENT_TIMESTAMP default.
Only a timestamp column can have it.
Change
`regdate` datetime DEFAULT CURRENT_TIMESTAMP ,
to
`regdate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
Can the people of the internet help me with MySQL
Error
SQL query:
CREATE TABLE `users` (
`user_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 32 ) NOT NULL ,
`password` VARCHAR( 32 ) NOT NULL ,
`first_name` VARCHAR( 32 ) NOT NULL ,
`last_name` VARCHAR( 32 ) NOT NULL ,
`email` VARCHAR( 1024 ) NOT NULL ,
`active` INT( 11 ) NOT NULL DEFAULT '0'
) ENGINE = innodb
MySQL said: Documentation
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
It clearly says in the error there can be only one auto column and it must be defined as a key.
Add PRIMARY KEY (user_id) at the end and it should work.
CREATE TABLE `users` (
`user_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 32 ) NOT NULL ,
`password` VARCHAR( 32 ) NOT NULL ,
`first_name` VARCHAR( 32 ) NOT NULL ,
`last_name` VARCHAR( 32 ) NOT NULL ,
`email` VARCHAR( 1024 ) NOT NULL ,
`active` INT( 11 ) NOT NULL DEFAULT '0',
PRIMARY KEY (user_id)
) ENGINE = innodb;
I have a dump file that I used mysqldump to generate using mysqldump on mysql 5.5.34 on mac os x. I am able to import using mysql source command and also able to import using phpMyAdmin 4.0.8.
I have a user using mysql 5.5.32-log and phpMyAdmin 2.8.0.1 with the mysql extension using client library 5.0.51a
When importing the database, they get the following error:
SQL query:
/*!40101 SET #saved_cs_client = ##character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `phppos_customers` (
`person_id` INT( 10 ) NOT NULL ,
`account_number` VARCHAR( 255 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`company_name` VARCHAR( 255 ) COLLATE utf8_unicode_ci NOT NULL ,
`balance` DECIMAL( 23, 10 ) NOT NULL DEFAULT '0.0000000000',
`taxable` INT( 1 ) NOT NULL DEFAULT '1',
`cc_token` VARCHAR( 255 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`cc_preview` VARCHAR( 255 ) COLLATE utf8_unicode_ci DEFAULT NULL ,
`card_issuer` VARCHAR( 255 ) COLLATE utf8_unicode_ci DEFAULT '',
`tier_id` INT( 10 ) DEFAULT NULL ,
`deleted` INT( 1 ) NOT NULL DEFAULT '0',
UNIQUE KEY `account_number` ( `account_number` ) ,
KEY `person_id` ( `person_id` ) ,
KEY `deleted` ( `deleted` ) ,
KEY `cc_token` ( `cc_token` ) ,
KEY `phppos_customers_ibfk_2` ( `tier_id` ) ,
CONSTRAINT `phppos_customers_ibfk_1` FOREIGN KEY ( `person_id` ) REFERENCES `phppos_people` ( `person_id` ) ,
CONSTRAINT `phppos_customers_ibfk_2` FOREIGN KEY ( `tier_id` ) REFERENCES `phppos_price_tiers` ( `id` )
) ENGINE = INNODB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;
MySQL said: <b_help.png>
#1005 - Can't create table 'nbofpos.phppos_customers' (errno: 150)
If I export my database using phpMyAdmin's export, it works correctly on his phpMyAdmin. He doesn't have shell access or any way to update phpMyAdmin. I verified he has INNODB abilities, so that isn't it either.
I need to generate sql that works will on all situations and I thought mysqldump would be the right way, but maybe I am wrong.
Mysql doesn't want to add this database into my localhost database section.
Am I doing something wrong?
db.sql
This tutorial: https://github.com/samanz/cakecart
Error:
SQL query:
CREATE TABLE `categories` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 50 ) NULL default NULL ,
`parent_id` INT( 11 ) UNSIGNED default '0',
`order` INT( 3 ) default '0',
`image` VARCHAR( 50 ) NULL default NULL ,
`ids` VARCHAR( 225 ) NULL default NULL ,
`url` VARCHAR( 255 ) NULL default NULL ,
PRIMARY KEY ( `id` ) ,
FOREIGN KEY ( `parent_id` ) REFERENCES categories( `id` ) ,
UNIQUE KEY `url` ( `url` )
);
MySQL said: Documentation
#1005 - Can't create table 'cake_cart.categories' (errno: 150)
Error 150 is a foreign key problem. Likely caused by:
FOREIGN KEY ( `parent_id` ) REFERENCES categories( `id` ) ,
You can't make a "foreign" key reference to the same table you're creating. Simply make the parent_id column indexed instead.
KEY `parent_id` ( `parent_id` ) ,
Should look something like this...
CREATE TABLE IF NOT EXISTS `categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`parent_id` int(11) unsigned NOT NULL DEFAULT '0',
`order` int(3) NOT NULL DEFAULT '0',
`img` varchar(50) NOT NULL,
`ids` varchar(255) NOT NULL,
`url` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `url` (`url`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I updated the structure and ran it on my database and it worked.
How do I import this database correctly?
https://github.com/samanz/cakecart
Every time I import then I get this error:
Error
SQL query:
CREATE TABLE `categories` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 50 ) NULL default NULL ,
`parent_id` INT( 11 ) UNSIGNED default '0',
`order` INT( 3 ) default '0',
`image` VARCHAR( 50 ) NULL default NULL ,
`ids` VARCHAR( 225 ) NULL default NULL ,
`url` VARCHAR( 255 ) NULL default NULL ,
PRIMARY KEY ( `id` ) ,
FOREIGN KEY ( `parent_id` ) REFERENCES categories( `id` ) ,
UNIQUE KEY `url` ( `url` )
);
MySQL said: Documentation
#1005 - Can't create table 'db.categories' (errno: 150)
Foreign key is error 150, but there's much more tables than this error.
Please try import first then answer.
THis one works:
CREATE TABLE `categories` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 50 ) NULL default NULL ,
`parent_id` INT( 11 ),
`order` INT( 3 ) default '0',
`image` VARCHAR( 50 ) NULL default NULL ,
`ids` VARCHAR( 225 ) NULL default NULL ,
`url` VARCHAR( 255 ) NULL default NULL ,
PRIMARY KEY ( `id` ) ,
FOREIGN KEY ( `parent_id` ) REFERENCES categories( `id` ) ,
UNIQUE KEY `url` ( `url` )
);
Edit: Actually you only need to remove unsigned to make it work. But I don't really know why you want it to be default 0. It should be default NULL which is the default default.. :)
I believe the type of parent_id must be the same as id.
The problem is that,You are trying to create table category.In this table you are using forign key but this forign key included table isnot created yet.
So first create the table contaning parent_id .After that try to create the category table
I'm think it's giving you and error because you're referencing an nonexistent, not yet created, table which is the table your trying to create itself.
why don't you create the table first then add the constraint(foreign key)?
but there's a possible error that you may run into whole doing this in the same table. what would happen if the newly added record doesn't have a parent assigned to it? default value is 0. will this give you an error because there's no record with id=0?
I suggest you normalize this by creating a relationship table for this.
CREATE TABLE CategoryGroups //or whatever name you find fits.
(
`Cat_id` int(11) NOT NULL,
`Parent_id` int(11),
FOREIGN KEY (`Parent_id`) REFERENCES categories(`id`),
FOREIGN KEY (`Cat_id`) REFERENCES categories(`id`)
)
Best practices would be to normalize all data and remove all many to many relationships between any two tables by creating relationship tables.