Database Concepts

What is Database? A database can be defined as a collection of coherent ,meaningful data. A set of inter-related data is known as database e.g Address book is Dbase and postal addresses in that book is the data that fills the database.

Database Management system: A computer based record keeping system which consists of software for processing a collection of inter-related data.

Def Of DBA: The database is centrally managed by a person known as the database administrator or the DBA. Responsibilities of DBA: 
Initially Studies the system Accordingly decides the types of data to be used. Decides structures to be used to hold the data and the relationships between the data structures. Ensures the security of the database. DBA usually controls access to the data through the user codes and passwords and by restricting the views or operations that the user can perform on the database.

Characteristics of DBMS 
Control of data Redundancy Sharing of data Maintenance of integrity Support for transaction Control and Recovery Data independence Availability of Productivity Tools Control over security Hardware independence

DBMS Models 1. Hierarchical 2.Network 3.Relational

Relational data consists of relations. A relational table consists of a set of named columns and an arbitrary number of rows.g Dept table Dept No Dname 1 Accounts 2 Purhase Loc Pune Bombay row or tuple Column or attribute .Relational DBMS The relational model presents an orderly . Each column or attribute is associated with a domain. A relation is a two dimensional table with special properties.manipulating and viewing data.predictable and intuitive approach to organizing. E. A domain is a set of values that may appear in one or more columns.

.Properties Of Relational Structures Entries of attributes are single valued Entries of attributes are of the same kind No two rows are identical The order of attributes is unimportant The order of rows is unimportant Every column can be uniquely identified.

Command level 3.DBMS V/S RDBMS DBMS RDBMS Relationship between two tables or Relationship between two tables or files are maintained programmatically files can be specified at the time of table creation.Logging in at O/S level 2.Object level Many tables are grouped in one database Each table is given an extension . Does not support Client/Server architecture Does not support Distributed databases In DBMS no security of data Most of the RDBMS supports Client/Server architecture Most of the RDBMS supports Distributed databases In RDBMS there are multiple levels of security 1.

Attribute Row.Relation.Naming Conventions DBMS Field Record File RDBMS Column. Entity Class .Entity Table.tuple.

To structure the data between tables so that data maintenance is simplified. Normalization is the process that helps analyst or database designers to design table structures for an application. 5. .making them normal. To reduce the need to restructure tables as new application requirements arise To improve the quality of design for an application by rationalization of table data. 4. Normalization is carried out for following reasons: 1. To allow data retrieval at optimal speed. To simplify data maintenance through updates. 2. 3.inserts and deletes.Normalization : Normalization is the process of putting things right .

the table is said to be in its first normal form. Decomposes data into two-dimensional tables. 2. Eliminates any relationships in which table data does fully depend upon the primary key of a record. A table is in 1st NF if: ‡ ‡ ‡ There are no repeating groups.Normalization is technique that: 1. 3. First Normal Form: When a table is decomposed into two-dimensional tables with all repeating groups of data eliminated . . All the key attributes are defined All are dependent on a primary key. Eliminates any relationship that contains transitive dependencies.

To understand the application of normalization to table data the following table structure will be taken as an example: Table: EmpProj Field Project Number Project Name Employee Number Employee Name Rate Category Hourly Rate Key ------- Type 1-n 1-n 1-n 1-n .

After Converting this data to its 1NF : Field Project Number Project Name Employee Number Employee Name Rate Category Hourly Rate Key Primary key Primary key .

e.Second Normal Form: A table is said to be in 2nd NF when each record in the table is in the 1NF and each column in the record is fully dependent on its primary key. . The steps to convert a table to its 2Nf: 1.Group the removed items in the another table 3. part of a whole composite key. To convert the table into the 2nd NF remove and place these fields in a separate table. with the key being that part of the original key are dependent on.find and remove fields that related to the only part of the key. 2.Assign the new table with the key I.

After Converting to 2NF : Field Project Number Employee Number Key Primary key Primary key Field Project Number Project Name Key Primary key -- Field Employee Number Employee Name Rate Category Hourly rate Key Primary key ---- .

