0% found this document useful (0 votes)
85 views22 pages

Database Lab Assignment 1: Study of M SQL & Oracle

The document provides information about MySQL and Oracle databases including: 1. It introduces MySQL as an open source relational database management system that uses SQL and stores information in tables within databases. 2. Key features of MySQL are discussed such as speed, cost, portability, and security. 3. The four data models - relational, hierarchical, network, and object oriented - are defined. 4. Terminology related to the relational model such as relation, tuple, attribute, primary key, and foreign key are explained.

Uploaded by

7779854268
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views22 pages

Database Lab Assignment 1: Study of M SQL & Oracle

The document provides information about MySQL and Oracle databases including: 1. It introduces MySQL as an open source relational database management system that uses SQL and stores information in tables within databases. 2. Key features of MySQL are discussed such as speed, cost, portability, and security. 3. The four data models - relational, hierarchical, network, and object oriented - are defined. 4. Terminology related to the relational model such as relation, tuple, attribute, primary key, and foreign key are explained.

Uploaded by

7779854268
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Database lab Manual

Computer Department, SCOE.

DATABASE LAB
ASSIGNMENT 1
Study of MYSQL & ORACLE
Database lab Manual
Computer Department, SCOE.
A. INTRODUCTION TO MySQL

MYSQL

It is freely available open source Relational Database Management System (RDBMS) that uses Structured Query
Language(SQL). In MySQL database , information is stored in Tables. A single MySQL database can contain many
tables at once and store thousands of individual records.

FEATURES OF MySQL

1. Speed : If the server hardware is optimal, MySQL runs very fast.


2. Cost : MySQL is available free of cost.
3. Portability : MySQL is portable also, since it can run on many different platforms.
4. Security : MySQL offers a privilege and password system that is very flexible and secure.

SQL (Structured Query Language)

SQL is a language that enables you to create and operate on relational databases, which are sets of related
information stored in tables.

DIFFERENT DATA MODELS

A data model refers to a set of concepts to describe the structure of a database , and certain constraints (restrictions)
that the database should obey. The four data model that are used for database management are :

1. Relational data model: In this data model, the data is organized into tables (i.e. rows and columns). These tables
are called relations.

2. Hierarchical data model 3. Network data model 4. Object oriented data model

RELATIONAL MODEL TERMINOLOGY

1. Relation : A table storing logically related data is called a Relation.

2. Tuple : A row of a relation is generally referred to as a tuple.

3. Attribute : A column of a relation is generally referred to as an attribute.

4. Degree : This refers to the number of attributes in a relation.

5. Cardinality : This refers to the number of tuples in a relation.

6. Primary Key : This refers to a set of one or more attributes that can uniquely identify tuples within the relation.

7. Candidate Key : All attribute combinations inside a relation that can serve as primary key are candidate keys as
these are candidates for primary key position.

8. Alternate Key : A candidate key that is not primary key, is called an alternate key.

9. Foreign Key : A non-key attribute, whose values are derived from the primary key of some other table, is known
as foreign key in its current table.

REFERENTIAL INTEGRITY

- A referential integrity is a system of rules that a DBMS uses to ensure that relationships between records in
related tables are valid, and that users don’t accidentally delete or change related data. This integrity is
ensured by foreign key.
Database lab Manual
Computer Department, SCOE.
CLASSIFICATION OF SQL STATEMENTS

SQL commands can be mainly divided into following categories:

1. Data Definition Language(DDL) Commands


Commands that allow you to perform task, related to data definition e.g;
Creating, altering and dropping tables.
Granting and revoking privileges and roles. Maintenance commands.

2. Data Manipulation Language(DML) Commands


Commands that allow you to perform data manipulation e.g., retrieval, insertion, deletion and modification of data
stored in a database.

DML are basically of two types : 1. Procedural DML 2. Non-Procedural DML

PROCEDURAL DML
It requires a user to specify what data is needed and how to get it.
NON PROCEDURAL DML
It require a user to specify what data is needed without specifying how to get it.

3. Transaction Control Language(TCL) Commands


Commands that allow you to manage and control the transactions e.g.,
Making changes to database, permanent
Undoing changes to database, permanent Creating save points
Setting properties for current transactions.

MySQL ELEMENTS

1. Literals 2. Datatypes 3. Nulls 4. Comments

