SQL Commands
SQL Commands
SQL Commands
What is SQL?
SQL is Structured Query Language, which is a computer language for storing, manipulating and
retrieving data stored in relational database.
SQL is the standard language for Relation Database System. All relational database management
systems like MySQL, MS Access, Oracle, Sybase, Informix, postgres and SQL Server use SQL
as standard database language.
Why SQL?
• Allows users to access data in relational database management systems.
• Allows users to define the data in database and manipulate that data.
• Allows to embed within other languages using SQL modules, libraries & pre-compilers.
What is RDBMS?
RDBMS stands for Relational Database Management System. RDBMS is the basis for SQL and
for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft
Access.
2
What is table ?
The data in RDBMS is stored in database objects called tables. The table is a collection of related
data entries and it consists of columns and rows.
Remember, a table is the most common and simplest form of data storage in a relational database.
What is field?
Every table is broken up into smaller entities called fields. The fields in the CUSTOMERS table
consist of ID, NAME, AGE, ADDRESS and SALARY.
A field is a column in a table that is designed to maintain specific information about every record
in the table.
What is column?
A column is a vertical entity in a table that contains all information associated with a specific
field in a table.
It is very important to understand that a NULL value is different than a zero value or a field that
contains spaces. A field with a NULL value is one that has been left blank during record creation.
SQL Constraints:
Constraints are the rules enforced on data columns on table. These are used to limit the type of
data that can go into a table. This ensures the accuracy and reliability of the data in the database.
3
Constraints could be column level or table level. Column level constraints are applied only to one
column where as table level constraints are applied to the whole table.
SQL Syntax:
SQL is followed by unique set of rules and guidelines called Syntax. This tutorial gives you a
quick start with SQL by listing all the basic SQL Syntax:
All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE,
DELETE, ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon
(;).
Important point to be noted is that SQL is case insensitive which means SELECT and select have
same meaning in SQL statements but MySQL make difference in table names. So if you are
working with MySQL then you need to give table names as they exist in the database.
COMMANDS:
SQL commands are instructions, coded into SQL statements, which are used to
communicate with the database to perform specific tasks, work, functions and queries with
data.
SQL commands can be used not only for searching the database but also to perform various
other functions like, for example, you can create tables, add data to tables, or modify data,
drop the table, set permissions for users. SQL commands are grouped into four major
categories depending on their functionality:
• Data Definition Language (DDL) - These SQL commands are used for creating,
modifying, and dropping the structure of database objects. The commands are
CREATE, ALTER, DROP, RENAME, and TRUNCATE.
• Data Manipulation Language (DML) - These SQL commands are used for
storing, retrieving, modifying, and deleting data.
These Data Manipulation Language commands
are: SELECT, INSERT, UPDATE, and DELETE.
• Transaction Control Language (TCL) - These SQL commands are used for
managing changes affecting the data. These commands are COMMIT,
ROLLBACK, and SAVEPOINT.
• Data Control Language (DCL) - These SQL commands are used for providing
security to database objects. These commands are GRANT and REVOKE.
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
GROUP BY column_name;