which are linked using a Foreign key.C must be placed in separate tables.B.B.This means that columns A.Third Normal Form: Table data is said to be in 3NF when all transitive dependencies are removed from this data. . To Convert such data into 3NF remove this transitive dependency bu splitting each relation into two separate relations. A general case of transitive dependencies : A.C are three columns in table: If C is related to B If B is related to A. Then C is indirectly related A This is when transitive dependency exists.

After Converting to 3NF: Empproj Field Project Number Employee Number Emp Field Employee Number Employee Name Rate Category Key Primary key -Foreign Key Field Rate Category Hourly rate Rate Key Primary key -Key Primary key Primary key Proj Field Project Name Key -- Project Number Primary key .

Most RDBMS provide extensions to it to make the life of the application programmer easier. 4. . Data Control Language (DCL):This is used for defining your security for your application objects like tables etc. ANSI has standardized the commands and relational databases conform to this standard. Components Of SQL : SQL can be broadly classified into four components. Oracle has modified SQL to support ORDBMS features.What is SQL ? SQL or Structured Query Language is the set of commands. which is used for interacting with relational Databases. Data Manipulation Language (DML):This is used to modify the data according to our needs . Data Definition Language (DDL) :This component is used for defining and destroying objects in your application. 3. 2. Data Query Language (DQL):This is used to retrieve the data as per requirement. 1.

Examples of DDL. including all spaces allocated for the records are removed Commit ± gives user¶s access privileges to database. DML:     Insert ± Insert data into table Update ± Updates existing data within a table. the space for record is remain Lock table control concurrency .deletes object from database Truncate ± remove all records from table .DQL DDL:       Create . Revoke ± withdraw access privileges given with the GRANT command.Alters the structure of the database Drop .DML.DCL.To create objects in database Alter . Delete ± Deletes all records from a table.

DCL: Commit ± save work done Savepoint ±Identify a point in a transaction to which you can later roll back Rollback ± restore database to original since the last commit Grant / Revoke ± Grant or take back permission to and from the oracle user DQL: Select ± Retrieve . 2. ‡Provides automatic navigation to the from the database. Benefits of SQL : Non-procedural Language ‡processes sets of records rather than just one record at a time.Language For All users ‡System Administrator ‡Database Administrator .