LITERALS
It refer to a fixed data value. This fixed data value may be of character type or numeric type. For example, ‘replay’ ,
‘Raj’, ‘8’ , ‘306’ are all character literals.
Numbers not enclosed in quotation marks are numeric literals. E.g. 22 , 18 , 1997 are all numeric literals.
Numeric literals can either be integer literals i.e., without any decimal or be real literals i.e. with a decimal point
e.g. 17 is an integer literal but 17.0 and 17.5 are real literals.

DATA TYPES
Data types are means to identify the type of data and associated operations for handling it. MySQL data types are
divided into three categories:
Numeric
Date and time
String types

Numeric Data Type


1. int - used for number without decimal.
2. Decimal(m,d) - used for floating/real numbers. m denotes the total length of number and d is number of
decimal digits.
Database lab Manual
Computer Department, SCOE.
Date and Time Data Type
1. date - used to store date in YYYY-MM-DD format.
2. time - used to store time in HH:MM:SS format.

String Data Types


1. char(m) - used to store a fixed length string. m denotes max. number of characters.
2. varchar(m) - used to store a variable length string. m denotes max. no. of characters.

DIFFERENCE BETWEEN CHAR AND VARCHAR DATA TYPE

S.NO. Char Datatype Varchar Datatype


1. It specifies a fixed length It specifies a variable length character string.
character String.
2. When a column is given datatype When a column is given datatype as VARCHAR(n),
As CHAR(n), then MySQL ensures then the maximum size a value in this column
that all values stored in that can have is n bytes. Each value that is stored in
column have this length i.e. n this column store exactly as you specify it i.e. no
bytes. If a value is shorter than this blanks are added if the length is shorter than
length n then blanks are added, but maximum length n.
the size of value remains n bytes.

NULL VALUE
If a column in a row has no value, then column
is said to be null , or to contain a null. You
should use a null value when the actual value is
not known or when a value would not be
meaningful.
Database lab Manual
Computer Department, SCOE.
DATABASE COMMNADS

1. VIEW EXISTING DATABASE


To view existing database names, the command is : SHOW DATABASES ;

2. CREATING DATABASE IN MYSQL


For creating the database in MySQL, we write the following command :
CREATE DATABASE <databasename> ;
e.g. In order to create a database Student, command is :
CREATE DATABASE Student ;
3. ACCESSING DATABASE
For accessing already existing database , we write :
USE <databasename> ;
e.g. to access a database named Student , we write command as :
USE Student ;
4. DELETING DATABASE
For deleting any existing database , the command is :
DROP DATABASE <databasename> ;
e.g. to delete a database , say student, we w
DROP DATABASE Student ;

5. VIEWING TABLE IN DATABASE


In order to view tables present in currently accessed database , command is : SHOW TABLES ; CREATING TABLES

IN MYSQL
- Tables are created with the CREATE TABLE command. When a table is created, its columns are named, data
types and sizes are supplied for each column.
Syntax of CREATE TABLE command
is : CREATE TABLE <table-name>
( <column name> <data type> ,
<column name> <data type> ,
……… ) ;

E.g. in order to create table EMPLOYEE given


below : ECODE ENAME GENDER GRADE GROSS
We write the following command :
CREATE TABLE employee
( ECODE integer ,
ENAME varchar(20) ,
GENDER char(1) ,
GRADE char(2) ,
GROSS integer ) ;
Database lab Manual
Computer Department, SCOE.
INSERTING DATA INTO TABLE
- The rows are added to relations(table) using INSERT command of SQL. Syntax of INSERT is :
INSERT INTO <tablename> [<column list>] VALUE ( <value1> , <value2> , …..) ;

e.g. to enter a row into EMPLOYEE table (created above), we write command as :
INSERT INTO employee VALUES(1001 , ‘Ravi’ , ‘M’ , ‘E4’ , 50000);

OR
INSERT INTO employee (ECODE , ENAME , GENDER , GRADE , GROSS) VALUES(1001 , ‘Ravi’ , ‘M’ , ‘E4’ , 50000);

In order to insert another row in EMPLOYEE table , we write again INSERT command :
INSERT INTO employee VALUES(1002 , ‘Akash’ , ‘M’ , ‘A1’ , 35000);

ECODE ENAME GENDER GRADE GROSS


1001 Ravi M E4 50000
1002 Akash M A1 35000

INSERTING NULL VALUES

