sql
  1. sql-commands

SQL Syntax Commands

SQL (Structured Query Language) is a standard language for managing relational databases. In this page, we will cover various SQL Syntax Commands, their syntax, examples, outputs, explanations, uses, important points, and summaries.

SELECT Command

The SELECT command is used to retrieve data from a table in the database.

Syntax

SELECT column1, column2, ..., columnN
FROM table_name;

Example

SELECT * FROM employees;

Output

employee_id first_name last_name salary
1 John Doe 5000
2 Jane Smith 6000
3 Mark Johnson 7000

Explanation

In the above example, we used the SELECT command to retrieve all the columns from the employees table.

Use

The SELECT command is widely used in SQL queries to retrieve data from the database.

Important Points

  • The SELECT command is case-insensitive.
  • The column names in the SELECT command are separated by commas.
  • The asterisk (*) represents all the columns of the table.

Summary

The SELECT command is used to retrieve data from a table in the database. It has a simple syntax and is widely used in SQL queries.

INSERT Command

The INSERT command is used to insert data into a table in the database.

Syntax

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

Example

INSERT INTO employees (first_name, last_name, salary)
VALUES ('Sarah', 'Johnson', 8000);

Output

The INSERT command does not have any output. It adds a new row or rows to the table.

Explanation

In the above example, we used the INSERT command to insert a new row into the employees table.

Use

The INSERT command is used to add new data to a table in the database.

Important Points

  • The column names in the INSERT command are optional.
  • The values in the INSERT command must match the data type of the columns.
  • The order of the column names in the INSERT command must match the order of the values.

Summary

The INSERT command is used to insert new data into a table in the database. It has a simple syntax and is widely used in SQL queries.

UPDATE Command

The UPDATE command is used to update data in a table in the database.

Syntax

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

Example

UPDATE employees
SET salary = 9000
WHERE employee_id = 1;

Output

The UPDATE command does not have any output. It updates one or more rows in the table.

Explanation

In the above example, we used the UPDATE command to update the salary of an employee where the employee ID is 1.

Use

The UPDATE command is used to modify existing data in a table in the database.

Important Points

  • The UPDATE command must have a WHERE clause to specify which rows to update.
  • The SET keyword is used to specify the new values of the columns.
  • The WHERE clause is used to specify the conditions to identify which rows to update.

Summary

The UPDATE command is used to modify existing data in a table in the database. It has a simple syntax and is widely used in SQL queries.

DELETE Command

The DELETE command is used to delete data from a table in the database.

Syntax

DELETE FROM table_name
WHERE condition;

Example

DELETE FROM employees
WHERE employee_id = 2;

Output

The DELETE command does not have any output. It deletes one or more rows from the table.

Explanation

In the above example, we used the DELETE command to delete an employee where the employee ID is 2.

Use

The DELETE command is used to remove data from a table in the database.

Important Points

  • The DELETE command must have a WHERE clause to specify which rows to delete.
  • The WHERE clause is used to specify the conditions to identify which rows to delete.

Summary

The DELETE command is used to remove data from a table in the database. It has a simple syntax and is widely used in SQL queries.

Published on: