SQL

SQL (Structured Query Language) is a domain-specific language used in programming and designed for managing data held in a relational database management system (RDBMS), SQL is used to communicate with a database. According to ANSI (American National Standards Institute), It is a standard language for storing, manipulating and retrieving data in databases. It is particularly useful in handling structured data where there are relations between different entities/variables of the data. SQL introduced the concept of accessing many records with one single command; and second, it eliminates the need to specify how to reach a record, e.g. with or without an database index. Some common relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access, MySQL, etc. Although most database systems use SQL, most of them also have their own additional proprietary extensions that are usually only used on their system. However, the standard SQL commands such as \”Select\”, \”Insert\”, \”Update\”, \”Delete\”, \”Create\”, and \”Drop\” can be used to accomplish almost everything that one needs to do with a database.

Table Basics

A relational database system contains one or more objects called tables. The data or information for the database are stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows. Columns contain the column name, data type, and any other attributes for the column. Rows contain the records or data for the columns. Here is a sample table called \”weather\”.

city, state, high, and low are the columns. The rows contain the data for this table:

Weather
city state high low
City A State A 105 90
City B State A 101 92
City C State A 88 69
City D State B 77 60
City E State C 80 72

What is Relational Database?

Relational database means the data is stored as well as retrieved in the form of relations (tables). The relational database with only one relation called STUDENT which stores ROLL_NONAMEADDRESSPHONE and AGE of students.

STUDENT

ROLL_NO NAME ADDRESS PHONE AGE
1 RAM DELHI 9000000001 88
RAMESH GURGAON 9000000002 55
3 SUJIT ROHTAK 9000000003 65
4 SURESH DELHI 9000000004 15

 These are some important terminologies that are used in terms of relation.

Attribute:
Attributes are the properties that define a relation. e.g.; ROLL_NONAME etc.

Tuple:
Each row in the relation is known as tuple. The above relation contains 4 tuples, one of which is shown as:

1 RAM DELHI 9000000001 18

Degree:
The number of attributes in the relation is known as degree of the relation. The STUDENT relation defined above has degree 5.

Cardinality:
The number of tuples in a relation is known as cardinality. The STUDENT relation defined above has cardinality 4.

Column:
Column represents the set of values for a particular attribute. The column ROLL_NO is extracted from relation STUDENT.

Basics of SQL Commands

  • SQL commands are a set of instructions that are used to interact with the database like Sql Server, MySql, Oracle etc. SQL commands are responsible to create and to do all the manipulation on the database. These are also responsible to give/take out access rights on a particular database

Sql Commands Category

We have different sql commands for different-different purpose. We can grouped Sql Commands into five major categories depending on their functionality.

  1. Data Definition Language (DDL)
    These SQL commands are used to create, modify, and drop the structure of database objects like table, view, procedure, indexes etc. In this category we have CREATE, ALTER, DROP and TRUNCATE commands.
    Note
    Only with DDL commands we need to write keyword like (table, procedure, view, index, function) with the syntax of command.
    These commands are used to create/modify the structure of the database object.
  2. Data Manipulation Language (DML)
    These SQL commands are used to store, modify, and delete data from database tables. In this category we have INSERT, UPDATE, and DELETE commands.
  1. Data Query Language (DQL)
    These SQL commands are used to fetch/retrieve data from database tables. In this category we have only SEELCT command.
  1. Transaction Control Language (TCL)
    These SQL commands are used to handle changes which affect the data in database. Basically we use these commands with in the transaction or to make a stable point during changes in database at which we can rollback the database state if required. In this category we have SAVEPOINT, ROLLBACK and COMMIT commands.
  1. Data Control Language (DCL)
    These SQL commands are used to implement security on database objects like table, view, stored procedure etc. In this category we have GRANT and REVOKE commands.

SQL commands are a set of instructions that are used to interact with the database like Sql Server, MySql, Oracle etc. SQL commands are responsible to create and to do all the manipulation on the database. These are also responsible to give/take out access rights on a particular database

Scroll to Top