What is SQL (Structured Query Language)?
SQL is an ANSI (American National Standard Institute) standard computer language for accessing and manipulating database systems. SQL statements are used to retrieve and update the data in the database. They are not case-sensitive in nature.
Some key points to write better SQL queries:
- Use pascal notation for object name. Example: Products, Customers
- Use the singular form of nouns for the Column name. Example: FirstName, Address
- Each table must have a primary key.
- Use upper case for all SQL keywords. Example: SELECT, UPDATE, INSERT, DELETE
- Do not use white space in identifiers.
- Use parentheses to increase readability.
- Indent code to improve readability.
- Use ANSI joins instead of old-style joins.
- Do not use SELECT *
- Always use table aliases when your SQL statement involves more than one table.
- Do not use column numbers in the ORDER BY clause.
- Always use column list in INSERT statements.
These key points might be confusing for you because we have not started learning how to write SQL queries access and insert data in our database. But before moving to that, it is important for us to understand components of SQL
Components of SQL.
SQL is divided into four different components. Let us understand each of them one by one:
DDL (Data Definition Language).
Data Definition Language deals with the structure of Database objects and commands are CREATE, ALERT, TRUNCATE, DROP.
- CREATE: used to create new Database objects like table, view, and stored procedure.
- ALERT: used to modify the existing structure of the database objects.
- TRUNCATE: used to remove all the data from database objects.
- DROP: used to remove the database object from the database.
- RENAME: used to change the name of the existing object.
DML (Data Manipulation Language).
Data Manipulation Language deals with the manipulation of the data in the Database objects and the commands are SELECT, INSERT, UPDATE.
- INSERT: used to insert data into a table.
- UPDATE: used to update existing data within a table.
- DELETE: used to delete records from the table.
TCL (Transaction Control Language).
Transaction Control Language deals with transaction management and the commands are COMMIT, ROLLBACK.
- COMMIT: used to end the current transaction by making all pending data changes permanent.
- ROLLBACK: used to ends the current transaction by discarding all pending data changes.
- SAVEPOINT: used to mark a savepoint within the current transaction.
DCL (Data Control Language).
Data Control Language deals with providing access privilege of the data by using command GRANT, REVOKE.
- GRANT: used to give user access privilege to the database.
- REVOKE: used to revert back the user access privilege to the database.
DQL (Data Query Language).
DQL command is used to perform quarries to fetch the data from the database within the schema object. We can use the DQL command with JOIN to get the data from multiple tables at one time using Primary key and Foreign key relations. Example: SELECT
So these are the few important components of SQL and in our further articles, we are going to learn the syntax of all the SQL commands with their practical examples.
No comments:
Post a Comment