DML Commands For Adding & Manipulating The Data in Database Tables
DML Commands For Adding & Manipulating The Data in Database Tables
Before learning about the INSERT, DELETE and UPDATE commands of SQL, we must learn how to retrieve the structure of the table,
we want to work with; so that during any DM operation, we can provide appropriate data that satisfies the column definitions across the
table.
One way to retrieve the structure of a mysql table, is to use describe <table-name> command, aka desc <table-name>, as
shown below.
The output displays the table's column names, data types, and default values, among other information.
Another way is to display the CREATE TABLE STATEMENT used for creating the table. For this, we can use the SHOW CREATE
TABLE <table-name>\G command, as shown below.
(B)INSERT command
Simplest form of INSERT command, includes providing a set of values for all the columns of the respective table, in the same order, in which the
columns are defined in the table structure.
Sometimes, for some rows, values of certain columns is not available. In this scenario, we specify the column names for which, we wish to enter
values as shown below; followed by their respective values in paranthesis.
Lastly, if we wish to insert multiple rows together through a single INSERT command, we can do so using the following format.
SELECT QUERY
At the end of any DML operation, we can see the data stored in the tables using SELECT command as shown below.
(C)DELETE command
To remove any rows from a table, we can use DELETE command. The basic syntax of DELETE command is-
(D)UPDATE command
If you wish to modify the column values of existing rows, you can use UPDATE command for that. It’s basic syntax is given below.
Before executing the UPDATE query, status of table data is shown above.
After executing the UPDATE query, how the changes are being reflected in the table- is shown above.