- To insert value NULL in a specific column, we can type NULL without quotes and NULL will be inserted in that
column. E.g. in order to insert NULL value in ENAME column of above table, we write INSERT command as :

INSERT INTO EMPLOYEE VALUES (1004 , NULL , ‘M’ , ‘B2’ , 38965 ) ;

ECODE ENAME GENDER GRADE GROSS


1001 Ravi M E4 50000
1002 Akash M A1 35000
1004 NULL M B2 38965

MODIFYING DATA IN TABLES

you can modify data in tables using UPDATE command of SQL. The UPDATE command specifies the rows to be
changed using the WHERE clause, and the new data using the SET keyword. Syntax of update command is :
UPDATE <tablename> SET <columnname>=value , <columnname>=value WHERE <condition> ;

e.g. to change the salary of employee of those in EMPLOYEE table having employee code 1009 to 55000. UPDATE
EMPLOYEE SET GROSS = 55000 WHERE ECODE = 1009 ;

UPDATING MORE THAN ONE COLUMNS


e.g. to update the salary to 58000 and grade to B2 for those employee whose employee code is 1001.

UPDATE EMPLOYEE SET GROSS = 58000, GRADE=’B2’ WHERE ECODE = 1009 ;


Database lab Manual
Computer Department, SCOE.
OTHER EXAMPLES
e.g.1. Increase the salary of each employee by 1000 in the EMPLOYEE table.
UPDATE EMPLOYEE SET GROSS = GROSS +100 ;
e.g.2. Double the salary of employees having grade as ‘A1’ or ‘A2’ .
UPDATE EMPLOYEE SET GROSS = GROSS * 2 WHERE GRADE=’A1’ OR GRADE=’A2’ ;
e.g.3. Change the grade to ‘A2’ for those employees whose employee code is 1004 and name is Neela.
UPDATE EMPLOYEE SET GRADE=’A2’ WHERE ECODE=1004 AND GRADE=’NEELA’ ;

DELETING DATA FROM TABLES


To delete some data from tables, DELETE command is used. The DELETE command removes rows from a table.
The syntax of DELETE command is :
DELETE FROM <tablename> WHERE <condition> ;
For e.g., to remove the details of those employee from EMPLOYEE table whose grade is A1.
DELETE FROM EMPLOYEE WHERE GRADE =’A1’ ;

TO DELETE ALL THE CONTENTS FROM A TABLE


DELETE FROM EMPLOYEE ;

So if we do not specify any condition with WHERE clause, then all the rows of the table will be deleted. Thus above
line will delete all rows from employee table.

DROPPING TABLES
The DROP TABLE command lets you drop a table from the database. The syntax of DROP TABLE command is :
DROP TABLE <tablename> ;
e.g. to drop a table employee, we need to write :
DROP TABLE employee ;

S.NO. DELETE COMMAND DROP TABLE


1 It is a DML command. COMMAND It is a DDL Command.
2 This command is used to delete only This command is used to delete all the data of the table
rows of data from a table along with the structure of the table. The table is no
longer recognized when this command gets executed.
3 Syntax of DELETE command is: Syntax of DROP command is :
DELETE FROM <tablename> DROP TABLE <tablename> ;
WHERE <condition> ;

EMPLOYEE
ECODE ENAME GENDER GRADE GROSS
1001 Ravi M E4 50000
1002 Akash M A1 35000
1004 Neela F B2 38965
1005 Sunny M A2 30000
1006 Ruby F A1 45000
1009 Neema F A2 52000
Database lab Manual
Computer Department, SCOE.
SELECTING ALL DATA
- In order to retrieve everything (all columns) from a table, SELECT command is used
as : SELECT * FROM <tablename> ;

e.g. In order to retrieve everything from Employee table, we write SELECT command as :
SELECT * FROM Employee ;

SELECTING PARTICULAR COLUMNS


- A particular column from a table can be selected by specifying column-names with SELECT command. E.g. in
above table, if we want to select ECODE and ENAME column, then command is :
SELECT ECODE , ENAME FROM EMPLOYEE ;
E.g.2 in order to select only ENAME, GRADE and GROSS column, the command is :
SELECT ENAME , GRADE , GROSS FROM EMPLOYEE ;

SELECTING PARTICULAR ROWS


We can select particular rows from a table by specifying a condition through WHERE clause along with SELECT
statement. E.g. In employee table if we want to select rows where Gender is female, then command is :
SELECT * FROM EMPLOYEE WHERE GENDER = ‘F’ ;
E.g.2. in order to select rows where salary is greater than 48000, then command is :
SELECT * FROM EMPLOYEE WHERE GROSS > 48000 ;

