DEV Community

eveline philipia
eveline philipia

Posted on

Essential SQL Commands

SQL (Structured Query Language) is a programming language used to manage and manipulate data in a relational database management system (RDBMS). Here are some essential SQL commands:

SELECT: The SELECT statement retrieves data from one or more tables. It is used to query the database and retrieve specific data.

INSERT: The INSERT statement is used to insert data into a table.

UPDATE: The UPDATE statement is used to update data in a table.

DELETE: The DELETE statement is used to delete data from a table.

CREATE TABLE: The CREATE TABLE statement is used to create a new table in the database.

DROP TABLE: The DROP TABLE statement is used to delete an existing table from the database.

ALTER TABLE: The ALTER TABLE statement is used to modify the structure of an existing table.

CREATE INDEX: The CREATE INDEX statement is used to create an index on a table, which improves the speed of data retrieval.

GROUP BY: The GROUP BY statement is used to group the result set by one or more columns.

ORDER BY: The ORDER BY statement is used to sort the result set by one or more columns.

WHERE: The WHERE clause is used to filter data based on a specified condition.

JOIN: The JOIN statement is used to combine rows from two or more tables based on a related column between them.

DISTINCT: The DISTINCT keyword is used to return only distinct (unique) values from a result set.

COUNT: The COUNT function is used to return the number of rows in a table or the number of rows that match a specific condition.

AVG, SUM, MIN, and MAX: These are aggregate functions used to perform calculations on a set of values.

SELECT: The SELECT statement is used to retrieve data from one or more tables. It is the most commonly used command in SQL, and it allows you to specify the columns you want to retrieve and any filtering or sorting criteria.
For example:

SELECT column1, column2 FROM table_name WHERE condition;

INSERT: The INSERT statement is used to insert new data into
a table.
You specify the table and the values you want to insert.
For example:

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

UPDATE: The UPDATE statement is used to modify existing data in a table. You specify the table, the columns you want to update, and the new values. You can also include a WHERE clause to specify which rows to update.
For example:

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

DELETE: The DELETE statement is used to delete data from a table. You specify the table and a WHERE clause to specify which rows to delete. For example:
DELETE FROM table_name WHERE condition;

CREATE TABLE: The CREATE TABLE statement is used to create a new table in the database. You specify the table name and the columns, their data types, and any constraints.
For example:

CREATE TABLE table_name (
column1 data_type constraint,
column2 data_type constraint,
...
);

DROP TABLE: The DROP TABLE statement is used to delete an existing table from the database. You specify the table name. For example:

DROP TABLE table_name;
ALTER TABLE: The ALTER TABLE statement is used to modify the structure of an existing table. You can add

Top comments (0)