Академический Документы
Профессиональный Документы
Культура Документы
Certificate
Index
S. no. Name of practical Remarks
1. Database, DBMS definition
2. Introduction to SQL
3. Components of SQL, Data types
4. SQL Queries create, insertion
5. Create a table
6. Describe the table
7. Insert the values
8. To view the table
9. Sorting the data
10. To rename the table
11. Delete a particular row
12. Lower case
13. Upper case
14. Drop the table
15. Maximum
16. Minimum
17. Average
18. Like
19. Between
20. Primary key
21. Unique key
22. Count
23. Sum
24. Alter
25. Update
Database
A database is an organized collection of facts. In other words, we can say that it is
a collection of information arranged and presented to serve an assigned purpose.
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.
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
Ashoka College of Computer Education |
6
DBMS & SQL queries
2) DML (Data Manipulation Language):- It is the area of SQL that allows changing
data within the database.
3) DCL (Data Control Language):- It is the component of SQL statement that control
access to data and to the database. Occasionally DCL statements are grouped with DML
statements.
4) DQL (Data Query Language):- It is the component of SQL statement that allows
getting data from the database and imposing ordering upon it. It includes the SELECT
statement. This command is the heart of SQL. It allows getting the data out of the
database perform operations with it. When a SELECT is fired against a table or tables the
results is compiled into a further temporary table, which is displayed or perhaps received
by the program i.e. a front-end.
Data types come in several forms and sizes, allowing the programmer to create tables suited to
the scope of the project. The decisions made in choosing proper data types greatly influence the
performance of a database. The information in the database is maintained in the form of tables
and each table consists of rows and columns, which store data and therefore this data must have
some data type i.e. the type of data, which is stored in the table.
CHAR
VARCHAR (size) or VARChAR2 (size)
NUMBER
DATE
LONG.
CHAR: - This data types 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. The data held is right- padded with spaces to whatever
length specified.
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
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:
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;
9 rows selected.
NAME ROLL_NO
-------------------- ----------
Prabhat 06
6 rows selected
6 rows selected.
6 rows selected.
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:--
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;
Table created
DEPT_NAME VARCHAR2(25)
DEPT_LOC CHAR(5)
E_NO NUMBER(11).
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(*)
----------
5
salary
----------
5
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.
AVG(SALARY)
-----------
59000
20) LIKE OPREATOR :- The LIKE predicate allows comparison of one string value with
another string value, which is not identical. This is achieved by using
wildcard characters. Two wildcard characters that are available are:
% allows to match any string of any length(including zero length)
_allows to match on a single character.
Example:-
Example:-
21) IN OPERATOR:- In case a value needs to be compared to a list of values then the IN
predicate is used. The IN predicates helps reduce the need to use
multiple OR conditions.
Example:-
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
3 panku 22 75000
STRING FUNCTIONS
23) UPPER function :- Returns char, with all letters forced to uppercase.
Syntax: - UPPER(char)
Example: -
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