RELATIONAL OPERATORS
- To compare two values , a relational operator is used. The result of the comparison is true or false. The
SQL recognizes following relational operators:
= < > <= >= < > (Not equal to).

LOGICAL OPERATORS

- The logical operator OR ( || ), AND (&&) and NOT (!) are used to connect search conditions in the WHERE clause.e.g.

1. To list the employee details having grade ‘A1’ or ‘A2’ from table employee, logical operator OR will be
used as : SELECT * FROM EMPLOYEE WHERE GRADE=’A1’ OR GRADE =’A2’ ;

2. To list the employee details having grades as A1 and salary greater than 40000, logical operator AND will be

used as: SELECT * FROM EMPLOYEE WHERE GRADE=’A1’ AND GROSS > 40000;

3. To list the employee details whose grades are other than ‘A1’, logical operator NOT will be used as :

SELECT * FROM EMPLOYEE WHERE NOT GRADE=”A1” ;

ELIMINATING REDUNDANT DATA


The DISTINCT keyword eliminates duplicate rows from the results of a SELECT statement. For example ,
SELECT GENDER FROM EMPLOYEE ;

GENDER
M
M
Database lab Manual
Computer Department, SCOE.
F
M
F
F

SELECT DISTINCT(GENDER) FROM EMPLOYEE ;

DISTINCT(GENDER)
M
F

VIEWING STRUCTURE OF A TABLE


- If we want to know the structure of a table, we can use DESCRIBE or DESC command, as per following
syntax : DESCRIBE | DESC <tablename> ;
e.g. to view the structure of table EMPLOYEE, command is :
DESCRIBE EMPLOYEE ; OR DESC EMPLOYEE ;

USING COLUMN ALIASES


- The columns that we select in a query can be given a different name, i.e. column alias name for output purpose.
Syntax :
SELECT <columnname> AS column alias , <columnname> AS column alias ….. FROM <tablename> ;
e.g. In output, suppose we want to display ECODE column as EMPLOYEE_CODE in output , then command is :
SELECT ECODE AS “EMPLOYEE_CODE” FROM EMPLOYEE ;

CONDITION BASED ON A RANGE


- The BETWEEN operator defines a range of values that the column values must fall in to make the condition true.
The range include both lower value and upper value.

e.g. to display ECODE, ENAME and GRADE of those employees whose salary is between 40000 and 50000,
command is:
SELECT ECODE , ENAME ,GRADE FROM EMPLOYEE WHERE GROSS BETWEEN 40000 AND 50000 ;
Output will be :

ECODE ENAME GRADE


1001 Ravi E4
1006 Ruby A1

CONDITION BASED ON A LIST


- To specify a list of values, IN operator is used. The IN operator selects value that match any value in a given
list of values. E.g.
SELECT * FROM EMPLOYEE WHERE GRADE IN (‘A1’ , ‘A2’);

Output will be :

ECODE ENAME GENDER GRADE GROSS


1002 Akash M A1 35000
Database lab Manual
Computer Department, SCOE.
Database lab Manual
Computer Department, SCOE.
1006 Ruby F A1 45000
1005 Sunny M A2 30000
1009 Neema F A2 52000

- The NOT IN operator finds rows that do not match in the list. E.g.
SELECT * FROM EMPLOYEE WHERE GRADE NOT IN (‘A1’ , ‘A2’);

Output will be :
ECODE ENAME GENDER GRADE GROSS
1001 Ravi M E4 50000
1004 Neela F B2 38965

CONDITION BASED ON PATTERN MATCHES


- LIKE operator is used for pattern matching in SQL. Patterns are described using two special wildcard characters:

1. percent(%) - The % character matches any substring.


2. underscore(_) - The _ character matches any character.
e.g. to display names of employee whose name starts with R in EMPLOYEE table, the command is :

SELECT ENAME FROM EMPLOYEE WHERE ENAME LIKE ‘R%’ ;


Output will be :
ENAME
Ravi
Ruby

e.g. to display details of employee whose second character in name is ‘e’.

SELECT * FROM EMPLOYEE WHERE ENAME LIKE ‘_e%’ ;

Output will be :

ECODE ENAME GENDER GRADE GROSS


