Adarsh College, Vita
Department of BCA
Presentation
On
Introduction to SQL
By
Asst.Prof.Ghorpade D.L
Objectives
• Explore basic commands and functions of
SQL
• How to use SQL for data administration (to
create tables, indexes, and views)
• How to use SQL for data manipulation (to
add, modify, delete, and retrieve data)
• How to use SQL to query a database to
extract useful information
Introduction to SQL
• SQL functions
 Data definition
User define the structure.
 Data retrieval
User retrieve stored data from the database.
 Data manipulation
User to update database by adding new data,
removing old data and modifying previously
stored data.
 Access Control
Restricting user’s unauthorized access.
 Data sharing
Data sharing by concurrent users.
 Data integrity
Protecting it from corruption due to
inconsistent updates or system failures
SQL Data Types
• Character Data Type
 CHAR(size)
Fixed length character data of length size
bytes. This should be used for fixed length data.
2000 bytes Default and minimum size is 1 byte.
 VARCHAR2(size)
Variable length character string having
maximum length size bytes. You must specify size.
4000 bytes minimum is 1
 NVARCHAR2(size)
Variable length national character set string
having maximum length size bytes. You must specify
size. 4000 bytes minimum is 1.
 NCHAR(size)
Fixed length national character set data of
length size bytes. This should be used for fixed length
data. Such as codes A100, B102... 2000 bytes Default
and minimum size is 1 byte.
• Numeric Data Type
 NUMBER(p,s)
Number having precision p and scale s. The
precision p can range from 1 to 38. The scale s can
range from -84 to 127.
 INTEGER or INT
A 64-bit signed integer value with an implied
scale of zero.
 FLOAT(p)
A single or double precision floating point
number value ,precision up to a maximum of 64. 7
 DECIMAL [(p[,s])] or DEC [(p[,s])]
 DECIMAL - Precision defaults to 38,Scale
defaults to zero.
 DECIMAL (p)- Scale defaults to zero.
DECIMAL (p,s)- Precision & Scale are defined by
user.
DATE
Date value should be specified in the form:
YYYY-MM-DD
 TIMESTAMP
Timestamp value should be specified in the form:
YYYY-MM-DD HH:MM:SS
Classification of SQL Commands
1. DDL (Data definition language)
The DDL part of SQL permits database tables
to be created or deleted.
Example
a. CREATE TABLE
b. ALTER TABLE
c. DROP TABLE
d. CREATE INDEX
e. DROP INDEX
f. GRANT
g. REVOKE
2. DML(Data manipulation languages)
It is used to manipulate data through queries
it also change the content of a table.
Examples
a. INSERT : To insert data into table.
b. SELECT : To display data from a table.
c. DELETE : Delete all records from a table, the space for
the record remain.
d. UPDATE : To change the content of a table.
e. LOCK : Table control concurrency.
3. DCL(Data Control languages)
That control access to data and to the
database.
Examples
a. COMMIT : Save work done.
b. SAVEPONT : Indentify a point in a transaction to which
can later rollback.
c. SET TRANSACTION : Change transaction option like
what rollback segment to use.
d. GRANT/REVOKE : grant or take back permission to or
from the oracle user.
4. DQL(Data query languages)
That allows getting data from the database
and imposing ordering upon it.
Examples
a. SELECT : Retrieves data from table.
THE CREATE TABLE COMMAND
The create table command defines each column of
table uniquely. Each column has a minimum three
attributes a name, data type and size.
Rules for creating a table
1. A name can have maximum up to 10 characters.
2. Alphabets from A-Z, a-z and digits 0-9 are allowed.
3. A name should begin with alphabet.
4. Only use special character as _(underscore).
Syntax :
Create table <table name>
(<column name1><data type> (<size>),
< column name2><data type> (<size>));
Example
SQL>create table emp(empno number(4),
ename varchar(10),
job char(10),
mgr number(4),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2));
SQL>Table created
Modifying the structure of Table
1.Adding New Columns
Alter Command
Used to alter structure of DB.
Syntax :
alter table <table name>
add(<newcolumn name><data type> (<size>),
< newcolumn name><data type> (<size>));
Example:
Enter a new field eaddress in the table emp.
SQL> alter table emp
add(eaddress varchar2(30));
SQL> table altered
Modifying the structure of Table
2. Modifying Existing Columns
Alter Command
Only modifying column size can be increased.
Syntax :
alter table <table name>
modify(<newcolumn name><new data type>
(<new size>));
Example:
SQL> alter table emp
modify(ename varchar2(25));
Modifying the structure of Table
3. Dropping an Existing Columns
Alter Command
To drop an existing column.
Example:
SQL> alter table emp drop column city;
• The multiple columns can be dropped in single
command.
SQL> alter table emp drop column (city,address);
Modifying the structure of Table
4. Dropping Tables
Table can be deleted using drop table command.
Syntax :
SQL>drop table tablename;
Example:
SQL>drop table emp;
5.Truncate Command
Removes all records from a table including all space allocated
for the records are removed.
Syntax :
SQL>truncate table tablename;
Example:
SQL>truncate table emp;

