Practical File SQL Queries DBMS
Practical File SQL Queries DBMS
Certificate
Teacher Incharge
Principal
Index
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.
• It is a nonprocedural language.
Components of SQL
• CHAR
• NUMBER
• DATE
• LONG.
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.
Example:
Table created.
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.
If we want to see all the tables that are already exist in the database .we use
Example:-
1 row created.
When we use the command SELECT* FRM TAB; the output is displayed as:-
ABC TABLE
ANKU TABLE
BONUS TABLE
DEPARTMENTS TABLE
DEPT TABLE
EMP TABLE
EMPLOYEE TABLE
EMPLOYEES TABLE
STUDENT TABLE
9 rows selected.
This syntax will give the unique values of column 1 and column 2.
Example:-
NAME ROLL_NO
-------------------- ----------
Prabhat 06
Example:-
Example:-
6 rows selected
6 rows selected.
6 rows selected.
Example:-
Example:-
Table renamed.
8) DESTROYING TABLES:-
• DROP COMMAND: - By using the DROP TABLE statement with the table name
we can destroy a specific table .
Example:--
Table dropped.
Example:-
Table truncated.
This command displays the columns names, the data types and the
special attributes connected to the table.
Example: -
EMP_ID NUMBER(5)
EMP_NAME VARCHAR2(20)
DEPT_ID NUMBER(10)
DEPT_NAME NAME(12)
SALARY NUMBER(21)
CONSTRAINTS
11) NOT NULL:- The NOT NULL column constraint ensures that a
table column cannot be left
Example:-
or
relatio
nships between tables. A foreign key is a column (or a group of columns)
whose values are derived from the primary key or unique key of some other
table. The table in which the foreign key is defined is called a FOREIGN
TABLE or DETAIL TABLE. The table that defines the primary or unique key
and is referenced by the foreign key is called the PRIMARY KEY or MASTER
KEY.
Example:-
Table created
DEPT_NAME VARCHAR2(25)
DEPT_LOC CHAR(5)
E_NO NUMBER(11).
• A table can have more than one unique key which is not possible in
primary key.
Example:-
Table created.
DOB DATE
NAME VARCHAR2(20)
CLASS VARCHAR2(20)
E_MAIL VARCHAR2(20)
ORACLE FUNCTIONS
Example:-
1 sourabh 21 55000
2 sonu 22 55000
3 anku 4 55000
5 anku 21 55000
3 panku 22 75000
COUNT(DISTINCTNAME)
-------------------
COUNT(SALARY)
----------
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’.
Example:-
SUM(SALARY)
-----------
295000
Example:-
MAX(SALARY)
-----------
75000
Example:-
MIN(SALARY)
-----------
55000
19) THE AVG FUNCTION: - Returns an average value of ‘n’, ignoring null
values in a column.
Example:-
AVG(SALARY)
-----------
59000
Example:-
3 anku 4 55000
5 anku 21 55000
Example:-
1 sourabh 21 55000
2 sonu 22 55000
3 panku 22 75000
3 anku 4 55000
5 anku 21 55000
Example:-
2 sonu 22 55000
3 panku 22 75000
• NOT IN OPERATOR:-
Example :-
1 sourabh 21 55000
3 anku 4 55000
5 anku 21 55000
2 sonu 22 55000
3 panku 22 75000
1 sourabh 21 55000
5 anku 21 55000
STRING FUNCTIONS
Syntax: - UPPER(char)
Example: -
UPPER(NAME)
--------------------
SOURABH
SONU
ANKU
ANKU
PANKU
Syntax: - LOWER(char)
Example:-
LOWER(NAME)
--------------------
sourabh
sonu
anku
anku
panku
Syntax:- INITCAP(char)
Example:-
INITCAP(NAME)
--------------------
Sourabh
Sonu
Anku
Anku
Panku