1004 Neela F B2 38965
1009 Neema F A2 52000

e.g. to display details of employee whose name ends with ‘y’.

SELECT * FROM EMPLOYEE WHERE ENAME LIKE ‘%y’ ;

Output will be :

ECODE ENAME GENDER GRADE GROSS


1005 Sunny M A2 30000
1006 Ruby F A1 45000

SEARCHING FOR NULL


- The NULL value in a column can be searched for in a table using IS NULL in the WHERE clause. E.g. to list
employee details whose salary contain NULL, we use the command :
SELECT * FROM EMPLOYEE WHERE GROSS IS NULL ;
Database lab Manual
Computer Department, SCOE.
e.g.
Roll_No Name Marks
1 ARUN NULL
2 RAVI 56
4 SANJAY NULL

--to display the names of those students whose marks is NULL, we use the command :
SELECT Name FROM EMPLOYEE WHERE Marks IS NULL ;

Output will be :
Name
ARUN
SANJAY

SORTING RESULTS

Whenever the SELECT query is executed , the resulting rows appear in a predefined order. The ORDER BY clause allow
sorting of query result. The sorting can be done either in ascending or descending order, the default is ascending.

The ORDER BY clause is used as :


SELECT <column name> , <column name>…. FROM <tablename>
WHERE <condition> ORDER BY <column name> ;

e.g. to display the details of employees in EMPLOYEE table in alphabetical order, we use command :
SELECT * FROM EMPLOYEE ORDER BY ENAME ;

Output will be :
ECODE ENAME GENDER GRADE GROSS
1002 Akash M A1 35000
1004 Neela F B2 38965
1009 Neema F A2 52000
1001 Ravi M E4 50000
1006 Ruby F A1 45000
1005 Sunny M A2 30000

e.g. display list of employee in descending alphabetical order whose salary is greater than 40000. SELECT
ENAME FROM EMPLOYEE WHERE GROSS > 40000 ORDER BY ENAME desc ;

Output will be :
ENAME
Ravi
Ruby
Neema
Database lab Manual
Computer Department, SCOE.
B. INTRODUCTION TO ORACLE.

ORACLE
Oracle is one of the powerful RDBMS products that provide efficient solutions for
database applications. Oracle is the product of Oracle Corporation which was founded by
LAWRENCE ELLISION in 1977. The first commercial product of oracle was delivered in 1970.
The first version of oracle 2.0 was written in assembly language. Nowadays commonly used
versions of oracle are ORACLE 8, 8i & 9i Oracle 8 and onwards provide tremendous increase in
performance, features and functionality.

FEATURES OF ORACLE
Client/Server Architecture
Large database and Space Management
Concurrent Processing
High transaction processing performance
High Availability
Many concurrent database users
Controlled availability
Openness industry standards
Manageable security
Database enforced integrity
Distributed systems
Portability
Compatibility
ORACLE SERVER TOOL
Oracle is a company that produces most widely used server based multi-user RDBMS.
Oracle server is a program installed on server hard-disk drive. This program must be loaded in
RAM to that it can process the user requests. Oracle server takes care of following functions.
Oracle server tools are also called as back end. Functions of server tool:
updates the data

Retrieves the data sharing

manages the data sharing

accepts the query statements PL/SQL and SQL

 enforce the transaction consistency


Database lab Manual
Computer Department, SCOE.
ORACLE CLIENT TOOL
Once Oracle engine is loaded into sever memory user would have to log in to engine in order to
work done. Client tools are more useful in commercial application development. It provides
facilities to work on database objects. These are more commonly used in commercial applications.
Oracle client tools are also called front end.

APPLICATION DEVELOPMENT TOOLS

SQL*Plus - A command line tool used to manipulate tables and other database objects in
an Oracle database.
DeveloperA suite of application development tools including Forms, Reports and Graphics.

Oracle Forms - A screen based tool used to develop data entry forms and menus that
access tables in an Oracle database.

Oracle Reports - A screen based tool used to develop reports that access tables in an
Oracle database.

Oracle Graphics - A graphical tool used to develop charts and reports that access tables in an
Oracle database.

Oracle JDeveloper - A general purpose Java Integrated Development Environment that has been
pre-loaded with classes and methods used to connect to and manipulate schemas in Oracle
databases. A collection of code development wizards allow the developer to quickly create data
entry forms as Java applications or applets as well as reports using Java Server Pages (JSP).