Introduction to (sql)

  • 1.
    Adarsh College, Vita Departmentof BCA Presentation On Introduction to SQL By Asst.Prof.Ghorpade D.L
  • 2.
    Objectives • Explore basiccommands and functions of SQL • How to use SQL for data administration (to create tables, indexes, and views) • How to use SQL for data manipulation (to add, modify, delete, and retrieve data) • How to use SQL to query a database to extract useful information
  • 3.
    Introduction to SQL •SQL functions  Data definition User define the structure.  Data retrieval User retrieve stored data from the database.  Data manipulation User to update database by adding new data, removing old data and modifying previously stored data.
  • 4.
     Access Control Restrictinguser’s unauthorized access.  Data sharing Data sharing by concurrent users.  Data integrity Protecting it from corruption due to inconsistent updates or system failures
  • 5.
    SQL Data Types •Character Data Type  CHAR(size) Fixed length character data of length size bytes. This should be used for fixed length data. 2000 bytes Default and minimum size is 1 byte.  VARCHAR2(size) Variable length character string having maximum length size bytes. You must specify size. 4000 bytes minimum is 1
  • 6.
     NVARCHAR2(size) Variable lengthnational character set string having maximum length size bytes. You must specify size. 4000 bytes minimum is 1.  NCHAR(size) Fixed length national character set data of length size bytes. This should be used for fixed length data. Such as codes A100, B102... 2000 bytes Default and minimum size is 1 byte.
  • 7.
    • Numeric DataType  NUMBER(p,s) Number having precision p and scale s. The precision p can range from 1 to 38. The scale s can range from -84 to 127.  INTEGER or INT A 64-bit signed integer value with an implied scale of zero.  FLOAT(p) A single or double precision floating point number value ,precision up to a maximum of 64. 7
  • 8.
     DECIMAL [(p[,s])]or DEC [(p[,s])]  DECIMAL - Precision defaults to 38,Scale defaults to zero.  DECIMAL (p)- Scale defaults to zero. DECIMAL (p,s)- Precision & Scale are defined by user. DATE Date value should be specified in the form: YYYY-MM-DD  TIMESTAMP Timestamp value should be specified in the form: YYYY-MM-DD HH:MM:SS
  • 9.
    Classification of SQLCommands 1. DDL (Data definition language) The DDL part of SQL permits database tables to be created or deleted. Example a. CREATE TABLE b. ALTER TABLE c. DROP TABLE d. CREATE INDEX e. DROP INDEX f. GRANT g. REVOKE
  • 10.
    2. DML(Data manipulationlanguages) It is used to manipulate data through queries it also change the content of a table. Examples a. INSERT : To insert data into table. b. SELECT : To display data from a table. c. DELETE : Delete all records from a table, the space for the record remain. d. UPDATE : To change the content of a table. e. LOCK : Table control concurrency.
  • 11.
    3. DCL(Data Controllanguages) That control access to data and to the database. Examples a. COMMIT : Save work done. b. SAVEPONT : Indentify a point in a transaction to which can later rollback. c. SET TRANSACTION : Change transaction option like what rollback segment to use. d. GRANT/REVOKE : grant or take back permission to or from the oracle user.
  • 12.
    4. DQL(Data querylanguages) That allows getting data from the database and imposing ordering upon it. Examples a. SELECT : Retrieves data from table.
  • 13.
    THE CREATE TABLECOMMAND The create table command defines each column of table uniquely. Each column has a minimum three attributes a name, data type and size. Rules for creating a table 1. A name can have maximum up to 10 characters. 2. Alphabets from A-Z, a-z and digits 0-9 are allowed. 3. A name should begin with alphabet. 4. Only use special character as _(underscore).
  • 14.
    Syntax : Create table<table name> (<column name1><data type> (<size>), < column name2><data type> (<size>));
  • 15.
    Example SQL>create table emp(empnonumber(4), ename varchar(10), job char(10), mgr number(4), hiredate date, sal number(7,2), comm number(7,2), deptno number(2)); SQL>Table created
  • 16.
    Modifying the structureof Table 1.Adding New Columns Alter Command Used to alter structure of DB. Syntax : alter table <table name> add(<newcolumn name><data type> (<size>), < newcolumn name><data type> (<size>)); Example: Enter a new field eaddress in the table emp. SQL> alter table emp add(eaddress varchar2(30)); SQL> table altered
  • 17.
    Modifying the structureof Table 2. Modifying Existing Columns Alter Command Only modifying column size can be increased. Syntax : alter table <table name> modify(<newcolumn name><new data type> (<new size>)); Example: SQL> alter table emp modify(ename varchar2(25));
  • 18.
    Modifying the structureof Table 3. Dropping an Existing Columns Alter Command To drop an existing column. Example: SQL> alter table emp drop column city; • The multiple columns can be dropped in single command. SQL> alter table emp drop column (city,address);
  • 19.
    Modifying the structureof Table 4. Dropping Tables Table can be deleted using drop table command. Syntax : SQL>drop table tablename; Example: SQL>drop table emp; 5.Truncate Command Removes all records from a table including all space allocated for the records are removed. Syntax : SQL>truncate table tablename; Example: SQL>truncate table emp;