Understanding SQL command is essential for working with databases. SQL command allows user to retrieve, manipulate, and manage data stored in the databases. It include commands like SELECT, INSERT, UPDATE, DELETE, CREATE and DROP etc.
SQL command is also referred to as "SQL statement".
A set of SQL command/statement used to retrieve data from a database is known as a "SQL query".
1. Data Definition Language (DDL)
2. Data Manipulation Language (DML)
3. Data Query Language (DQL)
"CREATE" command is used to create a new database object such as a tables, functions, views and stored procedure. Here's is an example of creating [SQL Tutorial] table -
CREATE TABLE [SQL Tutorial] ( Sno INT PRIMARY KEY, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50), Age INT CHECK (age > 18), Gender VARCHAR(10) CHECK (gender IN ('Male', 'Female')), Salary DECIMAL(18,2) );
"DROP" command is used to delete a database object. Here's is an example of removing [SQL Tutorial] table -
DROP TABLE [SQL Tutorial];
"ALTER" command is used to modify the structure of an existing database object. Here's is an example of modifying the structure of the existing [SQL Tutorial] table -
ALTER TABLE [SQL Tutorial] ADD Address VARCHAR(100);
"TRUNCATE" command is used to remove all data from a table, while keeping the table structure intact. Here's is an example of removing all data from [SQL Tutorial] table -
TRUNCATE TABLE [SQL Tutorial];
"INSERT" command is used to add new data to a table. Here's is an example of adding new records in [SQL Tutorial] table -
INSERT INTO [SQL Tutorial] ( FirstName, Age ) VALUES ('Mike', 25), ('Tim', 35), ('Jim', 40);
"UPDATE" command is used to modify existing data in a table. Here's is an example modifying existing data in [SQL Tutorial] table -
UPDATE [SQL Tutorial] SET Gender = 'Male';
"DELETE" command is used to remove data from a table. Here's is an example removing data from [SQL Tutorial] table -
DELETE FROM [SQL Tutorial] WHERE Age = 25;
"SELECT" command is used to retrieve data from one or more tables in a database. This command is the most commonly used command and is considered as the backbone of SQL. It is essential to understand this command in order to effectively work with relational databases. Here's is an example retrieving data from [SQL Tutorial] table -
SELECT * FROM [SQL Tutorial];
The 5 basic SQL commands are: SELECT, INSERT, UPDATE, DELETE, and CREATE.
An SQL command is a statement used to perform operations on a database, such as querying data or modifying its structure.
DDL (Data Definition Language) is for defining the structure of the database, DML (Data Manipulation Language) is for managing data within the database, and DCL (Data Control Language) is for controlling access and permissions in the database.
SQL (Structured Query Language) is a domain-specific language used for managing relational databases, with types including MySQL, PostgreSQL, SQL Server, Oracle, etc.