Oracle Designer - A graphical tool used to create and display models contained in the
CASE*Dictionary. The CASE*Dictionary is a repository for business rules, functional
models and data models used for organizing and documenting an application development
effort. CASE*Generator is a code generating tool that uses information stored in
CASE*Dictionary to develop data entry forms, reports and graphics.

Programmer - Including the Pro* precompilers - Libraries of routines and utilities that can
be linked with “C”, C++, FORTRAN, Java, ADA, COBOL or other host languages to
allow access to Oracle databases.

RUNNING SQL*PLUS
In this section, we give some general directions on how to get into the SQL*Plus program and
connect to an Oracle database. Specific instructions for your installation may vary depending on
the version of SQL*Plus being used, whether or not SQL*Net or Net8 is in use, etc.

Some tips on Obtaining and Installing Oracle Software can be found on this link.
If you have the Oracle Express Edition installed, this link. will describe how to run SQL
Commands in Oracle Application Express.
Before using the SQL*Plus tool or any other development tool or utility, the user must obtain an
Oracle account for the DBMS. This account will include a username, a password and, optionally,
a host string indicating the database to connect to. This information can typically be obtained
from the database administrator.
Database lab Manual
Computer Department, SCOE.
The following directions apply to two commonly found installations: Windows XP or Windows
7 client (from here on, referred to simply as a Windows client) with an Oracle server, and a
UNIX/LINUX installation.

RUNNING SQL*PLUS UNDER WINDOWS


To run the SQL*Plus command line program from Windows, click on
the button, Programs,
Oracle - OraHomeXX, Application Development and then SQL*Plus. The SQL*Plus login
screen will appear after roughly 15 seconds.
(Note the XX is replaced with the version of the database you are using such as 81 for Oracle8i,
90 for Oracle9i etc.).

In the User Name: field, type in your Oracle username.

Press the TAB key to move to the next field.

In the Password: field, type your Oracle password. Press the TAB key to move to the next field.

In the Host String: field, type in the SERVICE NAME of the Oracle host to connect to.
If the DBMS is Personal Oracle lite then this string might be ODBC:POLITE. If the DBMS is a
local Personal Oracle8, 8i or 9i database, then the host string might be either beq-local or in some
cases, you can leave this field blank to connect to your local database instance. Make certain
your local instance is started. For Client/Server installations with SQL*Net or Net8, this string
will be the service name set up by the SQL*Net or Net8 assistant software.

Finally, click on the OK button to complete the Oracle log in process. SQL*Plus will then
establish a SESSION with the Oracle DBMS and the SQL*Plus prompt (SQL> ) will appear. The
following figure shows the results of logging into Oracle using SQL*Plus:

DDL - DATA DEFINATION LANGUAGE


The SQL sentences that are used to create these objects are called DDL’s or Data Definition
Language. The sql provides various commands for defining relation schemas, deleting relations,
creating indexes and modify relation schemas. DDL is part of sql which helps a user in defining
the data structures into the database. Following are the various DDL commands are
 Alter table & Create table & drop table
Database lab Manual
Computer Department, SCOE.
 Create index & drop index

 Create view & drop view

DML - DATA MANIPULATION LANGUAGE


The SQL sentences used to manipulate data within these objects are called DML’s or Data
Manipulation Language. It is language that enables users to access or manipulate data as
organized by appropriate data model. By data manipulation we have
O Retrieval of information stored in database.
O Insertion of new information into database.
O Deletion of information from database.

O Modification of data stored in


database. Two types of DML are
 Procedural DML

 Non-procedural DML

Following are DML commands are


 Select

 Update

 Delete

 Insert

DCL - DATA CONTROL LANGUAGE


The SQL sentences, which are used to control the behavior of these objects, are called DCL’s or
Data Control Language. It is language used to control data and access to the database. Following
are some DCL commands are
 Commit

 Rollback

 Save point

 Set transaction

DATA TYPES OF SQL

CHAR: This data type is used to store character strings values of fixed length. The size in
brackets determines the number of characters the cell can hold. The maximum number of
characters (i.e. the size) this data type can hold is 255 characters. Syntax is CHAR(SIZE)
Example is CHAR (20)
Database lab Manual
Computer Department, SCOE.
VARCHAR: This data type is used to store variable length alphanumeric data. The
maximum this data type can hold is 4000 characters. One difference between this data type and
the CHAR data type is ORACLE compares VARCHAR values using non-padded comparison
semantics i.e. the inserted values will not be padded with spaces. Syntax is VARCHAR(SIZE)
Example is VARCHAR (20) OR VARCHAR2 (20)

