whats wrong with this mysql? - mysql

can anyone please tell me what is wrong with my sql query
"INSERT INTO `userdetails`(`ID`,'Gender','RS') VALUES ('09090','0','1')";
i have set ID to be bigintand 'Gender' and 'RS' to be booleans.

Use back tics for column and table names. Single quotes are for values.
INSERT INTO `userdetails`
(`ID`,`Gender`,`RS`)
VALUES
('09090','0','1');

The problem is when you are inputing a value for the ID you are passing in a char instead of a bigint. Also, for the boolean values they shouldn't be in quotes the should be either true or false. The query should look something like this:
INSERT INTO userDetails(Id, Gender, RS)
VALUES(09090, true, false)

"INSERT INTO `userdetails`(`ID`,'Gender`,`RS`) VALUES ('09090','0','1')";
You should use the backtick (``) character to enclose column names. String values use regular quotes ('')

Related

Error with "insert '0' in bit-field type"

Why does INSERT '0' in bit(1), produce an error:
#1406 - Data too long for column [del] at row [del].
If I INSERT 0 (like int) everything is fine. Why doesn't the field want to automatically convert the string to an integer?
Try:
INSERT '0'='0';
INSERT '0'='1';
to insert resp. true and false.
Single quotes are for literals, here is a great explanation
https://stackoverflow.com/a/14123649/5754159

Syntax error in SQL query unable to understand

I'm getting a syntax error:
Syntax error near 17:38
insert into tbl_otp('mobile', 'otp', 'exp') values (9932111111, 333333, 2019-04-09 17:38:34)
Single quotes denote string literals, so you shouldn't use them for column names. You should, however, surround the date literal with quotes:
insert into
tbl_otp(mobile, otp, exp) -- no quotes
values (9932111111, 333333, '2019-04-09 17:38:34') -- quotes
insert into tbl_otp(`mobile`, `otp`, `exp`)
values ('9932111111', '333333', '2019-04-09 17:38:34')
Need to backquote your column names and single-quote your values, though the latter is just to be safe.
put the date value in quotes and remove quotes from column names:
insert into tbl_otp(mobile, otp, exp) values (9932111111, 333333, '2019-04-09 17:38:34')

MySql Functions: Insert substring into string

I need to know what function to use to insert a substring into a string of characters in MySql.
This is an example of ua field in my database:
https://www.facebook.com/ExamplePage/
I need to insert the substring pg/ and it needs to look like this when completed:
https://www.facebook.com/pg/ExamplePage/
Note: the first part of all the strings in my fields are the same.
You can do this with a simple replacement:
update `table`
set `field` = replace(field, 'https://www.facebook.com/', 'https://www.facebook.com/pg/')
where `field` like 'https://www.facebook.com/%';

Can someone please tell me why this doesn't work? Please see screenshot

I believe my date format is correct.
This happened with the rest of the tables as well :(
You just need to surround your first attribute with simple quotes, because it is a varchar
And for the date: you also need to surround it with quotes, and it must follow 'yyyy-mm-dd HH:MM:SS' format (dashes, not dots):
INSERT INTO Curator VALUES ('AnneGreenland', 322554897, '2009-07-11');
Varchar and date are string. So, use them within " symbol.
INSERT INTO Curator (CuratorName, CPhoneNumber, EmpolymentDate) VALUES ("AnneGreenland", 322554897, "2009-07-11");
You need to add the double quotes for each string and date value. What is more there is other error, the date type need - instead of ..
You need also to include the column names if you won't insert all columns values.
INSERT INTO Curator (CuratorName, CPhoneNumber, EmpolymentDate)
VALUES ("AnneGreenland", 322554897, "2009-07-11");
But in your case you can just do the next:
INSERT INTO Curator VALUES ("AnneGreenland", 322554897, "2009-07-11");
I hope that helps :D
You have to name the columns you're setting.
INSERT INTO table_name (column1, column2, column3) VALUES (value1, value2, value3)

Replace values with string mysql

I have a VARCHAR column in which some values end with the digit '5'. These
values may be of different lengths. I want to replace all such values
with the string 'UTR-5'. How can I do that?
Maybe not the fastest solution, but:
update myTable set value = 'UTR-5' where value like '%5'