Dbms Practical File: Komal 81404113024

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Komal 81404113024 1

DBMS
Practical File

Komal
BTech IT 5th Sem
81404113024
Komal 81404113024 2

INTRODUCTION TO DBMS
A Database Management System (DBMS) is a set of computer programs that controls the
creation, maintenance, and the use of a database. It allows organizations to place control of
database development in the hands of database administrators (DBAs) and other specialists. A
DBMS is a system software package that helps the use of integrated collection of data records
and files known as databases. It allows different user application programs to easily access the
same database. DBMSs may use any of a variety of database models, such as the network model
or relational model. In large systems, a DBMS allows users and other software to store and
retrieve data in a structured way. Instead of having to write computer programs to extract
information, user can ask simple questions in a query language. Thus, many DBMS packages
provide Fourth-generation programming language (4GLs) and other application development
features. It helps to specify the logical organization for a database and access and use the
information within a database. It provides facilities for controlling data access, enforcing data
integrity, managing concurrency, and restoring the database from backups. A DBMS also
provides the ability to logically present database information to users.

A DBMS is a set of software programs that controls the organization, storage, management, and
retrieval of data in a database. DBMSs are categorized according to their data structures or
types. The DBMS accepts requests for data from an application program and instructs the
operating system to transfer the appropriate data. The queries and responses must be
submitted and received according to a format that conforms to one or more applicable
protocols. When a DBMS is used, information systems can be changed much more easily as the
organization's information requirements change. New categories of data can be added to the
database without disruption to the existing system.

ORACLE
The Oracle Database (commonly referred to as Oracle RDBMS or simply as Oracle) is a relational
database management system (RDBMS) produced and marketed by Oracle Corporation. As of
2010, Oracle has been a major presence in database computing for many years.

SQL
SQL, often referred to as Structured Query Language, is a database computer language designed
for managing data in relational database management systems (RDBMS), and originally based
upon relational algebra. Its scope includes data insert, query, update and delete, schema
creation and modification, and data access control.

The most common operation in SQL is the query, which is performed with the
declarative SELECT statement. SELECT retrieves data from one or more tables, or
expressions. Standard SELECT statements have no persistent effects on the database.
Some non-standard implementations of SELECT can have persistent effects, such as the
SELECT INTO syntax that exists in some databases.[10]

Queries allow the user to describe desired data, leaving the database management
system (DBMS) responsible for planning, optimizing, and performing the physical
operations necessary to produce that result as it chooses.
Komal 81404113024 3

A query includes a list of columns to be included in the final result immediately


following the SELECT keyword. An asterisk ("*") can also be used to specify that the
query should return all columns of the queried tables. SELECT is the most complex
statement in SQL, with optional keywords and clauses that include:

 The FROM clause which indicates the table(s) from which data is to be retrieved.
The FROM clause can include optional JOIN subclauses to specify the rules for
joining tables.
 The WHERE clause includes a comparison predicate, which restricts the rows
returned by the query. The WHERE clause eliminates all rows from the result set
for which the comparison predicate does not evaluate to True.
 The GROUP BY clause is used to project rows having common values into a smaller
set of rows. GROUP BY is often used in conjunction with SQL aggregation functions
or to eliminate duplicate rows from a result set. The WHERE clause is applied
before the GROUP BY clause.
 The HAVING clause includes a predicate used to filter rows resulting from the
GROUP BY clause. Because it acts on the results of the GROUP BY clause, aggregation
functions can be used in the HAVING clause predicate.
 The ORDER BY clause identifies which columns are used to sort the resulting data,
and in which direction they should be sorted (options are ascending or
descending). Without an ORDER BY clause, the order of rows returned by an SQL
query is undefined.

BASIC DATA TYPES OF SQL:


1. CHAR(SIZE)
CHAR is used for character data values. The size in bracket determines the number of
characters that the particular tupple can hold. Maximum number of characters
supported by this data type is 255.

2. VARCHAR(SIZE)
VARCHAR is used for character data. In bracket determines the number of characters
that the particular tupple can hold. In this data type we have dynamic allocation
approach.

3. VARCHAR2(SIZE)
VARCHAR2 can use character data as well as numbers and special characters. In bracket
determine the number of characters/number that the particular tupple can hold. In this
data type we have dynamic allocation approach.

4. DATE
DATE data type is used to have date in the table or data. Its format is DD/MM/YY.

5. NUMBER(P,S)
It is used to store Integer value up to 38 digit of precision. ’P’ determines maximum
length of integer data. ‘S’ determines number of places to write off decimal. If the scale is
omitted the default is zero.
6. LONG
Komal 81404113024 4

LONG is used for character data values. Maximum number of characters supported by
this data type is 2 GB.
7. RAW
RAW data type is used for storing images. It stores images up to 255 bytes.
8. LONG RAW
LONG RAW data type is used for storing images. It stores images up to 2 GB
Komal 81404113024 5

SQL COMMANDS:

1. CREATE:
It creates the table in database.

Syntax:
Create table <table name>
(“name of field”<data type> (size),”name of second field”<data type> (size));
Example:
Create table student (“name“ char(20),”roll no.” number(4),”marks” number(4));

2. DESCRIBE:
It creates the description of the created table in database.

