sql
  1. sql-update-date

SQL INSERT, UPDATE, and DELETE UPDATE DATE

INSERT Statement

Syntax

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

Example

INSERT INTO students (id, name, age)
VALUES (1, 'John Doe', 25);

Output

The above query will insert a new record with id=1, name='John Doe', and age=25 in the table 'students'.

Explanation

The INSERT statement is used to insert new records into a table. The columns that are being inserted into, and the values for those columns, are specified in the VALUES clause.

Use

The INSERT statement is used to add new rows to a database table.

Important Points

  • The column names and values in the VALUES clause must be in the same order.
  • If you omit a column from the column list, you must also omit its value from the VALUES clause.
  • The data types of the values in the VALUES clause must match the data types of the columns they are being inserted into.

UPDATE Statement

Syntax

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

Example

UPDATE students
SET age = 26
WHERE id = 1;

Output

The above query will update the age of the student with id=1 to 26.

Explanation

The UPDATE statement is used to modify existing records in a table. The columns that are being updated, and their new values, are specified in the SET clause. The rows to be updated are specified in the WHERE clause.

Use

The UPDATE statement is used to modify existing rows in a database table.

Important Points

  • If you omit the WHERE clause, all rows in the table will be updated.
  • If you specify multiple columns in the SET clause, separate them with commas.
  • The data types of the values in the SET clause must match the data types of the columns they are updating.

DELETE Statement

Syntax

DELETE FROM table_name WHERE condition;

Example

DELETE FROM students WHERE id = 1;

Output

The above query will delete the student with id=1 from the table 'students'.

Explanation

The DELETE statement is used to delete records from a table. The rows to be deleted are specified in the WHERE clause.

Use

The DELETE statement is used to remove existing rows from a database table.

Important Points

  • If you omit the WHERE clause, all rows in the table will be deleted.
  • Be careful when using the DELETE statement, as it permanently removes data from the database. It is recommended to always have a backup of the data before executing a DELETE statement.

Summary

  • The INSERT statement is used to add new rows to a database table.
  • The UPDATE statement is used to modify existing rows in a database table.
  • The DELETE statement is used to remove existing rows from a database table.
  • All three statements require a table name and a WHERE clause to specify which rows are affected.
Published on: