A Program Lab Report On: Bachelor of Computer Applications
A Program Lab Report On: Bachelor of Computer Applications
On
DBMS (506P)
As the tool that is employed in the broad practice of managing databases, the
DBMS is marketed in many forms. Some of the more popular examples of
DBMS solutions include Microsoft Access, FileMaker, DB2, and Oracle. All
these products provide for the creation of a series of rights or privileges that
can be associated with a specific user. This means that it is possible to
designate one or more database administrators who may control each function,
as well as provide other users with various levels of administration rights. This
flexibility makes the task of using DBMS methods to oversee a system
something that can be centrally controlled, or allocated to several different
people.
Introduction to Structured Query Language
(SQL)
Structured query language is a language that provides an interface to relational
database systems. SQL was developed by IBM in the 1970s for use in system R,
and is a de facto standard, as well as an ISO and ANSI standard. SQL is often
pronounced SEQUEL.
SQL has been a command language for communication with the oracle 9i
server from any tool or application. Oracle SQL contains many extensions.
When an SQL statement is entered, it is stored in a part of memory called the
SQL buffer and remains there until a new SQL statement is entered.
It is a nonprocedural language.
It reduces the amount of time required for creating and maintaining systems.
It is English like language.
Components of SQL
CHAR
VARCHAR (size) or VARChAR2 (size)
NUMBER
DATE
LONG.
data type that is used to store number data can be specified either to store
integers or decimals with the addition of a parenthetical precision
indicator. If we do not use then the default value is 0 and if we don’t use
precision then by default value stored can be of 38 digits.
DATE:- The DATE data type stores date and time information. Although
date and time information can be represented in both character and number
data types, the DATE data type has special associated properties. For each
DATE value, Oracle stores the following information: century, year, month,
date, hour, minute, and second.
QUERY
A query is a concise memo submitted to an editor by a writer seeking publication. It is basically
an in query to see whether the writer’s work is of interest to a particular publication. A query
briefly details a writer’s experience and knowledge of the subject matter, and gives a summary
or synopsis of the article the writer hopes to have published. An approximate word count for
the proposed article or feature is also generally included.
1) THE CREATE TABLE COMMAND :- The CREATE TABLE command defines each
column of the table uniquely. Each column
has a minimum of three attributes, a name, data type and size (i.e. column width).
Example:
SQL> create table student(name varchar(23),roll_no number(12),class
varchar2(12),address varchar(23));
Table created.
2) THE INSERTION OF DATA INTO TABLE: - Once a table is created, the most
natural thing to do is load this with data to
be manipulated later i.e. to insert the rows in a table. The data in a table can be
inserted in three ways.
OR
OR
Example:-
SQL> insert
intostudent(name,roll_no,class,address)values('Prabhat',06,'BCA',Hat
limore');
1 row created.
Or
1 row created.
Or
1 row created.
FOR inserting more values we use ‘/’ slash after SQL> as below but after above
syntax used:
SQL> /
1 row created.
3) FOR VIEWING DATA IN THE TABLE: - Once data has been inserted into a
table, the next most logical operation would be to
view what has been inserted. The SELECT SQL verb is used to achieve this. The
SELECT command is used to retrieve rows selected from one or more tables.
Syntax: - SELECT * FROM <table name>;
If we want to see all the tables that are already exist in the database .we use
SELECT * FROM TAB;
Example:-
SQL> select * from student;
1 row created.
When we use the command SELECT* FRM TAB; the output is displayed as:-
SQL> select * from tab;
ABC TABLE
ANKU TABLE
BONUS TABLE
DEPARTMENTS TABLE
DEPT TABLE
EMP TABLE
EMPLOYEE TABLE
EMPLOYEES TABLE
STUDENT TABLE
9 rows selected.
4) ELIMINATION OF DUPLICATE ROWS :- A table could hold duplicate rows in
such a case, only unique rows the distinct
clause can be used.
Syntax: - SELECT DISTINCT <column name 1>,<column name2> FROM <table name> ;
This syntax will give the unique values of column 1 and column 2.
Example:-
SQL> select distinct name,roll_no from student;
NAME ROLL_NO
Prabhat 06
6 rows selected
6 rows selected.
6 rows selected.
6) MODIFYING THE STRUCTURE OF TABLES: - The structure of a table can be
modified by using the ALTER
TABLE command. ALTER TABLE allows changing the structure of an existing table.
With ALTER TABLE it is possible to add or delete columns, create or destroy indexes,
changes the data type of existing columns, or rename columns or the table itself.
(a) ADDING NEW COLUMNS
Syntax: - ALTER TABLE <Table name> ADD(<New column Name> <data type> (<size>),<new
column name><data type>(<size>)….);
Example:-
(b) DROPPING A COLUMN FROM A TABLE
Syntax: - ALTER TABLE<TABLE NAME>DROP COLUMN<COLUMNNAME>;
Example:- alter table prabhu drop column name;
Table renamed.
8) DESTROYING TABLES:-
DROP COMMAND: - By using the DROP TABLE statement with the table name we can
destroy a specific table .
Syntax: - DROP TABLE <table name>;
Example:--
Example:-
CONSTRAINTS
11) NOT NULL:- The NOT NULL column constraint ensures that a table
column cannot be left empty. When a column is defined as not null, then
that column becomes a
mandatory column. It implies that a value must be entered into the column if the record is
to be accepted for storage in the table.
Syntax:- <Column Name> <data type>(<size>) NOT NULL ;
Example:-name varchar(22) not null;
THE PRIMARY KEY CONSTRAINT: - A primary
is one or more column in a table used to
identify each row in a table. None of the
fields that are part of the primary key can contain a null value. A table can have only
one primary
Syntax:- <Column name> <data type>(<size>) PRIMARY
KEY Example:-
Table created
13) THE UNIQUE KEY CONSTRAINT:- The unique key constraint permits multiple
entries of NULL into the column. These NULL
values are clubbed at the top of the column in the order in which they were entered into
the table. This is the essential difference between the primary key and the unique
constraints when applied to table column(s). Key point about UNIQUE constraint:
Unique key will not allow duplicate values.
Unique index is created automatically.
A table can have more than one unique key which is not possible in primary key.
Table created.
ORACLE FUNCTIONS
Oracle functions serve the purpose of manipulating data items and returning a result.
Functions are the programs that take zero or more arguments and return a single value.
Oracle has built a no. of functions into SQL. These functions can be called from SQL
statements.
14) COUNT (expr) function: - Returns the number of rows where expression is
not null. Syntax: - COUNT ([<distinct>[<all>] <expr>)
Example:-
COUNT(DISTINCTNAME)
-
4
COUNT(SALARY)
- -
5
15) COUNT (*) function: - Returns the number of rows in the table, including duplicates
and those with nulls.
Syntax: - COUNT(*)
Example:-
COUNT(*)
salary
16) THE SUM FUNCTION: - Returns the sum of the values of ‘n’.
Syntax: - SUM ([<distinct>][<all>] <expr>)
Example:-
SUM(SALARY)
295000
MAX(SALARY)
75000
Example:-
SQL> select min (salary) from employees;
MIN(SALARY)
55000
19) THE AVG FUNCTION: - Returns an average value of ‘n’, ignoring null values in a
column.
Syntax: - AVG ([<distinct>][<all>] <n>);
Example:-
AVG(SALARY)
59000
Example:-
3 anku 4 55000
5 anku 21 55000
NOT LIKE OPERATOR:-
Example:-
SQL>select emp_id,name,dept_id,salary from employees
where name not like 'a%';
NOT IN OPERATOR:-
Example :-
SQL>select emp_id,name,dept_id,salary from employees where
dept_id not in(20,22);
- - -
1 sourabh 21 55000
3 anku 4 55000
5 anku 21 55000
STRING FUNCTIONS
UPPER(NAME)
SOURABH
SONU
ANKU
ANKU
PANKU
LOWER(NAME)
sourabh
sonu
anku
anku
panku
25) INITCAP function: - Returns a string with the first letter of each word in
upper case.
Syntax:- INITCAP(char)
Example:-
INITCAP(NAME)
Sourabh
Sonu
Anku
Anku
Panku