Syntax:
Describe table <table name>
Example:
Describe student;
Komal 81404113024 6

3. SELECT:
It retrieves data from table.

Syntax:
Select * from <table name>;
Example:
Select * from student;

(a) SELECT WITH CLAUSE:


To select the record from table as per condition.

Syntax:
Select * from <table name> where<condition>;
Example:
Select * from student where “rollno.”=4;
Komal 81404113024 7

(b) SELECT TABLE FROM EXISTING TABLES:

Syntax:
Select * from tab;
Example:
Select * from tab;
It gives list of all tables.

4. INSERT:
To insert data into the table.
Syntax:
Insert into <table name> (“column name”, “column name”, “column name”) values
(“…”,”…”, ”….”);
Example:
Insert into student (roll no, name, marks) values (201,”abc”, 49);

5. DROP:
To delete table.

Syntax:
Drop table <table name>;
Example:
Drop table student;

6. DELETE:
To delete a record from the table.

Syntax:
Delete from <table name>;
Example:
Delete * from student;
Komal 81404113024 8

7. TRUNCATE:
To delete the table.

Syntax:
Truncate table<table name> ;
Example:
Truncate table student;

8. DISTINCT:
To select a particular value i.e. unique value from table.
Syntax:
Select distinct <column name > from <Table name> ;
Example:
Select distinct name from student;

9. SORTING:
To sort the table data entries or values in a required order.
Syntax:
Select * from <Table name> order by<column name >;
Example:
Select * from student order by rollno;
Komal 81404113024 9

10. UPDATE:
To update data values of the table.
Syntax:
update<Table name>set<column name=’expression’ > where < column
name=’expression’>;
Example:
Update student set “name”=’abha’ where “rollno”=1;

11. ALTER:
To alter the table. To add a new column to the table.

Syntax:
Alter table <Table name> add <column name data type (size) >;
Example:
Alter table student add (name varchar(20));

12. ALTER MODIFIES:


To alter the table. To modify an existing column of the table.

Syntax:
Alter table <Table name> modify <”column name “data type (size) >;
Example:
Alter table student add (“name” varchar2 (20));
Komal 81404113024 10

13. Create table from existing table:


To create a new table from an existing table.
Syntax:
Create table<Table name1> (column name.column name) as select column
name,column name from <table name2>;
Example:
Create table student (name ,rollno) as select column name , rollno from class;

14. Inserting data from existing table:


To insert values in a new table from an existing table.
Syntax:
Insert into <Table name1> select column name,column name from <table name2>;
Example:
Insert into student select column name, rollno from class;
Komal 81404113024 11

Arithmetic Operators:

15. Addition:
To add any integer to the table values.
Syntax:
Select column name+’expression’ from <table name>;
Example:
Select rollno,attendance+12 from student;

16. Subtraction:
To subtract any integer to the table values.
Syntax:
Select column name-’expression’ from <table name>;
Example:
Select rollno,attendance-12 from student;
Komal 81404113024 12

17. Multiplication:
To multiply any integer to the table values.
Syntax:
Select column name*’expression’ from <table name>;
Example:
Select rollno,attendance*12 from student;

18. Division:
To divide any integer to the table values.
Syntax:
Select column name/’expression’ from <table name>;
Example:
Select rollno,attendance/12 from student;
Komal 81404113024 13

Logical Operators:

19. Logical AND:


Logical AND select the record when both conditions are true.
Syntax:
Select column name from <table name> where condition AND condition;
Example:
Select rollno from student where attendance<=75 AND attendance>=70;

20. Logical OR:


Logical OR select the record when one condition is true.
Syntax:
Select column name from <table name> where condition OR condition;
Example:
Select rollno from student where attendance<=75 OR attendance>=70;

21. Logical NOT:


Logical NOT select the record when either one or more conditions are false.
Syntax:
Select column name from <table name> where NOT condition;
Example:
Select rollno from student where NOT (attendance<=75 OR attendance>=70);
Komal 81404113024 14
Komal 81404113024 15

Range Searching:

22. Between:
Between select the record within a range.
Syntax:
Select column name from <table name> where column name BETWEEN ‘expression’
AND ‘expression’;
Example:
Select rollno from student where marks between 70 and 80;

23. Not Between:


Not Between select the record not within the mentioned range.
Syntax:
Select column name from <table name> where column name NOT BETWEEN
‘expression’ AND ‘expression’;
Example:
Select rollno from student where marks not between 70 and 80;

24. In:

In select the record in the mentioned conditions.


Syntax:
Select column name from <table name> where column name IN (‘expression’,
‘expression’;
Example:
Select rollno from student where marks in (70 , 80);
Komal 81404113024 16

25. Not In:

Not In select the record not in the mentioned conditions.


Syntax:
Select column name from <table name> where column name NOT IN (‘expression’,
‘expression’;
Example:
Select rollno from student where marks not in (70 , 80);
Komal 81404113024 17

Pattern Matching:

1. Like:

Like select the record whose pattern matches with the given string.
Like works on two operators
1. % which is used for multiple characters.
2. _ is used for single character.
Syntax:
Select * from <table name> where column name LIKE ‘expression%’ or ‘expression_’;
Example:
Select *from student where name like ‘ma%’;

Example:
Select *from student where name like ‘_a’;

You might also like