rightclickdisable

Topics Categories

SQL Introduction

SQL Basics

DataBase:

Its the collection of tables. It is the place of storage of data or useful information. A database can also be defined as collection of one or more tables.

Table:
A table has ROWS and COLUMNS. A table is called as Entity or Relation.
    - Column of a table is called as Field or Attribute.
    - Row of a table is called as Record or Tuple.

SQL is an abbreviation of Structured Query Language. Its a db, ANSI and 5th generation language used to Retrieve, Manipulate and handle the data in database. SQL is a Language but SQL Server is an DB Software.

-  SQL is a language to access the database.
- SQL is non-case sensitive.
- SQL is a non-procedural language. 

RDBMS Concepts:
Before RDBMS, DBMS was a very popular db language. RDBMS stands for Relational Database Management System. RDBMS is the well organized collection of tables from which data can be accessed easily. RDBMS is the basis for SQL, and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access. 

RDBMS has got better features in terms of Data Storage, Security , Performance when compared to DBMS. 



In DBMS, Relationship between the tables is not maintained and it’s used to manage DB.
In RDBMS, Relationship between the tables is maintained and it also used to manage as well.
DBMS is used for simple application
RDBMS is used for Complex Applications.
In a single DB file can able to create single table
Multiple tables are created and related within a single DB File.
Less in Data Storage
Large data storage
Less Secured and Low Performer
Highly Secured and High Performer.

    Its Dr E.F. Codd during 1971 who termed RDBMS in his paper to IBM. Any DBMS to qualify RDBMS it has to support 12 Codd Rules. Below is the Codd Rules



Rule 0: The Foundation rule:
A relational database management system must manage its stored data using only its relational capabilities. The system must qualify as relational, as a database, and as a management system. For a system to qualify as a relational database management system (RDBMS), that system must use its relational facilities (exclusively) to manage the database.

Rule 1: The information rule:
All information in a relational database (including table and column names) is represented in only one way, namely as a value in a table.

Rule 2: The guaranteed access rule:
All data must be accessible. This rule is essentially a restatement of the fundamental requirement for primary keys. It says that every individual scalar value in the database must be logically addressable by specifying the name of the containing table, the name of the containing column and the primary key value of the containing row.

Rule 3: Systematic treatment of null values:
The DBMS must allow each field to remain null (or empty). Specifically, it must support a representation of "missing information and inapplicable information" that is systematic, distinct from all regular values (for example, "distinct from zero or any other number", in the case of numeric values), and independent of data type. It is also implied that such representations must be manipulated by the DBMS in a systematic way.

Rule 4: Active online catalog based on the relational model:
The system must support an online, inline,offline, relational catalog that is accessible to authorized users by means of their regular query language. That is, users must be able to access the database's structure (catalog) using the same query language that they use to access the database's data.

Rule 5: The comprehensive data sub-language rule:
The system must support at least one relational language that
Has a linear syntax..
Can be used both interactively and within application programs,
Supports data definition operations (including view definitions), data manipulation operations (update as well as retrieval), security and integrity constraints, and transaction management operations (begin, commit, and rollback).

Rule 6: The view updating rule:
All views that are theoretically updatable must be updatable by the system.

Rule 7: High-level insert, update, and delete:
The system must support set-at-a-time insert, update, and delete operators. This means that data can be retrieved from a relational database in sets constructed of data from multiple rows and/or multiple tables. This rule states that insert, update, and delete operations should be supported for any retrievable set rather than just for a single row in a single table.

Rule 8: Physical data independence:
Changes to the physical level (how the data is stored, whether in arrays or linked lists etc.) must not require a change to an application based on the structure.

Rule 9: Logical data independence:
Changes to the logical level (tables, columns, rows, and so on) must not require a change to an application based on the structure. Logical data independence is more difficult to achieve than physical data independence.

Rule 10: Integrity independence:
Integrity constraints must be specified separately from application programs and stored in the catalog. It must be possible to change such constraints as and when appropriate without unnecessarily affecting existing applications.

