HomeLinuxHow do I Insert Knowledge right into a Particular Row in MySQL?

How do I Insert Knowledge right into a Particular Row in MySQL?


MySQL is an RDBMS which shops and manages huge knowledge in an organized kind in order that knowledge might be managed effectively. It additionally gives the power of updating knowledge utilizing the “UPDATE” question with a “The place” clause that matches a particular situation or situation within the present data.

This information will talk about how one can:

Prerequisite

To start with, on this submit it’s best to log in to the MySQL server containing databases, and choose a database to insert knowledge. After the login, use this command to show the checklist of all accessible databases:

The output is displaying an inventory of databases:

Choose a database. For this submit, the identify of the database is “linuxhint”:

Run these instructions to indicate all tables accessible within the database after which choose a particular desk:

present tables;

choose * from worker;

Insert Knowledge right into a New Row in MySQL

To insert knowledge into a brand new row, use the “INSERT INTO” command and specify the desk identify. Enter the names of columns and their values. For instance, if you wish to insert a brand new row within the “worker” desk, use this question:

INSERT INTO worker (Id,CompanyName,ContactName,Metropolis,Nation,Telephone)VALUES(7,’Maroon Door’,’John’,’London’,’UK’,'(000) 123-2531′);

After the profitable execution of the command “Question Okay” message will show:

To confirm if the brand new row is added or not, use this question:

The brand new row is efficiently inserted within the desk:

Insert Knowledge right into a Particular Column

To insert knowledge into a particular column utilizing the “SET” assertion. For instance, if you wish to replace the columns “Metropolis” and “Nation” to a particular worth, run this question:

UPDATE worker SET Metropolis = ‘London’, Nation = ‘UK’;

The brand new knowledge will insert into these columns efficiently:

Insert Knowledge right into a Particular Row That Meets a Situation

To insert knowledge into a particular row that meets a situation within the “The place” clause. If you wish to change the worth of “Metropolis” and “Nation”, “The place” the “id” is the same as “1”, run this question:

UPDATE worker SET Metropolis = ‘Osaka’, Nation = ‘Japan’ the place id = 1;

The message “Question OK, 1 row affected” is displaying that the information is up to date efficiently on “1” row. To confirm it shows the information of the desk by typing:

The information is inserted efficiently:

Insert Knowledge right into a Particular Row That Meets A number of Situations

The “UPDATE” assertion can comprise a number of situations utilizing the Logical operators. If you wish to insert knowledge into rows that meet the situation “The place” its id is the same as “2” “AND” the “ContactName” is the same as “Saavedra”, run this question:

UPDATE worker SET Metropolis = ‘Osaka’, Nation = ‘Japan’ the place id > 2 AND ContactName=”Saavedra”;

One row meets this specified situation so its values will probably be up to date for “Metropolis” and “Nation”, to confirm the adjustments show the information of the desk:

You’ve discovered how one can insert knowledge into a particular row in MySQL.

Conclusion

In MySQL to insert knowledge in a particular row into an present desk use the “UPDATE” assertion with the “The place” Clause to specify the situation. MySQL will solely Insert knowledge right into a row that can fulfill the situation. To outline a number of situations, use the Logical operators. This information demonstrated the process for inserting knowledge into a particular row in MySQL.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments