DEV Community

Avinash Kumar
Avinash Kumar

Posted on

Some Common SQL commands!

SQL (Structured Query Language) is a programming language used to manage and manipulate data stored in relational database management systems (RDBMS). It is a standard language used to perform various operations on databases, such as creating new tables, inserting data, updating data, and deleting data.

In this blog, we will discuss some of the most common SQL commands that are used to manage and manipulate data in a database.

SELECT
The SELECT command is used to retrieve data from a database. It allows you to specify the columns that you want to retrieve, as well as the rows that meet certain criteria.

For example, the following SQL statement retrieves all the rows from the "Customers" table, and displays the "CustomerName" and "City" columns:

SELECT CustomerName, City FROM Customers;

Enter fullscreen mode Exit fullscreen mode

You can also use the WHERE clause to specify criteria for selecting rows. For example, the following SQL statement retrieves all the rows from the "Customers" table where the "Country" is "Germany":

SELECT * FROM Customers WHERE Country='Germany';

Enter fullscreen mode Exit fullscreen mode

UPDATE
The UPDATE command is used to modify data in a database. It allows you to change the values of specific columns in a table.

For example, the following SQL statement updates the "Address" and "City" columns in the "Customers" table for the customer with the "CustomerID" of 1:

UPDATE Customers
SET Address='Tverskoy Boulevard, 32', City='Moscow'
WHERE CustomerID=1;

Enter fullscreen mode Exit fullscreen mode

DELETE

The DELETE command is used to delete data from a database. It allows you to remove specific rows or all rows from a table.
For example, the following SQL statement deletes the row with the "CustomerID" of 4 from the "Customers" table:

DELETE FROM Customers WHERE CustomerID=4;

Enter fullscreen mode Exit fullscreen mode

If you want to delete all rows from a table, you can use the TRUNCATE TABLE command. For example:

TRUNCATE TABLE Customers;

Enter fullscreen mode Exit fullscreen mode

INSERT INTO

The INSERT INTO command is used to insert new data into a database. It allows you to add one or more rows to a table.

For example, the following SQL statement inserts a new row into the "Customers" table:

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

Enter fullscreen mode Exit fullscreen mode

CREATE DATABASE

The CREATE DATABASE command is used to create a new database.

For example, the following SQL statement creates a new database called "MyDatabase":

CREATE DATABASE MyDatabase;

Enter fullscreen mode Exit fullscreen mode

ALTER DATABASE

The ALTER DATABASE command is used to modify a database. It allows you to change the name of a database, as well as other characteristics such as the file location and the maximum size.

For example, the following SQL statement changes the name of the "MyDatabase" database to "NewDatabase":

ALTER DATABASE MyDatabase
MODIFY NAME = NewDatabase;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)