This action might not be possible to undo. Are you sure you want to continue?
An Introduction to Database Concepts
DATABASE DBMS & RDBMS DATABASE MODELS DATABASE OBJECTS NORMALIZATION SQL COMMANDS & FUNCTIONS JOINS
• A database is a structured collection of records or data that is stored in a computer system so that a computer program or person can easily retrieve and manipulate the data using a query language.
Database Management System[DBMS]
• A database management system (DBMS) is computer software designed for creating and maintaining databases and allows users to retrieve information from that database.
Relational Database Management System[RDBMS]
• A type of DBMS in which the database is organized and accessed according to the relationships between data values. It is based on the relational model.
•Oracle, DB2, MS SQL Server,Teradata
• A database model is a theory or specification describing how a database is structured and used.
Three types of Data models are… Hierarchical Model Network model Relational Model
• Hierarchical data model organizes data in a tree structure,hierarchy is of parent and child data segments.hierarchical model structures data as a tree of records, with each record having one parent record and many children
Network Data Model
• Network data model organize data as a network and the network model allows each record to have multiple parent and child records.
Relational Data Model
• A relational database allows the definition of data structures, storage and retrieval operations and integrity constraints. In such a database the data and relations between them are organised in tables.
Database Objects Table
Table is a database object or structure where the data is stored.A table will contains rows and columns. A row in a table is called 'tuple' and the column in the table is called 'Attribute'.
• A view is a virtual, dynamic or logical table computed or collated from data in the database. • Changing the data in a table alters the data shown in the view.
Database Objects Stored Procedure
A stored procedure is a subroutine available to applications accessing a relational database system. Stored procedures are actually stored in the database.
A database trigger is procedural code that is automatically executed in response to certain events on a particular table in a database. Triggers can restrict access to specific data, perform logging, or audit data modifications.
Database Objects • Index A database index is a data structure that improves the
speed of operations in a table.Indexes can be created using one or more columns.The disk space required to store the index is typically less than the storage of the table , or audit data modifications.
Types of Index are Unique Index Non-unique Index
Keys in a table Primary Key
• It is a unique and non-nullable attribute of the table • The primary key of a relational table uniquely identifies each record in the table.
• It is a field in a relational table that matches the primary key column of another table. • Foreign key is used to establish and enforce a link between the data in two tables.
Keys in a table Candidate Keys
• A key that uniquely identifies rows in a table. Any of the identified candidate keys can be used as the table's primary key.
• A Candidate Key as a Super Key that contains only the minimum number of columns necessary to determine uniqueness.
It is a technique for designing relational database tables to minimize duplication of information.
The goals of normalization are, Eliminating redundant data Ensuring data dependencies make sense
Database Normalization Types of Normalization are
1st Normal form 2nd Normal form 3rd Normal form Boyce-Codd Normal Form 4th Normal form 5th Normal form
1st Normal form
A relation to be in 1NF, each column must contain only a single value and each row must contain the same columns.
2nd Normal form
In order to be in Second Normal Form, a relation must first fulfill the requirements to be in First Normal Form. Additionally, each nonkey attribute in the relation must be functionally dependent upon the primary key.
3rd Normal form
In order to be in Third Normal Form, a relation must first fulfill the requirements to be in Second Normal Form. Additionally, all attributes that are not dependent upon the primary key must be eliminated.
Boyce-Codd Normal Form
A relation is in Boyce-Codd Normal Form (BCNF) if every determinant is a candidate key.
4th Normal form
To be in Fourth Normal Form, a relation must first be in Boyce-Codd Normal Form. Additionally, a given relation may not contain more than one multivalued dependency.
5th Normal form
A 4NF table is said to be in the 5NF if and only if every join dependency in it is implied by the candidate keys.
Structured Query Language[SQL]
SQL is an ANSI standard computer language for accessing and manipulating Database systems. Data Definition Language[DDL] Data Manipulation Language[DML] Data Control Language [DCL] Transaction Control Language[TCL]
Data Definition Language [DDL]
SQL statements that can be used either interactively or within programming language source code to define databases and their components. DDL commands are …
CREATE -Create tables ALTER -Changing the table definition DROP -Drop tables RENAME -Renaming table TRUNCATE -Deletes the data
Data Manipulation Language [DML]
SQL statements that can be used to manipulate the data in a relational table. It includes …
SELECT UPDATE DELETE INSERT INTO - extracts data from a database table - updates data in a database table - deletes data from a database table - inserts new data into a database table
Data Control Language[DCL]
SQL statements that can be used for control access to data in a database. It includes…
GRANT -to allow specified users to perform specified tasks. REVOKE- to cancel previously granted or denied permissions
Transaction Control Language[TCL]
SQL statements that can be used for used to control transactional processing in a database
COMMIT -to apply the transaction. ROLLBACK -to undo all changes of a transaction
where group by -it is used to apply condition on queries
- we can use the GROUP BY clause to divide the rows in a table into groups, to return summary information for each group. -it is used in combination with the GROUP BY clause. It can be used in a SELECT statement to filter the records that a GROUP BY returns. -It allows to specify the order in which rows appear in the Result.
Functions in SQL
The syntax for built-in SQL functions is, SELECT function(column) FROM table
Important types of functions… String Functions Conversion Functions Mathematical Functions Date Functions
The string functions allows to manipulate strings Some String functions are…
length concat substr upper trim - Length of the specified string. - Concatenate two strings together. -Used to extract a substring from a string - Converts all letters uppercase - Removes all specified characters either from the beginning or the ending of a string
Conversion functions are used to convert the datatype. Some Conversion functions are…
Cast -converts one datatype to another. to_char -converts a number or date to a string to_date -converts a string to a date. to_number-converts a string to a number. to_lob -converts LONG or LONG RAW values to LOB values. Convert -converts a string from one character set to another
Aggregate functions operate against a collection of values, but return a single value. Some Aggregation functions are…
avg(column) count(column) max(column) first(column) sum(column) -Returns the average value of a column -Returns the number of rows - Returns the highest value of a column -Returns the value of the first record in a specified field - Returns the total sum of a column
Date functions used to manipulate date & time values. Some Date functions are…
current_date last_day next_day to_date Round -returns the current date -returnsthe last day of the month based on a date value -returns the first weekday -converts a string to a date - returns a date rounded to a specific unit of measure
Some other Commands / Functions
-it is a pseudo column that uniquely identifies a row within a table, but not within a database. the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table.
rownum -For each row returned by a query,
coalesce function -the coalesce function
returns the first non-null expression in the list. If all expressions evaluate to null, then the coalesce function will return null.
sample -sample in queries used for getting
Set Operations in Database
Union : the UNION operator combines the results of two SQL
queries into a single table of all matching rows. The two queries must have the same number of columns and compatible data types in order to join them. Any duplicate records are automatically removed unless UNION ALL is used.
Intersect: SQL INTERSECT operator takes the results of two
queries and returns only rows that appear in both result sets.
Except : The SQL EXCEPT operator takes the distinct rows of
one query and returns the rows that do not appear in a second result set.
A JOIN clause in SQL combines records from two tables in a relational database and results in a new (temporary) table, also called a "joined table". Structured Query Language specifies two types of joins: Inner join and Outer join
Inner Joins INNER JOIN returns all rows from both tables where there is a match.
Inner join is subdivided into three types Equi-join Natural join Cross join
Equi-join : The type of Join which links the columns of two tables using an equal relationship. Natural join: An inner join in which redundant columns are eliminated. Cross join : A cross join (or Cartesian Product join) will return a result table where each row from the first table is combined with each row from the second table. The number of rows in the result table is the product of the number of rows in each table
A Join operation in which all source records are included in the result, even those that don't satisfy the join condition
The Outer joins subdivided in to Left outer join Right outer join Full outer join
Left outer join : The resultant table will contain all the
records from the first table plus the records from second table which satisfying the join condition.
Right outer join : The resultant table will contain all the
records from the second table plus the records from first table which satisfying the join condition
Full outer join
: A full outer join combines the results
of both left and right outer joins. The joined table will contain all records from both tables
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.