You are on page 1of 7

SQL (structured Query Language)

SQL (structured Query Language) is a language which


helps in organizes, managing and retrieving data in database. It was
first developed by IBM in the early 1970’s .In early 1986 this was
accepted as query language for the relational model. With the
structure Query Language, or SQL, you tell Oracle which
information you want it to select, insert, update or delete. In fact,
these for verbs are the primary words you will use to give oracle
instructions.

Features of SQL:-
 Ease of use- It is made up of simple English sentences that
convey meaning of the statement clearly. Being interactive in
nature, it allows users to build complex queries easily.

 Portability- Since RDBMS products are available on almost


all hardware platforms requires very little changes.

SQL commands can be classified in to three categories:-

 DDL (Data Description Language): These allow data structure to be


created, modified, or deleted, that is, they manage the data in the data
dictionary.

 DML (Data Manipulation Language): These allow data to be


inserting, update delete or viewed.

 DCL (Data Control Language): These are used to set up the data
base security involving management of user and their privileges .
Data Type in SQL :-
The following data types are supported by the SQL.

Number – The number data type is used to store numbers of virtually


any magnitude may as 9099*10 to the power 124, i.e.1 followed by
125 Zeroes can be stored.

Varchar- Values of this data type are variable length character string of
maximum length 2000.

Long- Long can be store variable length character strings containing


Unto 65535 characters. Long data can be used to store arrays of
Binary data in ASCII format.

Date- The standard format is DD-MM-YY as in 13-nov-87. To enter


Dates other than the standard date in 24 hours format. By
Default, the time in a date 12:00:00 Am., if no time portion is
Specified. The default date field is the current month.

Char-Values of this data type are fixed length character strings of maximum
length 255 characters.

Constraints:-

There are many types of Constraints that can be apply on tables as


well columns. Most commonly used are as follows.

 Primary Key constraint-


A Primary key is one or more columns in a table Used
to uniquely identify each row in the table. Primary Key must
not be null and must be unique across the column. A
Multicolumn primary key is called composite key.
 Unique Constraint-
A unique key is similar to a primary key except that the
purpose of a unique key is to ensure that information in the
column for each record is unique, as with telephone number or
driver’s license number. A table may have many unique keys.

 Not null constraint-


This constraint restrict the user not to enter null value For
the column specified as not null constraint.

 Check constraint-
Use this constraint when you need to enforce Integrity Rules
that can be evaluated based on a logical Expression. Never use
Check constraints if the constraints can be defined using thee
not null, primary key or foreign Key constraint.

1. Command : create
Purpose: To create table.
Syntax: CREATE TABLE <table name>;
Example: Create table employee.
This command will create the table employee.

2. Command : Insert
Purpose: To insert insert a single or of data into a table.
Syntax: INSERT INFO<table name> VALUES (expression);
Example: Insert into employee values (111,’xyz’, 10);
Eno. =111, Ename=xyz and DeptNo.=10
This command will insert the record in table employee having
Values

3. Command: Update
Purpose: TO update table.
Syntax: UPDATE<tablename> set columnname=expression
Where columnName=expression;
Example: Update employee set DeptNo=20 where Eno.111;
His command will update the value of department No. where
Employee No. equals to 111.

4. Command: Delete
Purpose: To deletes all records from table.
Syntax: DELETE FROM <tablename>;
Example: delete from employee;
This command will delete all the rows of employees table.

5. Command: select
Purpose: to extract data globally.
Syntax: SELECT*FROM<table name>;
Example: select*from employee;

This command will extract all the record from employee tale. We can
Give condition clause to restrict the data extraction according to given
criteria

6. Command: Alter or modify


Purpose: To add change columns
Syntax: ALTER TABLE<table name>ADD (new column data type (size)
…);
Example: Alter table employee adds (address varchar (20));
This command will add the new column address to the employee table.

7. Command : Drop
Purpose: To delete the table table.
Syntax: DROP TABLE <table name>;
Example: Drop table employee;
This command will delete the data of table employee as well as its
description.
8. Command: Order By
Purpose: To change the ascending/descending order of output.
Syntax: SELECT*FROM<table name>ORDER BY<field name>;
Example: select*from employee Order By salary;
This command will show the all records of employee table in
Ascending order.

9. Command: Join (Equi Join)


Purpose: To join multiple relational tables.
Syntax: Select<field names…>from<tables names…> WHERE
Table1.field name=table2.field name;

Example: Select Eno, Dep, dname from employee department where


employee.deptNo. =depertment.dpNo;

10. Command: truncate


Purpose: To delete the data of table only.
Syntax: TRUNCATE TABLE<tablename>;
Example: truncate table employee;
This command will delete all the rows of employee table without effecting
The table description.

1. Create table EMP (Eno.chacter (5), Ename character (30), age


integer, basic integer);

(i) Select *from EMP

ENo. EName Age Basic


1 Amit 17 5000
2 Arun 17 8000
3 Ritu 16 8000
4 John 16 6000
(ii) Select age from EMP

17
17
16
16

(iii) Select distinct age from EMP

Age
17
16

(iv) Select ENO, Ename from EMP Where Basic>6000

ENo EName
2 Aman
3 Ritu

(iv) Select Ename, Basic from EMP Order by Basic Asc

EName Basic
Amit 5000
John 6000
Aman 8000
Ritu 8000
(v) Select Ename, Basic from EMP Where Basic Between 5500 and
8000.

EName Basic
Aman 8000
Ritu 8000
John 6000

(vi) select * from EMP Where Basic in (5000,6000,7000)

ENo EName Age Basic


1 Amit 17 5000
4 John 16 6000

You might also like