I have a MySQL table ( members ) with six columns ( FirstName, LastName, Email, username, password, Key)
I need to insert a string into the Key column for the username admin
How would I go about doing this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Suppose the string you want to insert is the literal string
'MyString'. You could update the table like this:Some things to note:
Key, in identifier quotes (backticks). This is mainly because I know that MySQL may treat the word ‘key’ as an SQL reserved word, which might result in it failing to parse my UPDATE query.Keyhas a string datatype, such asTEXTorCHAR(20). If it doesn’t (for example if it’s anINT), then it doesn’t make sense to try to update it to contain a string.CHARorVARCHAR, is long enough to contain this string (i.e. it’s of length at least 8). If the column is too short to contain the string I’m trying to put in it, then MySQL will either truncate the string or issue an error message, depending on the SQL mode.Alternatively, if there isn’t a row in the table for which
usernameis ‘admin’, but you want to insert one, you useThis statement is subject to the same provisos as the one above. Also, any columns that are
NOT NULLwill need to have values specified as well (with the possible exception of an auto-incrementing integer field).