Common SQL commands:

  SQL (Structured Query Language) is a powerful language used for managing and manipulating relational databases. Some of the most common SQL commands are:

 

1.       SELECT: Retrieves data from one or more tables.

 SELECT column1, column2 FROM table_name WHERE condition;

2.       INSERT: Inserts new records into a table.

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

3.       UPDATE: Modifies existing records in a table.

 UPDATE table_name SET column1 = value1 WHERE condition;

4.       DELETE: Removes records from a table.

 DELETE FROM table_name WHERE condition;

5.       CREATE TABLE: Creates a new table in the database.

 CREATE TABLE table_name ( column1 datatype, column2 datatype, ... );

6.       ALTER TABLE: Modifies an existing table structure.

 ALTER TABLE table_name ADD column_name datatype; ALTER TABLE table_name DROP COLUMN column_name;

7.       DROP TABLE: Deletes an existing table and its data.

 DROP TABLE table_name;

8.       CREATE INDEX: Creates an index on a table column to improve query performance.

 CREATE INDEX index_name ON table_name (column_name);

9.       DROP INDEX: Deletes an index from a table.

 DROP INDEX index_name;

10.   JOIN: Retrieves data from multiple tables based on a related column between them.

SELECT column1, column2 FROM table1 JOIN table2 ON table1.column_name = table2.column_name;

11.   GROUP BY: Groups rows that have the same values into summary rows.

 SELECT column1, COUNT(*) FROM table_name GROUP BY column1;

12.   ORDER BY: Sorts the result set in ascending or descending order.

 SELECT column1, column2 FROM table_name ORDER BY column1 ASC;

13.   HAVING: Used with the GROUP BY clause to filter groups based on a specified condition.

 SELECT column1, COUNT(*) FROM table_name GROUP BY column1 HAVING COUNT(*) > 1;


These are some of the fundamental SQL commands, but SQL is a rich language with many other commands and functions for managing and querying databases.


Comments

Popular posts from this blog

Chapter 7 MCQ's first Year computer science