SQL Commant A1
SQL Commant A1
SQL Commant A1
Introduction
SQL stands for Structured Query Language. SQL commands are the
instructions used to communicate with a database to perform tasks, functions,
and queries with data.
SQL commands can be used to search the database and to do other functions
like creating tables, adding data to tables, modifying data, and dropping tables.
Here is a list of basic SQL commands (sometimes called clauses) you should
know if you are going to work with SQL
❖ DDL (Data Definition Language)
The DDL Commands in Structured Query Language are used to create and
modify the schema of the database and its objects. The syntax of DDL
commands is predefined for describing the data. The commands of Data
Definition Language deal with how the data should exist in the database.
o CREATE
o ALTER
o DROP
o TRUNCATE
• CREATE Command
Syntax :
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]
);
Example:
It is used to delete both the structure and record stored in the table.
Syntax :
Example :
Syntax:
Example :
• TRUNCATE Command
It is used to delete all the rows from the table and free the space containing
the table.
The TRUNCATE TABLE command deletes the data inside a table, but not
the table itself.
Syntax:
Example:
DML commands are used to modify the database. It is responsible for all form
of changes in the database.The command of DML is not auto-committed that
means it can't permanently save all the changes in the database. They can be
rollback.
o INSERT
o UPDATE
o DELETE
• INSERT Command
The INSERT statement is a SQL query. It is used to insert data into the
row of a table.
1. Insert a single row into a table
2. Insert multiple rows into a table
3. Copy rows from a table to another table.
Syntax :
Example :
The power of the UPDATE command lies in its versatility. Whether you’re
dealing with small changes or massive data modifications, this function can
handle it all without breaking a sweat. But don’t let its power intimidate you;
once you understand how SQL UPDATE works and follow some simple
syntax rules, I believe you’ll find it surprisingly easy to use.
• Select the column (or columns) we want to update with new values via the
SET clause
• Optionally we can use a WHERE clause to limit the scope of the records
updated
Syntax:
Example :
UPDATE students
SET User_Name = 'Sonoo'
WHERE Student_Id = '3'
• DELETE Command
Syntax:
Example :
DCL commands are used to grant and take back authority from any
database user.
• DCL allows the administrator to control access to the data in the database.
• DCL commands permit to set the roles and permissions for different users.
• DCL commands can restrict or deny access to certain parts of the database.
• DCL ensures authorized access to sensitive data and maintains data security
& integrity.
o Grant
o Revoke
Example :
Syntax:
Example :
These operations are automatically committed in the database that's why they
cannot be used while creating tables or dropping them.
o COMMIT
o ROLLBACK
o SAVEPOINT
o
Syntax:
COMMIT;
Example:
DELETE FROM CUSTOMERS
WHERE AGE = 25;
COMMIT;
Syntax:
ROLLBACK;
Example:
DELETE FROM CUSTOMERS
WHERE AGE = 25;
ROLLBACK;
DQL statements are used for performing queries on the data within schema
objects. The purpose of the DQL Command is to get some schema relation
based on the query passed to it. We can define DQL as follows it is a
component of SQL statement that allows getting data from the database and
imposing order upon it. It includes the SELECT statement.
SELECT
Syntax:
SELECT expressions
FROM TABLES
WHERE conditions;
Example:
SELECT emp_name
FROM employee
WHERE age > 20;
❖ Conclusion
The breadth and scope of the SQL commands provide the capability to create
and manipulate a wide variety of database objects using the
various CREATE, ALTER, and DROP commands. Those database objects then
can be loaded with data using commands such as INSERT. The data can be
manipulated using a wide variety of commands, such as SELECT, DELETE,
and TRUNCATE, as well as the cursor commands,
DECLARE, OPEN, FETCH, and CLOSE. Transactions to manipulate the data
are controlled through the SET command, plus
the COMMIT and ROLLBACK commands. And finally, other commands
covered in this chapter include those that control a user’s access to database
resources through commands such as GRANT and REVOKE.
❖ Reference
https://levelup.gitconnected.com/
https://learn.microsoft.com
https://www.bing.com/