I'm trying to run the following query:
"insert into visits set source = 'http://google.com' and country = 'en' and ref = '1234567890';"
The query looks good to me and it prints a warning:
1 row(s) affected, 2 warning(s): 1364 Field 'country' doesn't have a default value 1292 Truncated incorrect DOUBLE value: 'http://google.com'
And the info isn't stored as expected:
id , ref , bnid, source, country
'5', NULL, NULL, '0' , ''
If I run the normal syntax like:
insert into visits (source,country,ref) values('http://google.com','en','1234567890');
I get the expected result:
'6', '1234567890', NULL, 'http://google.com', 'en'
The first syntax (insert set) was working in previous server. Now I changed to one with cpanel and it doesn't. It's the second time this week I get this problem in two different VPS with cpanel so I'm guessing it should be the version number or mysql config.
Mysql Version: 5.1.63-cll
Table:
CREATE TABLE `visits` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ref` varchar(64) DEFAULT NULL,
`bnid` int(11) DEFAULT NULL,
`source` varchar(256) DEFAULT NULL,
`country` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
Any help?
If you are using Insert or Insert into both will insert the data in Table. However Insert into is basically used to fatch the data from another table using select command and insert into table where you want to insert the data.
MySQL INSERT used to insert a specific value To insert values into the columns, we can use the SET clause instead of the VALUES clause. INSERT INTO Customers SET ID=2, FirstName='User2'; In the output, the statement inserts values into the columns based on the explicitly specified values in the SET clause.
INTO' creates the destination table, it exclusively owns that table and is quicker compared to the 'INSERT … SELECT'. Because the 'INSERT … SELECT' inserts data into an existing table, it is slower and requires more resources due to the higher number of logical reads and greater transaction log usage.
The INSERT INTO statement is used to insert new records in a table.
Remove 'and' from the insert query
insert into visits set source = 'http://google.com' , country = 'en' , ref = '1234567890'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With