0 votes
111 views
in DataBase Management System by (98.9k points)
edited
Explain any four DML commands with an example.

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer

DML (Data Manipulation Language) commands are used to manipulate data in a database. Here are four common DML commands with examples of their use:

  1. SELECT: The SELECT command is used to retrieve data from one or more tables. The syntax for a simple SELECT statement is:

    SELECT column1, column2, ... FROM table_name WHERE condition;

    For example, to retrieve the names and ages of all students with a GPA greater than 3.0 from the "Students" table, we might use the following command:

    SELECT Name, Age FROM Students WHERE GPA > 3.0;

    This command selects the "Name" and "Age" columns from the "Students" table where the "GPA" is greater than 3.0.

  2. INSERT: The INSERT command is used to add new rows to a table. The syntax for inserting data into a table is:

    INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);

    For example, to add a new student with the name "John Doe", age 21, and a GPA of 3.5 to the "Students" table, we might use the following command:

    INSERT INTO Students (Name, Age, GPA) VALUES ('John Doe', 21, 3.5);

    This command adds a new row to the "Students" table with the specified values.

  3. UPDATE: The UPDATE command is used to modify existing rows in a table. The syntax for updating data in a table is:

    UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;

    For example, to update the GPA of the student named "John Doe" to 3.7 in the "Students" table, we might use the following command:

    UPDATE Students SET GPA = 3.7 WHERE Name = 'John Doe';

    This command updates the "GPA" column to 3.7 for the row where the "Name" is "John Doe".

  4. DELETE: The DELETE command is used to remove rows from a table. The syntax for deleting data from a table is:

    DELETE FROM table_name WHERE condition;

    For example, to delete all students with a GPA less than 2.0 from the "Students" table, we might use the following command:

    DELETE FROM Students WHERE GPA < 2.0;  

Related questions

0 votes
1 answer 221 views
0 votes
1 answer 143 views
0 votes
1 answer 144 views
0 votes
1 answer 159 views
0 votes
1 answer 128 views
0 votes
1 answer 118 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...