You are on page 1of 3

Fields: Smallest unit in a table

Records: collections of fields or columns


Table: Collections of fields
Primary Key: A primary key has a immutable responsibility of serving a unique identifier
in a table.
Foreign Key: Is a column that refers to a primary key in another table.
Composite Index: more than one column are included to make primary key
Database: Collections all the tables and objects are called database
DBA: The integrity, security, connectivity, performance, tuning, ensuring the recovery of
the database is maintained by DBA’s. They use oracle enterprise management tools to do
the task.
Developers: They use tools like forms, reports, graphics for front-end development,
schema, procedure, query builder tools for back end. Project builder tools for delivery to
clients.
A table can have unique keys, composite keys, primary keys, foreign keys. Avoid having
too many keys on the table.
Joins: Joining two or more tables is the best use of relational database
INNER JOIN OR EQUI JOIN
Cartisian Product: x
Outer Join: Matching + unmatched Records
If Join keyword is used in the query then On key word condition is used or else Where
condition: only for natural join on key, where is not required
Using¨displayes only one caolumn
On displays all the common columns
Using = On(are interchangeable
A correlated sub-query is a term used for specific types of queries in SQL in computer
databases. It is a sub-query (a query nested inside another query) that uses values from
the outer query in its WHERE clause. The sub-query is evaluated once for each row
processed by the outer query.

Employees with their managers

Select e.empno, e.ename, e.mgr , m.empno, m.ename from emp e, emp m where e.mgr =
m.empno;

Escape Character queries


If the escape character is & then to find %, _ in the string use the query
SELECT * FROM emp WHERE ename LIKE '%^_%^%%' ESCAPE '^'

insert into emp1 (ename) values ('IMRAN&BAIG%1_2#')


NOTE: Error it will ask for value of baig
If you want to insert & in the field then
From sql> prompt set define off then insert statement
This will work.
SQL Loader:
LOAD DATA
INFILE ‘path’ or *(if the data is given using BEGINDATA key in the ctl file at the
end)
APPEND/INSERT/REPLACE INTO TABLE table_name
FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘”’
(
column_name1 [position(value1:value2) if begindata is used] ,
column_name2 [position(value1:value2) if begindata is used] ,
column_name3 [position(value1:value2) if begindata is used] ,
.
.
.
)
[([] means optional)
BEGINDATA
Column1_value Column2_value Column3_value………(give exact positions)
]

TRAILING NULLCOLS will allow null values into the table columns
BELOW is an example
If values are giving using begindata then null values can be passed by giving , without
values like ename, empno, , sal
If values are freom the data file then no need

LOAD DATA INFILE


*
APPEND INTO TABLE emp1
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'

TRAILING NULLCOLS
(
empno,
ename,
sal,
comm,
deptno
)

BEGINDATA
2222, "IMRAN BAIG", ,22, 20
3222, "IMRAN,BAIG", 3222, 32, 20
4222, "IMRAN&BAIG", 4222, 42, 30
Exists Operator
If the sub-query returns data, then the EXISTS operation will return TRUE and a record
from the parent query will be returned.

You might also like