0% found this document useful (0 votes)
84 views

SQL Preparation

Fields are the smallest units that make up records in a table. Records contain fields or columns, and tables contain collections of fields and records. A primary key uniquely identifies records in a table, while a foreign key links records between tables by referring to a primary key. A composite index uses multiple columns to uniquely identify records. Databases contain collections of tables and objects. DBAs manage database integrity, security, performance, and recovery using tools. Developers use front-end tools like forms and reports and back-end tools like schema and query builders to build applications. Tables can have keys like unique, primary, and foreign keys, but shouldn't have too many. Joins combine records from two or more tables. Subqueries can reference

Uploaded by

imranbaiggeek
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

SQL Preparation

Fields are the smallest units that make up records in a table. Records contain fields or columns, and tables contain collections of fields and records. A primary key uniquely identifies records in a table, while a foreign key links records between tables by referring to a primary key. A composite index uses multiple columns to uniquely identify records. Databases contain collections of tables and objects. DBAs manage database integrity, security, performance, and recovery using tools. Developers use front-end tools like forms and reports and back-end tools like schema and query builders to build applications. Tables can have keys like unique, primary, and foreign keys, but shouldn't have too many. Joins combine records from two or more tables. Subqueries can reference

Uploaded by

imranbaiggeek
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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