NUMBER: The NUMBER data type is used to store numbers (fixed or floating point).
Numbers of virtually any magnitude maybe stored up to 38 digits of precision. Numbers as
large as 9.99 * 10 to the power of 124, i.e. followed by 125 zeros can be stored. The precision,
(P), determines the maximum length of the data, whereas the scale, (S), determines the number
of places to the right of the decimal. If scale is omitted then the default is zero. If precision is
omitted values are stored with their original precision up to the maximum of 38 digits. Syntax
is NUMBER (P, S) Example is NUMBER (10, 2)

LONG: This data type is used to store variable length character strings containing up to
2GB. LONG data can be used to store arrays of binary data in ASCII format. LONG values
cannot be indexed, and the normal character functions such as SUBSTR cannot be applied to
LONG values Syntax is LONG (SIZE) Example is LONG (20)

DATE: This data type is used to represent data and time. The standard format id DD-
MM-YY as in 13-JUL-85. To enter dates other than the standard format, use the appropriate
functions. Date
Time stores date in the 24-hour format. By default, the time in a date field is 12:00:00 am, if
no time portion is specified. The default date for a date field is the first day of the current
month. Syntax is DATE

LONG RAW: LONG RAW data types are used to store binary data, such as Digitized
picture or image. Data loaded into columns of these data types are stored without any further
conversion. LONG RAW data type can contain up to 2GB. Values stored in columns having
LONG RAW data type cannot be indexed. Syntax is LONGRAW (SIZE)

RAW: It is used to hold strings of byte oriented data. Data type can have a maximum length
of 255 bytes. Syntax is RAW(SIZE)
Database lab Manual
Computer Department, SCOE.
SQL COMMANDS

CREATE TABLE: A table is basic unit of storage. It is composed of rows and columns.
To create a table we will name the table and the columns of the table. We follow the rules to
name tables and columns:-
O It must begin with a letter and can be up to 30 characters long.

O It must not be duplicate and not any reserved word.

Syntax to create a table is


CREATE TABLE tablename (column_name1 datatype (size), column_name2 datatype (size) …);

 Example is
O CREATE TABLE student (rollno number (4), name varchar2 (15));
Database lab Manual
Computer Department, SCOE.
SELECT : The select command of sql lets you make queries on the database. A query is a
command that is given certain specified information from the database tables. It can be used to
retrieve a subset of rows or columns from one or more tables.
Syntax to create a table is
SELECT <column_name1>,<column_name2> FROM <tablename>;
Example is SELECT empno, ename, sal from emp;
Database lab Manual
Computer Department, SCOE.
DESCRIBE : To find information about columns like column name, their data types
and other attributes of a table we can use DESCRIBE command. Syntax to describe table
is DESCRIBE tablename;

ALTER TABLE: After creating a table one may have need to change the table either by
add new columns or by modify existing columns. One can do so by using alter table command.
Syntax to add a column is
ALTER TABLE tablename ADD(col1 datatype,col2 datatype);
Syntax to modify a column is
ALTER TABLE tablename MODIFY(col1 datatype,col2 datatype);
Database lab Manual
Computer Department, SCOE.

DELETE: One can delete data fron table by using delete from statement. The delete
statement removes rows from table but it doesn’t release storage space. Syntax of delete rows
from table is DELETE FROM tablename WHERE <condition>;

INSERT: To add new rows in an existing oracle table the insert command is used. Syntax to
add new fields is
INSERT INTO tablename(col1,col2,col3,..)
VALUES(value1,value2,value3);
Example is
INSERT INTO employee(emp_id,ename,desg,basic_pay)
VALUES(100001,’MOHIT’,’MANAGER’,55000);
Database lab Manual
Computer Department, SCOE.
UPDATE: The update command enables user to change the values of existing
rows. Syntax to
update value of table is
UPDATE tablename SET col1=value1,col2=value2;
Example is
UPDATE emp_info SET salary =salary +100;

DROP TABLE: To remove the definition of oracle table, the drop table statement is
used.
Syntax to drop table is
DROP TABLE tablename

RENAME : One can change the name of a table by rename command Syntax to
rename table is

RENAME oldname TO newname

====================================================================

You might also like