steps in table creation:
* Identify data types for attributes
* Identify colums that can and cannot be null.
* Identify columns that must be unique (candidate keys)
* dentify primary key foreign key mates
* Determine default values
* Identify constraints on columns(domain specifications)
* Create the table and associated indexes
Common SQL data Types:
* String types
-> CHAR(n)- fixed length character data, n characters long Maximum length = 2000
bytes
->VARCHAR 2(n) - variable-length character datem up to 4GB .Maximum 1 per table.
->LONG-variable-length
* Numneric types
* Data\Time Type
SQL Environment:
* Catalog-a set of schemes that constitute the discription of a
database(Dictionary)
* Schema- The structure that contains descriptions of objects created by a user
(base tablesm views, constraints)
* Data Definition Language (DDL)-Commands that define a database, including
creating, altering and dropping tables and establishing contraints
* Data Manipulation Language(DML)-Commands that maintain and query a database
* Data Control Language-Commands that control a databasem including administering
privileges and committing data.
SYSTEM DATABASE DEFINITION:
* Data Definition Language
* Major CREATE statements:
-> CREATE SCHEMA-defines a portion of the database owned by a particular user
-> CREATE TABLE-defines a table and its columns
-> CREATE VIEW- defines a logival table from one or more views
* Other CREATE statements: CHARACTER SET,Sequence, Index,
Constraint,Role,......etc.,
DELETE & UPDATE:
* After using any DML statement (insert, delete, update ), save the changes using
the command.COMMIT
* Incase you want to undo your DML statements use the command:Rollback
UNSPECIFIED WHERE-cluase
a missing WHERE-clause indicates no condition; hence, all tuples of the relations
in the FROM-clause are selected
this is equivalent to the condition WHERE TRUE
USE OF :
To retrieve all the attribute values of the selected tuples, a * is used, which
stands for all the attributes
USE OF DISTINCT:
SQL does not treat a relation as a set; duplicate tuples can appear \
To eliminated duplicate tuples in a query result
SET OPERATIONS:
* SQL has directly incorporated some set operations
* There is a union operation , and in some versions of SQL there are set difference
and intersection operations
* The resulting relations of thses set operations are sets of tuple; duplicate
tuples are eliminated from the result
* The set operations apply onlyh to union compatible relations; the two relations
must have the same attributes and the attributes must appear in the same order
NESTING OF QUERIES:
* A complelete SELECT query, called a nested query, can be specifies within the
WHERE-clause of another query m called th outer auery
* Many of the previous queries can be specified in an alternative from using
nesting
the nested query selects the number of the 'reserch ' department
CORRELATED NESTED QUERIES:
* If a condition in the WHERE-clause of a nested query references an attribute of a
relation declared in the outer query, the two queries are said to be correlated
* The result of a correlated nested query is different for each tuple for
combination of tuples of the relations the outer query
AGGREGATE FUNCTIONS:
* Include COUNT,SUM,MAX,MIN,AND AVG
GROUPING:
in many cases, we want to apply the aggregatae functions to subgroups of tuples in
a relation