Dbms Lab File
Dbms Lab File
2.
3. .
Operators in SQL
4.
Functions in SQL
5.
Joins in SQL
6.
Subqueries in SQL
Program 1
Theory :
A) Introduction to Oracle : Oracle is a product from Oracle corporation that provides a relational
database management system. RDBMS supports any kind of data model. It has different product
editions, including Standard Edition, Enterprise Edition, Express Edition, and Personal Edition.
Oracle products are scalable and secure, with high-performance ability.
Oracle database is a relational database management system (RDBMS) from Oracle Corporation.
This article will explain a complete overview of the Oracle database, features, history, and editions.
Before discussing the oracle, we will first need to know about the database.
Oracle database is a relational database management system. It is also called OracleDB, or
simply Oracle. It is produced and marketed by Oracle Corporation. It was created
in 1977 by Lawrence Ellison and other engineers. It is one of the most popular relational database
engines in the IT market for storing, organizing, and retrieving data.
Oracle database was the first DB that designed for enterprise grid computing and data
warehousing. Enterprise grid computing provides the most flexible and cost-effective way to
manage information and applications. It uses SQL queries as a language for interacting with the
database.
EDITIONS OF ORACLE :
Oracle database is compatible with a wide range of platforms such as Windows, UNIX, Linux, and
macOS. It supports several operating systems like IBM AIX, HP-UX, Linux, Microsoft Windows
Server, Solaris, SunOS, macOS, etc. In the late 1990s, Oracle began supporting open platforms like
GNU/Linux.
The following is a list of Oracle database editions :
Enterprise Edition: It is the most robust and secure edition. It offers all features, including
superior performance and security.
Standard Edition:It provides the base functionality for users that do not require Enterprise
Edition's robust package.
Express Edition: It is the lightweight, free and limited Windows, and Linux edition.
Oracle lite:It is designed for mobile devices.
Personal Edition:It's comparable to the Enterprise Edition but without the Oracle Real
Application Clusters feature.
HISTORY OF ORACLE
Oracle Corporation is the largest software company to develop and markets computer software
applications for business. The company is best known for its Oracle database products and, more
recently, cloud products and services. Its relational database was the first to support SQL, which has
since become the industry standard.Oracle database is one of the most trusted and widely used
relational database engines. The biggest rival of Oracle database is Microsoft's SQL Server.
Oracle Corporation was founded by Lawrence Ellison (Larry Ellison), Bob Miner, Ed Oates, and
Bruce Scott in August 1977. They have a lot of experience in building database programs for
several companies and builds their first project (a special database program) for the CIA (Central
Intelligence Agency). Oracle was named after "Project Oracle," a project for one of their clients
named Central Intelligence Agency, and the company that created Oracle was called Systems
Development Labs (SDL). Systems Development Labs was renamed Relational Software Inc. (RSI)
in 1978 to expand their market for the new database. They had again changed the name of the
company from RSI to Oracle Systems Corporation in 1982.
The first commercially available RDBMS named Oracle V2 (Version 2) was built using PDP-11
assembler language (SQL-based RDBMS). Although they already developed a commercial
RDBMS in 1977, it wasn't available for purchase until 1979, when Oracle version 2 was released.
In 1983, Oracle database portable version named "Oracle version 3" was released. This version was
written in the C programming language. It was the first relational database that can run in
mainframes, minicomputers, PCs, or any hardware with a C compiler. It also supports SQL queries
and transactions execution.
The other versions of Oracle are :
In 1984, Oracle 4 was released that supports Transactions [Commit/Rollback],
export/import utilities, and the report writer.
In 1985, Oracle 5 was released, which provides support for Client-Server Architecture. This
new feature has the capability to connect the client's software to a database server through a
network.
In 1989, Oracle 6 added support for PL/SQL language. It also comes with new features such
as OLTP high-speed systems, hot backup capability, and row-level locking.
In 1992, Oracle 7 was released. This version comes in the market as a result of four years of
hard work and two years of customer testing. It added some exciting features and
capabilities in the area of security, administration, development, and performance.
In 1997, Oracle 8 was released. This version comes with the support of ORDBMS that was
designed to work with Oracle's network computer (NC). It also added support for Java,
HTML, and OLTP.
In 1998, Oracle 8i was released. Here 'I' stands for Internet. It was the first database version
that added support for Web technologies such as Java and HTTP.
In 2001, Oracle 9i was released with 400 new features such as XML, RAC (Real
Application Clusters), etc. These features reduce database size and provide high availability
& enhanced performance.
In 2003, Oracle 10g was released with grid computing technology means grid. It was the
first version that supports 64-bit LINUX OS.
In 2006, Oracle 11g was released. This version comes with new features such as Oracle
Database Replay, Transaction Management using Log Miner, Virtual Column Partitioning,
Case sensitive passwords, Online Patching, Parallel Backups on the same file using RMAN,
and many others.
In July 2014, Oracle 12C was released with Cloud support.
In Feb 2018, Oracle 18 C was released. This version was the world's first autonomous
database.
B) Introduction to SQL:
SQL is a standard language for accessing and manipulating databases.SQL stands for Structured
Query Language. SQL became a standard of the American National Standards Institute (ANSI) in
1986, and of the International Organization for Standardization (ISO) in 1987.
CHARACTERSTICS OF SQL:
SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new tables in a database
SQL can create stored procedures in a database
SQL can set permissions on tables, procedures, and views
All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as their
standard database language.SQL allows users to query the database in a number of ways, using
English-like statements.
RULES For writing SQL commands:
Structure query language is not case sensitive. Generally, keywords of SQL are written in
uppercase.
Statements of SQL are dependent on text lines. We can use a single SQL statement on one
or multiple text line.
Using the SQL statements, you can perform most of the actions in a database.
SQL depends on tuple relational calculus and relational algebra.
When an SQL command is executing for any RDBMS, then the system figure out the best way to
carry out the request and the SQL engine determines that how to interpret the task.In the process,
various components are included. These components can be optimization Engine, Query engine,
Query dispatcher, classic, etc. All the non-SQL queries are handled by the classic query engine, but
SQL query engine won't handle logical files.
ADVANTAGES OF SQL:
High Speed: Using the SQL queries, the user can quickly and efficiently retrieve a large
amount of records from a database.
No Coding Needed: In the standard SQL, it is very easy to manage the database system. It
doesn't require a substantial amount of code to manage the database system.
Portability: SQL can be used in laptop, PCs, server and even some mobile phones.
Interactive Language: SQL is a domain language used to communicate with the database.
It is also used to receive answers to the complex questions in seconds.
STATEMENTS IN ISQL*PLUS:
Typethe statements directly into the Enter statements text area or work area.
Copytext from a text editor and paste it into the Enter statements area.
Use the Browse and LoadScriptbuttons to load statements from a file.
PROGRAM 2
emp_id Number
emp_name varchar(40)
department varchar(20)
designation varchar2(40)
date_of_birth date
date_of_joining date
salary number
contact_no number
address varchar2(100)
Describe the structure of the table.
Answer:
Q.2) Insert the valid data of 10 employees to the table yourname_emp. Make sure at least 2
employees should have salary < 8000.
Answer:
Q.3) Update the designation of employees who are having salary < 8000.
Answer:
Q.4) Delete all the employees who belong to a particular department.
Answer:
Q.5) Alter the structure of table yourname_emp.
Add a new column manager_name of varchar2(40) type. Update the values in the manager_name
column.
Modify the column emp_name by changing its size to 60.
Drop any two columns from the table yourname_emp.
Answer:
Q.6) Rename table yourname_emp to yourname_empcserollno.
Answer:
PROGRAM 3
Q2) Display the name and salary of all employees whose salary is between 2500 to 5000.
Answer :
Q3) Display Annual salary of all the employee and name the column as “Annual Salary”.
Answer:
Q4) Display the name and Id of all employees whose Id is not 20, 10 or 40.
PROGRAM 4
Answer:
Q3) Modify your query Prog 3_2.sql to add a column that subtracts the old salary from the new salary.
Label the column Increase.
Answer :
Q4)Write a query that displays the employee’s last name combined with first name. Label the column
Employee_Name with the first letter capitalized and all other letters lowercase.
A) Find the length of the Employee Name.
B) Find first 5 characters of the Employee Name
C) Left Padding the Employee Name upto 15 characters.
D) Right Padding the Employee Name upto 15 characters.
Answer:A)
B)
Q5) Display the highest, lowest, sum and average salary of all employees. Label the columns
MAXIMUM, MINIMUM, SUM and AVERAGE respectively. Round your result to the nearest
whole number. Save your SQL Statement in a text file as Prog 3_7.sql
Answer:
Q6)Modify the query in Prog 3_7.sql to display the maximum, minimum, sum and average salary for
each job type. Resave as Prog 3_8.sql.
Answer:
PROGRAM 5
Q2) Write a SQL statement to find the names of all customers along with the salesmen who works for
them.
Answer:
Q3) Write a SQL statement to display all those orders by the customers not located in the same cities
where their salesmen live.
Answer:
Q4)Write a SQL statement that finds out each order number followed by the name of the customers
who made the order.
Answer:
Q5) Write a SQL statement that sorts out the customer and their grade who made an order. Each of the
customers must have a grade and served by at least a salesman, who belongs to a city.
Q6) Write a query that produces all customers with their name, city, salesman and commission, who
served by a salesman and the salesman works at a rate of the commission within 12% to 14%.
Q7)Write a SQL statement that produces all orders with the order number, customer name, commission
rate and earned commission amount for those customers who carry their grade is 200 or more and
served by an existing salesman.
Q8) Write a SQL statement to make a list in ascending order for the customer who works either through
a salesman or by own.
PROGRAM 6
AIM : SubQueries in SQL
Employees_Karan:-
Q1)Write a subquery to find all employees who locate in the location with the id 1700.
Q2)Write a subquery to find the employees who have the highest salary.
Q3)Write a subquery to find all employees who salaries are greater than the average salary of all
employees.