Escolar Documentos
Profissional Documentos
Cultura Documentos
Relational databases and SQL were developed in the early 1970s at IBM.In 1979, Oracle
released the first commercial relational database that used SQL. In 1986,
the American National Standards Institute (ANSI) began publishing SQL standards.
DDL(Data Definition Language):
Permanently removes data from the table not the structure of the table.
Comment :
Insert :
Retrives records from the table.(Select statement does not do any database changes but
Oracle considers it as DML statement).
Merge:
Grant :
Revoke:
Tables:
Combination of rows and columns and stores the data.Must begin with a letter and must
not contain oracle reserve words and be Unique in the database and 1-30 characters long
and Create table privilege to create the table.
syntax:
Constraints:
Oracle server uses constrains to prevent invalid data entry into table.
NULL / NOT NULL :
NOT NULL specifies that a column must have some value. NULL (default) allows NULL
values in the column.
DEFAULT:
Specifies that column(s) must have unique values. Index is automatically generated for
column
PRIMARY KEY :
Specifies that column(s) must have unique values. Index is automatically generated for
column
FOREIGN KEY :
Specifies that column(s) are defined primary key in another table. Used for referential
uniqueness of parent table. Index is automatically generated for column
CHECK :
Suffix DISABLE to any other constraint to make Oracle ignore the constraint, the
constraint will still be available to applications / tools and you can enable the constraint
later if required.
Data dictionary views:
Restrictive data access ,different views of same data ,making complex query easy.
Difference between simple view and complex view ?
Simple view :based on one table,dml operation is possible ,no group functions and
functions.
Complex view :based on one or more than one table ,dml operation is not possible ,can
Contain group functions and group data.
syntax:-
A materialized view is a database object that contains the results of a query. They are local
copies of data located remotely.
syntax:-
Refresh option states how the refresh of remote data occurs. Fast options specifies that the
modified data be transferred through the materialized view logs ( table)
Refresh Complete states that the data be refreshed completely. Force will choose fast
refresh if possible else do complete refresh.Start date states from when refresh should start
and next date gives the duration Primary key or rowid specifies which is the used as the
key in master table.
Index :
A schema object used to improve the query performance and avoids full
Table scan. Indexes are logically and physically independent of the table.Removing a table
indexes are dropped. Altering of the index is not possible.
Create index indexname on tablename(columnname);
Unique index :
primary key and unique key columns automatically creates unique index.
Non unique index :
If the table is small and updated frequently.columns are not used In condition.queries
expected to retrive more than 2-4 percent of the rows in the table.
Use :
column contains large no. of null values and wide range of data.frequently use in the
condition. Retrive less than 2-4 percent row.
Sequence :
Cache n|nocache :
JOINS :
A join is a query that combines rows from two or more tables, views, or materialized
views.
Oracle performs a join whenever multiple tables appear in the query's FROM clause.
The query's select list can select any columns from any of these tables.
If any two of these tables have a column name in common, then you must qualify all
references to these columns throughout the query with table names to avoid ambiguity.
Most join queries contain WHERE clause conditions that compare two columns, each
from a different table. Such a condition is called a join condition.
In addition to join conditions, the WHERE clause of a join query can also contain other
conditions that refer to columns of only one table. These conditions can further restrict the
rows returned by the join query.
Equi-joins:
Nonequi-joins:
An non equijoin is a join with a join condition containing other than equality operator.
Self Join:
Outer Join:
An outer join returns all rows that satisfy the join condition and also returns some or all of
those rows from one table for which no rows from the other satisfy the join condition
Left outer join means all rows of the table left to the Join condition will appear
right outer join means all rows of the table right to the Join condition will appear
Full Outer, means missing rows from both the tables being joined.
Subquery:
(single row comparison operators can be used e.g. =, <, >, <=, >= etc.)
Multiple row subquery
Correlated subqueries enable you to use an outside reference to the query.The subquery
will get executed once for every row returned by the main query.
Functions:
Types of Functions
Single-row functions:
Operate on groups of rows and produce one result per group of rows
Set operators combine the results of two component queries into a single result
Major set operators
UNION:
All distinct rows selected by the first query but not the second.
Note:
The set operators are not valid on columns of type BLOB, CLOB, BFILE, VARRAY, or
nested table.
how to see all the indexes created on a particular table? how to view all the
indexes in a tablespace?
To see all the indexes created on a particular table you need to query all_indexes
specifying the name of the table.
example:
sql>SELECT index_name FROM all_indexes WHERE table_name = 'EMP';
To see all the indexes in a particular tablespace you just have to query all_indexes
specifying the name of the tablespace.
example:
sql>SELECT index_name FROM all_indexes WHERE tablespace_name =
'USERS';
lastday of ayear?
sql>select add_months(last_day(trunc(sysdate,'y')),11)
from dual;
display hour,min,sec,day,month,year?
sql>SELECT TO_CHAR(SYSDATE,'hh24') HOUR,
TO_CHAR(SYSDATE,'mi') MIN,
TO_CHAR(SYSDATE,'ss') sec,
TO_CHAR(SYSDATE,'dd') DAY,
TO_CHAR(SYSDATE,'mm') mth,
TO_CHAR(SYSDATE,'yyyy') YEAR
FROM dual;