This article describes introduction to SQL, basic overview of SQL. Summary of the article:
- What is SQL?
- Why we should Use SQL?
- SQL Statements
- SQL Commands
- SQL Functions
What is SQL?
Structured Query Language or SQL is a one kind of programming language used to handle data in Relational Database Management System (RDMS) like Oracle, SQL Server, MySQL, Sybase, DB2, DB/400 etc. It is designed specifically for communicating with databases. SQL is an ANSI (American National Standards Institute) standard.
SQL invented at IBM in 1974 by Donald D. Chamberlin and Raymond F. Boyce.
Why we should Use SQL?
- SQL is not designed for a specific database vendor. Almost every major DBMS supports SQL. So learning this one language any programmer can interact with any database like ORACLE, SQL, MYSQL etc.
- SQL is easy to learn. All the statements are all made up of descriptive English words.
- SQL is a very powerful language and by using this anyone can perform very complex and sophisticated database operations.
SQL Statements done most of the operation on database. A simple SQL Statements to select all the records of a table is given bellow:
SELECT * FROM Students;
SQL statement is NOT case sensitive.
At the end of each SQL statement Some database require a semicolon. It is the standard way to separate each SQL statement. It help us to execute more than one statement in the same time.
Some Important SQL Commands are as follows:
- SELECT – extracts data from a database
- UPDATE – updates data in a database
- DELETE – deletes data from a database
- INSERT INTO – inserts new data into a database
- CREATE DATABASE – creates a new database
- ALTER DATABASE – modifies a database
- CREATE TABLE – creates a new table
- ALTER TABLE – modifies a table
- DROP TABLE – deletes a table
- CREATE INDEX – creates an index
- DROP INDEX – deletes an index
SQL has many built-in functions to perform calculations on data.
SQL Aggregate Functions
This functions return a single value calculated from values in a column. Some Useful aggregate functions are given bellow:
- AVG() – Returns the average value
- COUNT() – Returns the number of rows
- FIRST() – Returns the first value
- LAST() – Returns the last value
- MAX() – Returns the largest value
- MIN() – Returns the smallest value
- SUM() – Returns the sum
SQL Scalar Functions
This functions return a single value based on the input value. Some Useful scalar functions are given bellow:
- UCASE() – Converts a field to upper case
- LCASE() – Converts a field to lower case
- MID() – Extract characters from a text field
- LEN() – Returns the length of a text field
- ROUND() – Rounds a numeric field to the number of decimals specified
- NOW() – Returns the current system date and time
- FORMAT() – Formats how a field is to be displayed
That’s all about SQL.