INSERT INTO using SET in SQL - mysql

My first post so bear with me.
I need to restore a DB Table from a backup. I have cleaned the SQL up so I only have the the DROP TABLE, CREATE TABLE and INSERT INTO commands. The query is failing when I run it in MYSQl on my server.
The error message is....
MySQL said: Documentation
#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 'id='2',
unitid='1',
optionname='Baby Chair',
customtype='0',
customfeild' at line 3
The query is.....
DROP TABLE IF EXISTS `jos_resman_options`;
CREATE TABLE `jos_resman_options`
(
`id` int(4) NOT NULL AUTO_INCREMENT,
`unitid` int(9) NOT NULL DEFAULT '0',
`optionname` varchar(255) NOT NULL DEFAULT '',
`customtype` tinyint(1) NOT NULL DEFAULT '0',
`customfeild` varchar(150) NOT NULL DEFAULT '',
`moreinformation` varchar(255) NOT NULL DEFAULT '',
`totaloptions` tinyint(1) NOT NULL DEFAULT '0',
`price` decimal(10,2) NOT NULL DEFAULT '0.00',
`minvalue` int(2) NOT NULL DEFAULT '0',
`maxvalue` int(2) NOT NULL DEFAULT '0',
`formobject` int(1) NOT NULL DEFAULT '0',
`enabled` tinyint(1) NOT NULL DEFAULT '0',
`priceoption` int(1) NOT NULL DEFAULT '0',
`taxfree` tinyint(1) NOT NULL DEFAULT '0',
`compulsory` tinyint(1) NOT NULL DEFAULT '0',
`istax` tinyint(1) NOT NULL DEFAULT '0',
`isinsure` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=75;
INSERT INTO `jos_resman_options`
VALUES
id='2',
unitid='1',
optionname='Baby Chair',
customtype='0',
customfeild='',
moreinformation='Baby Chair',
totaloptions='0',
price='0.00',
minvalue='1',
maxvalue='2',
formobject='1',
enabled='1',
priceoption='2',
taxfree='1',
compulsory='0',
istax='0',
isinsure='0';
The table is created, When the CREATE TABLE part runs on it's own there is no error message. I only see the error message when the INSERT INTO part of the query runs.
The INSERT INTO data is directly from a backup of the database and so the data SHOULD be OK??
Many Thanks for any input
Have Tried all of the suggestions...Changing the Auto INCREMENT to DEFAULT Field, Put in the Brackets, All of them fail with error messages. Here's the latest error message... Thanks again all.!
Error
SQL query:
INSERT INTO `jos_resman_options`
SET unitid = '1',
optionname = 'Baby Chair',
customtype = '0',
customfeild = '',
moreinformation = 'Baby Chair',
totaloptions = '0',
price = '0.00',
minvalue = '1',
maxvalue = '2',
formobject = '1',
enabled = '1',
priceoption = '2',
taxfree = '1',
compulsory = '0',
istax = '0',
isinsure = '0'
MySQL said: Documentation
#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 'maxvalue='2',
formobject='1',
enabled='1',
priceoption='2',
taxfree='1',' at line 12

INSERT INTO `jos_resman_options`
VALUES (
id='2',
unitid='1',
optionname='Baby Chair',
customtype='0',
customfeild='',
moreinformation='Baby Chair',
totaloptions='0',
price='0.00',
minvalue='1',
maxvalue='2',
formobject='1',
enabled='1',
priceoption='2',
taxfree='1',
compulsory='0',
istax='0',
isinsure='0');

try to delete id fields becouse id was defined AutoNumber.
So you can not insert a value because it handles the database engine, if you delete the columba will tell you different amount of columns to insert, then try putting id = DEFAULT or omit the id field

Related

SQL query error #1064 without any obvious error

I'm scratching my head over this error. I'm trying to import a sql file through phpmyadmin and it comes up with this errors one after another and I cannot sea anything wrong with it. Can someone please analyse the lines below and let me know if they see any errors?
Thank you
--
-- Table structure for table `jos_address_members`
--
CREATE TABLE IF NOT EXISTS `jos_address_members` (
`uid` int(10) unsigned NOT NULL DEFAULT '0',
`adid` int(10) unsigned NOT NULL DEFAULT '0',
`publish` tinyint(4) NOT NULL DEFAULT '1',
`ordering` tinyint(3) unsigned NOT NULL DEFAULT '9',
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
MySQL said: Documentation
#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 ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' at line 12
Remove the comma after DEFAULT '9'
CREATE TABLE IF NOT EXISTS `jos_address_members` (
`uid` int(10) unsigned NOT NULL DEFAULT '0',
`adid` int(10) unsigned NOT NULL DEFAULT '0',
`publish` tinyint(4) NOT NULL DEFAULT '1',
`ordering` tinyint(3) unsigned NOT NULL DEFAULT '9'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

MYSQL wrong data inserted

I have a problem with my SQL query. I'm trying to insert data into table, but it seems like it put wrong value for one column.
Here is my query:
INSERT INTO va_users_points (user_id, order_id, points_amount, points_action, points_type, admin_id_added_by, admin_id_modified_by, date_added)
VALUES ('16772', '152424', '49', '1', '2', '0', '0', '2015-04-20 12:22:03')
The problem with column points_amount. In my query, it's 49. The DATA Type of this column in MYSQL table is INT(11). But, it inserts 490 value. Why it could be?
Here is my database structure
'points_id' INT(11) NOT NULL AUTO_INCREMENT,
'user_id' INT(11) NULL DEFAULT '0',
'order_id' INT(11) NULL DEFAULT '0',
'order_item_id' INT(11) NULL DEFAULT '0',
'points_amount' INT(11) NULL DEFAULT '0',
'points_action' INT(11) NULL DEFAULT '0',
'points_type' INT(11) NULL DEFAULT '0',
'admin_id_added_by' INT(11) NULL DEFAULT '0',
'admin_id_modified_by' INT(11) NULL DEFAULT '0',
'date_added' DATETIME NULL DEFAULT NULL,
'date_modified' DATETIME NULL DEFAULT NULL
As I see, there is no way this situation can occur except if there is a AFTER INSERT trigger defined on this table va_users_points which is doing this manipulation behind the scene as already commented by #fancypants.
Check this fiddle (http://sqlfiddle.com/#!9/4b1fb/1) which proves that there is nothing wrong with your INSERT statement.
To check if really a trigger is defined or not use the below SQL statement
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS
WHERE TRIGGER_SCHEMA='your_database_name'
AND EVENT_OBJECT_TABLE='va_users_points';

mysql error after trying put in SQL

I'm trying to insert tables from phpmyadmin in SQL, such as:
INSERT INTO users
(
steam VARCHAR(35) NOT NULL DEFAULT '',
name VARCHAR(32) NOT NULL DEFAULT '',
length INT NOT NULL DEFAULT 0,
unban VARCHAR(32) NOT NULL DEFAULT '',
reason VARCHAR(64) NOT NULL DEFAULT '',
banned SMALLINT NOT NULL DEFAULT 0,
leaves SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (steam)
);
But I'm getting an 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 'VARCHAR(35) NOT NULL DEFAULT '', name VARCHAR(32) NOT NULL DEFAULT '', length ' at line 3
What am I doing wrong?
Tables need to be exist in db before inserting value in that. so make sure that you are inserting value in that table which have existence in your database.
To create a table you need to fire the below query.
CREATE TABLE users
(
steam VARCHAR(35) NOT NULL DEFAULT '',
name VARCHAR(32) NOT NULL DEFAULT '',
length INT NOT NULL DEFAULT 0,
unban VARCHAR(32) NOT NULL DEFAULT '',
reason VARCHAR(64) NOT NULL DEFAULT '',
banned SMALLINT NOT NULL DEFAULT 0,
leaves SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (steam)
);
After creating the table you can directly insert value from you phpmyadmin or you can also do that by executing the below query.
INSERT INTO users VALUES
('steam value', 'name of user', '4', 'any unban value', 'any reason value', '0', '0');
if you want insert value from you php file than you must need to make a database connection & after that you can use mysql_query() function in insert value in you db
You should create table first:
CREATE TABLE users
(
steam VARCHAR(35) NOT NULL DEFAULT '',
name VARCHAR(32) NOT NULL DEFAULT '',
length INT NOT NULL DEFAULT 0,
unban VARCHAR(32) NOT NULL DEFAULT '',
reason VARCHAR(64) NOT NULL DEFAULT '',
banned SMALLINT NOT NULL DEFAULT 0,
leaves SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (steam)
);
once it created you can insert:
INSERT INTO users VALUES
('user steam value', 'user name', 3, 'unban value', 'reason value', 0, 0);

MySql don't create these table [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
1064 error in CREATE TABLE … TYPE=MYISAM
I am trying to install a PHP script named php-stats, this one: http://www.php-stats.it/ that is a Php that provides information about statistic of web site.
I have used it in the past and it is pretty good.
Today I am trying to install it on my server but I have some problem
It need to be installed on the server and use the database...my problem is when it try to create the database table...go into error with many tables...
The errors have the form of the following one (this is related to one specific table):
Error executing: CREATE TABLE php_stats_cache ( user_id varchar(15) NOT NULL default '0', data int(11) NOT NULL default '0', lastpage varchar(255) NOT NULL default '0', visitor_id varchar(32) NOT NULL default '', hits tinyint(3) unsigned NOT NULL default '0', visits smallint(5) unsigned NOT NULL default '0', reso varchar(10) NOT NULL default '', colo varchar(10) NOT NULL default '', os varchar(20) NOT NULL default '', bw varchar(20) NOT NULL default '', host varchar(50) NOT NULL default '', lang varchar(8) NOT NULL default '', giorno varchar(10) NOT NULL default '', level tinyint(3) unsigned NOT NULL default '0', UNIQUE KEY user_id (user_id) ) TYPE=MyISAM
Error string: 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 'TYPE=MyISAM' at line 17
I have also try to access inside the *.sql file that contains the query definition and execute the creation query table inside PHP MyAdmin, for example this query (related to the previus error):
DROP TABLE IF EXISTS php_stats_cache;
CREATE TABLE php_stats_cache (
user_id varchar(15) NOT NULL default '0',
data int(11) NOT NULL default '0',
lastpage varchar(255) NOT NULL default '0',
visitor_id varchar(32) NOT NULL default '',
hits tinyint(3) unsigned NOT NULL default '0',
visits smallint(5) unsigned NOT NULL default '0',
reso varchar(10) NOT NULL default '',
colo varchar(10) NOT NULL default '',
os varchar(20) NOT NULL default '',
bw varchar(20) NOT NULL default '',
host varchar(50) NOT NULL default '',
lang varchar(8) NOT NULL default '',
giorno varchar(10) NOT NULL default '',
level tinyint(3) unsigned NOT NULL default '0',
UNIQUE KEY user_id (user_id)
) TYPE=MyISAM;
Ig I try to execute this query inside PhpMyAdmin I obtain the following error message:
#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 'TYPE=MyISAM' at line 17
I also try to execute it on my local mysql server on my PC but I obtain always the same error message...
Why? What is the problem? How can I do to solve this problem?
Thank you
Andrea
Using TYPE has been deprecated and it was removed in MySQL 5.5. Use ENGINE = MYISAM instead.
CREATE TABLE php_stats_cache (....) ENGINE = MYISAM;

Latest version of MySQL gives error 1064 on code that used to work fine

Many servers now a days have the latest version of MySQL - which is giving an error when running the following piece of code:
$drop_table = mysql_query("DROP TABLE IF EXISTS `$t_ads`");
$sqls[$t_ads] = "CREATE TABLE `$t_ads` (
`adid` int unsigned NOT NULL auto_increment,
`adtitle` varchar(100) NOT NULL default '',
`addesc` longtext NOT NULL,
`area` varchar(50) NOT NULL default '',
`email` varchar(50) NOT NULL default '',
`showemail` enum('0','1','2') NOT NULL default '0',
`password` varchar(50) NOT NULL default '',
`code` varchar(35) NOT NULL default '',
`cityid` smallint unsigned NOT NULL default '0',
`subcatid` smallint unsigned NOT NULL default '0',
`price` DECIMAL( 10, 2 ) NOT NULL default '0',
`othercontactok` enum('0','1') NOT NULL default '0',
`hits` int unsigned NOT NULL default '0',
`ip` varchar(15) NOT NULL default '',
`verified` enum('0','1') NOT NULL default '0',
`abused` int unsigned NOT NULL default '0',
`enabled` enum('0','1') NOT NULL default '0',
`createdon` datetime NOT NULL default '0000-00-00 00:00:00',
`expireson` datetime NOT NULL default '0000-00-00 00:00:00',
`timestamp` timestamp(14) NOT NULL,
`paid` enum('0','1','2') NOT NULL default '2',
PRIMARY KEY (`adid`),
KEY `subcatid` (`subcatid`),
KEY `cityid` (`cityid`),
KEY `verified` (`verified`),
KEY `enabled` (`enabled`),
KEY `paid` (`paid`)
) TYPE=MyISAM;";
Servers with an older version of mysql seem to accept this, but the new version is not accepting it at all and giving an error. I have many errors related to it since the PHP database setup is little bigger. An example of the error is below:
#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 '(14) NOT NULL, paid enum, NOT NULL default '2', PRIMARY KEY (adid), K' at line 21
The plain SQL part of your code looks ok (just tested it with MySQL 5.6), though I'd generally advise not to use keywords like timestamp as a column name. The table will be created in MySQL 5.6, but you'll encounter two warnings:
The syntax TIMESTAMP(14) is deprecated and will be removed in
MySQL 6.0. Please use TIMESTAMP instead
The syntax TYPE=storage_engine is deprecated and will be removed in MySQL
6.0. Please use ENGINE=storage_engine instead
If this doesn't help, please post the actual MySQL version you're working with.
Change your column name it should not be mysql keyword 'timestamp' and
chnage
`timestamp` timestamp(14) NOT NULL,
to
`<SOME OTHERNAME>` timestamp NOT NULL,