Rule 11: Distribution independence:
The distribution of portions of the database to various locations should be invisible to users of the database. Existing applications should continue to operate successfully:
when a distributed version of the DBMS is first introduced; and
when existing distributed data are redistributed around the system.

Rule 12: The non-subversion rule:
If the system provides a low-level (record-at-a-time) interface, then that interface cannot be used to subvert the system, for example, bypassing a relational security or integrity constraint.


FoxPro
Oracle, DB2, SQL Server
Foxbase
MySQL, SYBASE, Informix
Dbase
Terradata, Ingres, GreenPlum DB

Database Trend Evolution


Evolution Of Oracle Database


Relationship:

What is a Relationship ?
The association between any two tables to preserve the data correctness (improve consistency).

- Minimum Two Tables needed to create the Relationship. One table becomes the master Table and Other become detail Table.
- Master Table called as Parent table as data is constant (infrequently   changing data)  and it
   contains master data. 
- Detail Table is called as Child Table as it data in it is highly volatile   (Frequently Changing Data).
- To Create a relationship their should be one common column should be   existed.

Candidate Key
The columns that are eligible to become Primary Key is called as Candidate Key. 

Alternate Key
The columns that are chosen as PK will remain as PK. 
The columns that are eligible to become PK but not be chosen as PK is called Alternate Key.

CK = AK + PK
AK = CK -  PK


Types Of Relationship
There are 4 types of relationships..

- One-To-One
- One-To-Many
- Many-To-One
- Many-To-Many

One-To-One (1:1)
In one-to-one relationship, One record of table1 relates or matches to another record of table2. Each record in table1 Linked to another record in table2. The number of records in table1 must be equal to number of records in table2.

EMP_ID
EMP_NAME
DEPT_ID
DEPT_ID
DEPT_NAME
100
AAA
10
10
A1
101
BBB
20
20
A2
102
CCC
30
30
A3

Ex:
 - One employee belongs to One Department
 - A book is published by one company.
 - One Person has One Passport
 - A dress has one designer
 - Iphone manufactured by Apple Inc

One-To-Many (1:N)
In one-to-many relationship each row in the one table can be related many rows in the relating table. This relationship allows frequently used information to be saved only once in a table and referenced many times in all other tables.

AUTHOR_ID
AUTHOR_NAME
BOOK_ID
TITLE
AUTHOR_ID
1001
KUVEMPU
B001
BIRUGAALI
1001
1002
BENDRE
B002
MAHARATRI
1001
B003
UTTARAYANA
1002
B004
MUGHILAMALLIGHE
1002
Ex:
- Customers can make many orders
- Orders can have many Items
- Items can have descriptions in Many Languages.

Many-to-One (N:1)
In Many-to-Many relationship many records of a table1 related to a record in the relating table. This type of relationship tries to referenced with multiple times to a single instance on entity.

ORDER_ID
CUST_ID
CUST_ID
CUST_NAME
CUST_DESC
O_001
C_001
C_001
RAJU
AAA
O_002
C_002
C_002
VINAY
BBB
O_003
C_001
O_004
C_002
Ex:
- Many Orders placed by a Customer
- Many Books written by a Author.
- Many Students have a single teacher for a particular subject

Many-to-Many (N: N)
In Many-to-Many Relationship one or more records in the table can be related to one or more records in another table. Each record in table1 is related to 0,1 or many records in table2 and vice versa. To implement such relationship, a new table required to map the data.

CUST_ID
PROD_ID
CUST_ID
CUST_NAME
CUST_DESC
PROD_ID
PROD_NAME
C_001
PROD_01
C_001
RAJU
AAA
PROD_01
SAVINGS
C_002
PROD_02
C_002
VINAY
BBB
PROD_02
CREDIT
C_001
PROD_01

C_002
PROD_02
Ex:
- One customer can have one or more Products,One Product can be owned by one or more customers
- A teacher can have many students, a student have many teachers.

No comments:

Post a Comment