SQL Preparation
-
Upload
imranbaiggeek -
Category
Documents
-
view
216 -
download
0
Transcript of SQL Preparation
-
8/14/2019 SQL Preparation
1/3
Fields: Smallest unit in a table
Records: collections of fields or columns
Table: Collections of fieldsPrimary 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 ofthe database is maintained by DBAs. 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 toclients.
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 databaseINNER JOIN OR EQUI JOIN
Cartisian Product: xOuter 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
Usingdisplayes only one caolumnOn displays all the common columns
Using = On(are interchangeable
A correlated sub-query is a term used for specific types ofqueries inSQL in computerdatabases. 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 rowprocessed 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 queriesIf the escape character is & then to find %, _ in the string use the querySELECT * 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.
http://en.wikipedia.org/wiki/Query_languagehttp://en.wikipedia.org/wiki/SQLhttp://en.wikipedia.org/wiki/SQLhttp://en.wikipedia.org/wiki/Databasehttp://en.wikipedia.org/wiki/Where_(SQL)http://en.wikipedia.org/wiki/Query_languagehttp://en.wikipedia.org/wiki/SQLhttp://en.wikipedia.org/wiki/Databasehttp://en.wikipedia.org/wiki/Where_(SQL) -
8/14/2019 SQL Preparation
2/3
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_nameFIELDS 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)
BEGINDATAColumn1_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 , withoutvalues like ename, empno, , sal
If values are freom the data file then no need
LOAD DATA INFILE
*
APPEND INTO TABLE emp1FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS(
empno,
ename,
sal,comm,
deptno
)
BEGINDATA
2222, "IMRAN BAIG", ,22, 203222, "IMRAN,BAIG", 3222, 32, 20
4222, "IMRAN&BAIG", 4222, 42, 30
Exists Operator
-
8/14/2019 SQL Preparation
3/3
If the sub-query returns data, then the EXISTS operation will return TRUE and a record
from the parent query will be returned.