1_sql Server Notes
1_sql Server Notes
Database is a collection of inter-related data which is used to retrieve, insert and delete data efficiently.
Database is also used to organize data in form of tables, schemas, views, and reports, etc. E.g.: A
college database organizes data about the admin, staff, students and faculty etc. Using the database,
you can easily retrieve, insert, and delete the information. A database is an organized collection of data,
so that it can be easily accessed and managed. You can organize data into tables, rows, columns, and
index it to make it easier to find relevant information.
Database handlers create a database file in such a way that only one set of software program provides
access of data to all users. The main purpose of a database is to operate large amounts of information
by storing, retrieving, and managing data. There are many dynamic websites on the World Wide Web
nowadays which are handled through databases. E.g., a model that checks the availability of rooms in a
hotel. It’s an example of a dynamic website that use database. There are many databases e.g. MySQL,
Sybase, Oracle, MongoDB, Informix, PostgreSQL, SQL Server, etc. Modern databases are managed
by a database management system (DBMS). SQL or Structured Query Language is
used to operate on the data stored in a database. A cylindrical structure is used to display
the image of a database.
WHAT IS RDBMS
RDBMS stands for Relational Database Management Systems. All modern database management
systems like SQL, MS SQL Server, IBM DB2, ORACLE, My-SQL and Microsoft Access are based on
RDBMS. It is called Relational Data Base Management System (RDBMS) because it is based on
relational model introduced by E.F. Codd.
HOW DOES IT WORK
Data is represented in terms of tuples (rows) in RDBMS. Relational database is most commonly used
database. It contains more than one table and each table has its own primary key. Due to a collection
of organized set of tables, data can be accessed easily in RDBMS.
BRIEF HISTORY OF RDBMS
During 1970 to 1972, E.F. Codd published a paper to propose the use of relational database model.
RDBMS is originally based on that E.F. Codd's relational model invention.
WHAT IS TABLE
The RDBMS database uses tables to store data. A table is a collection of related data entries and
contains rows and columns to store data. A table is the simplest example of data storage in RDBMS.
Let's see the example of student table.
1 Ajeet 24 B.Tech
2 aryan 20 C.A
3 Mahesh 21 BCA
4 Ratan 22 MCA
5 Vimal 26 BSC
WHAT IS FIELD
A field is a smaller entity of a table which contains specific information about every record in the table.
In the above example, the field in the student table consist of id, name, age, course.
WHAT IS ROW OR RECORD
A row of a table is also called record. It contains the specific information of each individual entry in the
table. It is a horizontal entity in the table. For example: The above table contains 5 records.
Let's see one record/row in the table.
1 BULEGA 24 B.TECH
WHAT IS COLUMN
A column is a vertical entity in the table which contains all information related with a specific field in a
table. E.g. "name" is a column in the above table which contains all information about student's name.
Aryan
Mahesh
Ratan
Vimal
NULL VALUES
The NULL value of the table specifies that the field has been left blank during record creation. It is totally
different from the value filled with zero or a field that contains space.
DATA INTEGRITY
THE FOLLOWING ARE CATEGORIES OF DATA INTEGRITY IN EVERY RDBMS:
Entity integrity: It specifies that there should be no duplicate rows in a table.
Domain integrity: It enforces valid entries for a given column by restricting the type, the format,
or the range of values.
Referential integrity: It specifies that rows cannot be deleted, which are used by other records.
User-defined integrity: It enforces some specific business rules that are defined by users. These
rules are different from entity, domain or referential integrity.
DIFFERENCE BETWEEN DBMS AND RDBMS
Although DBMS and RDBMS both are used to store information in physical database but there are some
remarkable differences between them.
THE MAIN DIFFERENCES BETWEEN DBMS AND RDBMS ARE GIVEN BELOW:
No. DBMS RDBMS
After observing the differences between DBMS and RDBMS, you can say that RDBMS is an extension
of DBMS. There are many software products in the market today who are compatible for both DBMS
and RDBMS.
DBMS VS. FILE SYSTEM
FILE SYSTEM APPROACH
File based systems were an early attempt to computerize manual systems. It is also called a traditional
based approach in which a decentralized approach was taken where each department stored and
controlled its own data with the help of a data processing specialist. The main role of a data processing
specialist was to create the necessary computer file structures, and also manage the data within
structures and design some application programs that create reports based on file data.
Consider an example of a student's file system. A student file will contain information about the student
(i.e. roll no, student name, course etc.). Similarly, we have a subject file that contains information about
the subject and the result file which contains the information regarding the result. Some fields are
duplicated in more than one file, which leads to data redundancy. So, to overcome this problem, we need
to create a centralized system, i.e. DBMS approach.
DBMS:
A database approach is a well-organized collection of data that are related in a meaningful way which
can be accessed by different users but stored only once in a system. The various operations performed
by the DBMS system are: Insertion, deletion, selection, sorting etc.
Data Abstraction DBMS gives an abstract view of The file system provides the
data that hides the details. detail of the data
representation and storage of
data.
Security and DBMS provides a good protection It isn't easy to protect a file
Protection mechanism. under the file system.
Recovery Mechanism DBMS provides a crash recovery The file system doesn't have a
mechanism, i.e., DBMS protects crash mechanism, i.e., if the
the user from system failure. system crashes while entering
some data, then the content of
the file will be lost.
Manipulation DBMS contains a wide variety of The file system can't efficiently
Techniques sophisticated techniques to store store and retrieve the data.
and retrieve the data.
Concurrency DBMS takes care of Concurrent In the File system, concurrent
Problems access of data using some form of access has many problems
locking. like redirecting the file while
deleting some information or
updating some information.
Where to use Database approach used in large File system approach used in
systems which interrelate many large systems which interrelate
files. many files.
Data Redundancy Due to the centralization of the In this, the files and application
and Inconsistency database, the problems of data programs are created by
redundancy and inconsistency are different programmers so that
controlled. there exists a lot of duplication
of data which may lead to
inconsistency.
Structure The database structure is complex The file system approach has
to design. a simple structure.
Data Independence In this system, Data Independence In the File system approach,
exists, and it can be of two types. there exists no Data
Logical Data Independence Independence.
Physical Data Independence
Data Models In the database approach, 3 types In the file system approach,
of data models exist: there is no concept of data
Hierarchal data models models exists.
Network data models
Relational data models
Flexibility Changes are often a necessity to the The flexibility of the system is
content of the data stored in any less as compared to the DBMS
system, and these changes are more approach.
easily with a database approach.
DBMS ARCHITECTURE
The DBMS design depends upon its architecture. The basic client/server architecture is used to
deal with a large number of PCs, web servers, database servers and other components that are
connected with networks.
The client/server architecture consists of many PCs and a workstation which are connected via
the network.
DBMS architecture depends upon how users are connected to the database to get their request
done.
Database architecture can be seen as a single tier or multi-tier. But logically, database architecture is of
two types: 2-tier architecture and 3-tier architecture
1-TIER ARCHITECTURE
In this architecture, the database is directly available to the user. It means the user can directly
sit on the DBMS and uses it.
Any changes done here will directly be done on the database itself. It doesn't provide a handy
tool for end users.
The 1-Tier architecture is used for development of the local application, where programmers can
directly communicate with the database for the quick response.
2-TIER ARCHITECTURE
The 2-Tier architecture is same as basic client-server. In the two-tier architecture, applications
on the client end can directly communicate with the database at the server side. For this
interaction, API's like: ODBC, JDBC are used.
The user interfaces and application programs are run on the client-side.
The server side is responsible to provide the functionalities like: query processing and
transaction management.
To link with a DBMS, a client-side application creates a connection with the server side.
DATA MODELS
Data Model is the modeling of the data description, data semantics, and consistency constraints of the
data. It provides the conceptual tools for describing the design of a database at each level of data
abstraction. Therefore, there are following four data models used for understanding the structure of the
database:
DATABASE LANGUAGE
A DBMS has appropriate languages and interfaces to express database queries and updates. Database
languages can be used to read, store and update the data in the database.
TYPES OF DATABASE LANGUAGE
17 DATABASE PROGRAMMING with Microsoft SQL Server by Bulega Herbert Moses
1. DATA DEFINITION LANGUAGE
DDL stands for Data Definition Language. It is used to define database structure or pattern.
It is used to create schema, tables, indexes, constraints, etc. in the database.
Using the DDL statements, you can create the skeleton of the database.
Data definition language is used to store the information of metadata like the number of tables
and schemas, their names, indexes, columns in each table, constraints, etc.
Here are some tasks that come under DDL:
Create: It is used to create objects in the database.
Alter: It is used to alter the structure of the database.
Drop: It is used to delete objects from the database.
Truncate: It is used to remove all records from a table.
Rename: It is used to rename an object.
Comment: It is used to comment on the data dictionary.
These commands are used to update the database schema that's why they come under Data
definition language.
2. DATA MANIPULATION LANGUAGE (DML )
DML stands for Data Manipulation Language. It is used for accessing and manipulating data in a
database. It handles user requests. Here are some tasks that come under DML:
Select: It is used to retrieve data from a database.
Insert: It is used to insert data into a table.
Update: It is used to update existing data within a table.
Delete: It is used to delete all records from a table.
Merge: It performs UPSERT operation, i.e., insert or update operations.
Call: It is used to call a structured query language or a Java subprogram.
Explain Plan: It has the parameter of explaining data.
Lock Table: It controls concurrency.
3. DATA CONTROL LANGUAGE (DCL)
DCL stands for Data Control Language. It’s used to retrieve the saved data. The DCL execution is
transactional. It also has rollback parameters. (But in Oracle database, the execution of data control
language does not have the feature of rolling back.)
Here are some tasks that come under DCL:
o Grant: It is used to give user access privileges to a database.
o Revoke: It is used to take back permissions from the user.
There are the following operations which have the authorization of Revoke:
CONNECT, INSERT, USAGE, EXECUTE, DELETE, UPDATE and SELECT.