g.g. Name char(15) 2.g.99E125 . Unified Language Data Types Supported in SQL: 1. Salary number(9. max digits = 38 e. Long(n) :To store variable length string .s) : To store numerical data .e. max length =255 bytes e. Char(n) : To store Fixed Length string . E. Synopsis Long(5000) 4.‡ ‡ ‡ Security Administrator Application Programmers End-Users 3. Range 1E-129 to 9. Number(p. Varchar2(n) : To store variable length string max length = 2000 bytes .g.max length= 2GB .2) . Description varchar2(1000 3.

. Nested Tables. Max size=255 bytes 7. Max size = 2GB. Range 01/01/4712 BC to 31/12/4712 AD. Raw(n) : To store data in binary format such as signature . Both date and time are stored. E. REFS and LOBS.photograph .Long Raw(n) : Same as Raw.5. Requires 8 bytes . Hiredate date 6. Date : To store date . They are Varrays. Oracle has added New Data types to support object extensions.g.

which satisfies the condition set . Business Rules . Business Rules that are applied to data are completely System dependant. Such Rules have to be enforced on data stored. Business Managers determine a set of business rules that must be applied to their data prior to it being stored in the database/table to ensure its integrity.Data Constraints All Business World run on business data being gathered . Only data . This ensures data stored in a table will be valid . If the data gathered fails to satisfy the condition set. it must be rejected . which are enforced on data being stored in a table are called Constraints. and have integrity. . should be stored for future analysis . stored and analyzed .

There are Two Types Of Data Constraints that can be applied to data being inserted in Oracle table.determines the speed at which data can be inserted or extracted from oracle table. Business Rule Constraint I/O Constraints:  Primary Key Foreign Key Unique Key Business Rule Constraint Null Value Constraint Check Constraint Default Value Constraint . I/O Constraints Input / output Constraints .

‡ Syntax: <column name> <datatype> (<size>) PRIMARY KEY Or PRIMARY KEY(<column name>. ‡ Primary key is not compulsory but it is recommended. Its main purpose is the Record uniqueness. ‡ Only one primary key is allowed per table . ‡ Primary Key Will not allow duplicate values and null values.Primary Key : ‡ Primary key is a column or set of columns that uniquely identifies a row .<column name>) . and can be formed by combining maximum 16 columns ‡ Primary Key helps to identify one record from another record and also helps in relating tables with another.

‡ Foreign Key represents relationships between tables. . ‡ Parent record can be delete provided no child record exists ‡ Master table can not be updated if child record exists ‡ If the ON DELETE CASCADE option is set . ‡ If the ON DELETE SET NULL option is set . a DELETE operation in the Master table will set the values held by the foreign key of the detail tables to null.Foreign Key : ‡ A Foreign key is a column or columns whose values are derived from the Primary key or Unique Key of some other table. ‡ Foreign key constraint can be specified on child but not on parent. a DELETE operation in the Master table will trigger a DELETE operation for corresponding records in all detail table.

Syntax: <Column name > <data type> (<size>) REFERENCES <Table Name> [(<column name>)] [ON DEELETE CASCADE ] Or FOREIGN KEY (<column name > [.<column name>) ON DELETE SET NULL .<column name>) Or CONSTRAINT <constraint name> FOREIGN KEY (<column name > [. <column name>]) REFERENCES <Table Name> [(<column name>. <column name>]) REFERENCES <Table Name> [(<column name>.

<coumn name2>) . ‡ Syntax: <column name> < Data type> (<size>) UNIQUE Or UNIQUE (<column name1>. ‡ Unique Key will not allow duplicate values ‡ A table can have more than one Unique Key which is not possible in Primary key ‡ Unique Index is created automatically.Unique Key ‡ The Unique column constraint permits entries of NULL into the column . ‡ Unique Key can combine up to 16 columns in composite Unique key.

UID.USRNV SQL functions. ‡ The Check constraint must be satisfied for the write operation to succeed.USER. ‡ The condition can not contain subqueries or sequences. ‡ Check constraint can be bound to a column or a table using the CREATE or ALTER command. A check constraint has the following limitations: ‡ The condition must be a Boolean expression that can be evaluated using the values in the row being inserted or updated. ‡Syntax: <column name> <data type>(<size>) CHECK (<logical expression>) .Check Constraint: ‡ Business rules can be implemented in Oracle by using CHECK constraint. ‡The condition can not include the SYSDATE.

‡ Now . This could be because the information is not available at the time of data entry or because the field is not applicable in every case. an empty string is treated as a null value in oracle.Null Value Concept: ‡ Often there may be records in a table that do not have values for every field. ‡ A NULL value can be inserted into columns of any data type. ‡ NOT NULL column constraint ensures that a table column can not be left empty. NOT NULL Constraint : ‡ When a column is defined as NOT NULL . If the column was created as NULLABLE . ‡ Syntax: <column name> <data type> (<size>) NOT NULL . Oracle will place a NULL value in the column in the absence of a user-defined value.then that column becomes mandatory column. ‡ A NULL value is different from a blank or a zero.

‡ Syntax: <column name> <data type>(<size>) DEFAULT <value> . the Oracle engine will automatically load this column with the default value specified. ‡ When a record is loaded into the table. ‡ The data type of the default value should match the data type of the column.Default Constraint: ‡ At the time of table creation a default value can be assigned to a column. and the column is left empty . ‡ The DEFAULT clause can be used to specify a default value fro a column.

Constraint at column level Create table emp ( eno varchar2(10) Primary key.Example for all Data Constraint 1. Addr2 varchar2(30). Comm number(10. Addr1 varchar2(30) Not Null. Check(eno like µC%¶) ). Deptno number(2) references dept(deptno) . Sal number(10. .2) Not Null.2) Default 0. Ename varchar2(20) Not Null.

2) Not Null. Ename varchar2(20) Not Null. Constraint PK_emp Primary Key(empno). . Sal number(10. Addr2 varchar2(30).2. Constraint at table level Create table emp ( eno varchar2(10) . Check(eno like µC%¶). Addr1 varchar2(30) Not Null.2) Default 0. Comm number(10. Constraint FK_deptno references dept(deptno) ). Deptno number(2) .

Sign up to vote on this title
UsefulNot useful