DATABASES
DATABASES
DATABASES
Other kinds of data stores can also be used, such as files on the file
system or large hash tables in memory but data fetching and writing
would not be so fast and easy with those type of systems.
RDBMS
• Nowadays, we use relational database management systems (RDBMS)
to store and manage huge volume of data.
• This is called relational database because all the data is stored into
different tables and relations are established using primary keys or
other keys known as Foreign Keys.
A Relational DataBase Management System (RDBMS)
is a software that −
• Enables you to implement a database with tables,
columns and indexes.
• Guarantees the Referential Integrity between rows of
various tables.
• Updates the indexes automatically.
• Interprets an SQL query and combines information
from various tables.
Terminology
Database- is a collection of tables with related data
Table − A table is a matrix with data. A table in a database looks like a simple
spreadsheet.
Column − One column (data element) contains data of one and the same
kind, for example the column postcode.
A row (= tuple, entry or record) is a group of related data, for example the
data of one subscription.
Primary Key − A primary key is unique. A key value can not occur twice in one table.
With a key, you can only find one row.
Foreign Key − A foreign key is the linking pin between two tables.
Referential Integrity- making sure that a foreign key value points to an
existing row.
DBMS languages
• Database languages are used to read, update and store data in a
database.
• There are several such languages that can be used for this purpose;
one of them is SQL (Structured Query Language).
• DDL – Data Definition Language:
(CREATE,DROP,ALTER,TRUNCATE,COMMENT,
RENAME)
• DML – Data Manipulation Language: (INSERT,
UPDATE,DELETE)
• DCL – Data Control Language: (GRANT,REVOKE)
• TCL-Transaction Control Language: (COMMIT,ROLLBACK)
DDL(Data Definition Language)
• Actually consists of the SQL commands that can be used to define the
database schema.
• It simply deals with descriptions of the database schema and is used
to create and modify the structure of database objects in the
database.
i) CREATE
• it is used to create the database or its objects (like table, index, function,
views, store procedure and triggers).
There are two CREATE statements available in SQL:
• CREATE DATABASE
Syntax: CREATE DATABASE database_name;
Eg.
CREATE DATABASE Employee;
In order to get the list of all the databases, you can use
SHOW DATABASES statement.
CREATE TABLE
The CREATE TABLE statement is used to create a table
in SQL.
Syntax:
• CREATE TABLE table_name ( column1
data_type(size), column2 data_type(size), column3
data_type(size), .... );
eg
CREATE TABLE Students ( ROLL_NO int(3), NAME
varchar(20), SUBJECT varchar(20), );
ii) DROP:
DROP is used to delete a whole database or just a table.
Syntax: DROP object object_name;
Examples: DROP TABLE table_name;
DROP DATABASE database_name;
iii) TRUNCATE
• It is used to remove all records from a table, inluding all spaces
Syntax: TRUNCATE TABLE table_name;
Eg
TRUNCATE TABLE Student_details;
iv) ALTER (ADD, DROP, MODIFY) ALTER TABLE
• is used to add, delete/drop or modify columns in the existing table.
• It is also used to add and drop various constraints on the existing
table.
ALTER TABLE – ADD: