Perform DML commands (Data Manipulation Language)
To perform manipulation or processing of data in a table used DML command. Various kinds of DML commands are:
1. Insert: enter/add new data
INSERT INTO table_name (column_name) VALUES (value);
example:
insert into student (ID, name, address, major) values (12345, ‘Josh’, ‘California’, ‘informatics’);
description:
insert into -> command to add data
students -> table name that you want to add data
ID, name, address, directions -> the column name of Student table
12345, ‘Josh’, ‘California’, ‘informatics’ -> data entered into the student table (according to the order of the columns that have been mentioned before)
PS: for data of type character must be enclosed in single quotes ( ”)
2. Select: to select/choose the data to be displayed
SELECT * | (column_name) FROM table_name [WHERE condition];
example ->
select ID, name, department from students;
description:
information: the above command displays the data of ID, name and department in the student table.
PS: to display all the columns can use the sign (*). Example: select * from students
There is a requirement / condition for which the data can be displayed using an example where clause: select ID, name from student where name = ‘Josh’;
3. Update: for updated existing data
UPDATE table_name SET column_name = value [WHERE condition];
example ->
update students set the major = ‘medicine’ where name = ‘Josh’;
description:
These command will change the name of the student, Josh by replacing the data in column major, previously “informatics” to replace “medicine”.
PS: we can change more than one column in one update command for example: update students set ID = 45678, major = ‘medicine’ where name = ‘Josh’;
Caution: If we do not use a clause “where”, all the lines on the columns to the update will change.
4. Delete: to delete the data row
DELETE [FROM] table_name [WHERE condition];
example ->
delete student where name = ‘Josh’;
description: the above command to delete the data rows in the Student table with name student of Josh
Caution: If you do not use a clause “where”, the all rows of data in the table are deleted.