0% found this document useful (0 votes)
119 views

Unit - 1 Database Concepts - RDBMS Tools

RDBMS CLASS 12 FREE PDF CLASS NOTES

Uploaded by

k7samir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views

Unit - 1 Database Concepts - RDBMS Tools

RDBMS CLASS 12 FREE PDF CLASS NOTES

Uploaded by

k7samir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Unit – 1 Database Concepts – RDBMS Tools

Unit - 1
Database Concepts – RDBMS Tools
Database
Collection of tables is known as database. It is collection of interrelated data.

DBMS
It stands for Data Base Management System. It is an application software which
provides several commands to work on database such as to create, to modify, to
delete the database etc. Example : MS Excel, Foxpro etc.

RDBMS
It stands for Relational Data Base Management System. It has all the features of
DBMS as well as it provides features to work on multiple tables together. Example-
Oracle, MySQL, MS SQL Server etc.

Types of Users of DBMS


(i) END Users : This type of user uses database for querying, modifying the
reports as per the requirements. He is not responsible for designing the
database.
(ii) Database Administrator : This type of user administrates the database. He
is responsible for providing access, supports, monitoring etc.
(iii) Application Programmer : This type of user is responsible for writing
programs to interact with the database.
(iv) System Analyst : This type of user is responsible for determining the
requirements of the end users and then develop the specifications to meet the
requirements.

Advantages of DBMS
(i) It reduces data redundancy (duplication of data)
(ii) It reduces data inconsistency (mismatch of data)
(iii) It allows sharing of data.
(iv) It provides high security to data.
(v) It is user friendly.

Relational Data Model


It is a set of concepts to describe the structure of a database. It is the most popular
data model. In this data model, data is organized into tables (relation).
.
Terms of Relational Data Model
1. Relation  In RDBMS, table is known as relation. A relation has the following
properties :
 A column must have same kind of values.
 Each column must have an atomic value for a row.
 All rows of a relation must be distinct.
 Each column of a relation must have distinct name.
2. Domain  A pool of values or the values in each column are known as
domain.

XII – I.T. Kumar Gourab Page 1


email : [email protected]
Unit – 1 Database Concepts – RDBMS Tools
3. Tuple  A row of a relation (table) is known as tuple.
4. Attribute  The columns or fields of a relation are known as attribute.
5. Degree  The number of columns or attributes in a relation or table is known
as degree.
Example : A table having 4 columns is said to be a relation of 4 degrees.
6. Cardinality  The number of rows or tuples in a relation is known as
cardinality.
Example : A table having 5 rows is said to be a relation of 4 cardinality.
7. View  It is a virtual table that does not really exists.
8. Primary Key  The key which uniquely identifies the tuples in a relation is
known as primary key. A table can have only one primary key. If we apply
primary key on more than one columns in a table then it is known as
Composite Primary Key. The column having primary key can not have
duplicate values as well as null values.
9. Candidate Key  The attributes or fields which are eligible for primary key
are known as candidate key.
For example : mobileno, emailid, regno, aadharno, etc in a relation.
10. Alternate Key  A candidate key which is not primary key in a table is known
as alternate key.
11. Foreign Key  A non-key attribute whose values are derived from primary
key of other table is known as foreign key.

SQL Constraint
A condition or rules which are applied on field of a table is known as constraint. It
validates entry during entering values in the table. It can be applied during or after
creation of a table. These are the following constraints :
NOT NULL : If we do not want to allow null values in the field then we use NOT
NULL constraint.
SQL>> CREATE TABLE Student(sname VARCHAR(20) NOT NULL, roll INT);
We can not leave blank sname field in Student table.

DEFAULT : This constraint is used to provide default value to a column if we do not


provide value during entering records.
SQL>> CREATE TABLE Student(sname VARCHAR(20), roll INT, sec CHAR(1)
DEFAULT “A”);
It will place A in sec field of Student table if we do not specify value during entering
record.

UNIQUE : It ensures unique entry in the column, but it can be left blank.
SQL>> CREATE TABLE Student(sname VARCHAR(20), roll INT UNIQUE, sec
CHAR(1));
Here sname field of Student table will accept only unique entry but we can leave it
blank.

CHECK : It ensures that all values in a column satisfy given condition.


SQL>> CREATE TABLE Student(sname VARCHAR(20), roll INT CHECK(roll>0),
sec CHAR(1));
Here roll field of Student table will accept only positive entry i.e. greater than 0.

PRIMARY KEY : It is used to uniquely identify each row in a table.

XII – I.T. Kumar Gourab Page 2


email : [email protected]
Unit – 1 Database Concepts – RDBMS Tools
SQL>> CREATE TABLE Student(admno INT PRIMARY KEY, sname
VARCHAR(20), roll INT, sec CHAR(1));
Here sname field of Student table will accept only unique value and we can not leave
it blank also.

FOREIGN KEY : It is used to create relationship between two tables.


SQL >> CREATE TABLE Student(admno INT PRIMARY KEY, sname
VARCHAR(20), roll INT, sec CHAR(1));
CREATE TABLE Contact(id INT PRIMARY KEY, sid INT, mobile VARCHAR(10),
FOREIGN KEY(admno) REFERENCES Student(admno));
Here sid field of Contact table is foreign key which references admno of Student
table.

Referential Integrity
The rules which allow us to ensure relationships between records of related tables
are valid are known as referential integrity. It restricts the accidental deletion or
modification in related data

MySQL
It is the most popular Open Source RDBMS. It was developed, distributed, and
supported by Oracle Corporation. It is easy to use. It is free to download and use. It
supports SQL to work on database. It was developed in Sweden by David Axmark,
Allan Larsson and Michael Widenius in 1908. It was named on the name of Michael
Widenius’s daughter “My”.

SQL
SQL stands for Structured Query Language. It allows us to perform the following :
(i) Creating or modifying database structure
(ii) Changing security settings for system
(iii) Permitting users for working on database or tables
(iv) Query
(v) Inserting, modifying and deleting records etc

Data Types
The concept to specify type of values for entering in a table is known as data types.
MySQL provides the following data types :
Data Type Range Data Type Range

CHAR 0 – 255 MEDIUMINT -8388608 to 8388607

VARCHAR 0 – 255 INT -2147483648 to


2147483647

TINYTEXT 0 – 255 BIGINT

TEXT 0 – 65535 FLOAT Decimal (Precise to 23


digits)

BLOB 0 – 65535 DOUBLE

MEDIUMTEXT 0 – 16777215 DECIMAL

XII – I.T. Kumar Gourab Page 3


email : [email protected]
Unit – 1 Database Concepts – RDBMS Tools

MEDIUMBLOB 0 – 16777215 DATE YYYY-MM-DD

LONGTEXT 0 - 4294967295 DATETIME YYYY-MM-DDHH:MM:SS

LONGBLOB 0 - 4294967295 TIMESTAMP YYYYMMDDHHMMSS

TINYINT -128 to 127 TIME HH:MM:SS

SMALLINT -32768 to BOOLEAN 0 or 1


32767

Difference Between Char and Varchar


The main difference between CHAR and VARCHAR is that CHAR occupies space of
fixed length for each entry but VARCHAR occupies space for exact length for each
entry.

Types of SQL Commands


These are the following types of SQL commands :
 DDL : It stands for Data Definition Language. This category helps us to define
a new structure or to modify existing structure of database, tables etc.
Example : Create database, create table, alter table, drop etc.
 DML : It stands for Data Manipulation Language. This category helps us to
modify values of table.
Example : Insert into, update, delete, select etc.
 TCL : It stands for Transaction Control Language. This category helps us to
control transactions of database.
Example : Commit, rollback, savepoint etc.

SQL Commands
 SHOW DATABASES;
It is used to display list of existing databases of current user.
SQL>> SHOW DATABASES;

 CREATE DATABASE <databasename>


It is used to create a new database.
SQL>> CREATE DATABASE demo;

 USE <databasename>
It is used to open an existing database.
SQL>> USE demo;

 SHOW TABLES;
This command is used to display all tables of current database.
SQL>> SHOW TABLES;

 CREATE TABLE <tablename> (columnname1 datatype constraint


defaultvalue, columnname2 datatype constraint . . .);
It is used to create a new table in current database.
SQL>> CREATE TABLE Student(sid int primary key, sname VARCHAR(20),
section CHAR(1), dob DATE);

XII – I.T. Kumar Gourab Page 4


email : [email protected]
Unit – 1 Database Concepts – RDBMS Tools

 DESC <tablename>; or DESCRIBE <tablename>;


It is used to display structure of given tablename.
SQL>> DESC Student;

 INSERT INTO <tablename>(<fieldname1, fieldname2, ….) VALUES(value1,


value2,…);
This command is used to insert values in the given table.
SQL>> INSERT INTO Student(sid, name) VALUES(101, “Kumar”);
Above command is used to enter values in selected fields. Here we can
change order of fields.
SQL>> INSERT INTO Student VALUES(102, “Raj”, “A”);
Above command is used to enter values in all fields. Here we can not change
order of fields also.

 SELECT * FROM <tablename>;


This command is used to display all records from given tablename with all
columns.
SQL>> SELECT * FROM Student;

 SELECT * FROM <tablename> WHERE <fieldname> = value;


This command is used to display selected records from given tablename with
all columns.
SQL>> SELECT * FROM Student WHERE sid = 101;
 SELECT <fieldname1, fieldname2, …..> FROM <tablename> ;
This command is used to display all records from given tablename with
selected columns.
SQL>> SELECT sid, sname FROM Student;

 SELECT <fieldname1, fieldname2, …..> FROM <tablename> WHERE


<fieldname> = value;
This command is used to display selected records from given tablename with
selected columns.
SQL>> SELECT sid, sname FROM Student WHERE sid = 101;

 SELECT DISTINCT <fieldname> FROM <tablename>;


This command is used to display unique values of given column from given
tablename.
SQL >> SELECT DISTINCT sname FROM Student ;

 SELECT ALL <fieldname> FROM <tablename>;


This command is used to display all values of given column from given
tablename.
SQL >> SELECT ALL sname FROM Student ;

 SELECT <fieldname> AS <columnalias>. FROM <tablename>;


This command is used to display all values of given column by changing
column name from given tablename.
SQL >> SELECT sname AS “Student’s Name” FROM Student ;

XII – I.T. Kumar Gourab Page 5


email : [email protected]
Unit – 1 Database Concepts – RDBMS Tools
 SELECT <fieldname1, fieldname2, …..> FROM <tablename> WHERE
<fieldname> BETWEEN value1 and value2;
This command is used to display selected records according to given range
from given tablename with selected columns.
SQL>> SELECT sid, sname FROM Student WHERE sid BETWEEN 101 AND
105;

 SELECT * FROM <tablename> WHERE <fieldname> IN(value1, value2,


value3……..);
This command is used to display selected records after matching value in
given list from table with all columns.
SQL>> SELECT * FROM Student WHERE class IN (“XII”, “XI”, “X”, “IX”);

 SELECT <fieldname> FROM <tablename> WHERE <fieldname> LIKE “%”;


This command is used to display selected records from given tablename with
selected columns.
SQL>> SELECT sname FROM Student WHERE sname LIKE “R%”;
It will display all names starting with R. eg Ravi, Raman, Raj etc

SQL>> SELECT sname FROM Student WHERE sname LIKE “R_ _”;
It will display all names of 3 characters starting with R . eg Ram, Raj etc.

 UPDATE <tablename> SET <fieldname> = value;


This command us used to place given value in the column of all rows of a
table.
SQL>> UPDATE Student SET sname = “Ravi”;
This command is used to place Ravi in sname field of Student table.

 UPDATE <tablename> SET <fieldname> = value WHERE <fieldname> =


value;
This command is used to place given value in the column of selected rows of
a table.
SQL>> UPDATE Student SET sname = “Ravi” WHERE roll = 101;
This command is used to place Ravi in sname field of Student table whose roll
is equal to 101.

 DELETE FROM <tablename>;


It is used to delete all records from given table;
SQL>> DELETE FROM Student;
It will delete all records from Student table.

 DELETE FROM <tablename> WHERE <fieldname> = value;


It is used to delete selected records from given table;
SQL>> DELETE FROM Student WHERE roll > 101;
It will delete only those records from Student table whose roll is greater than
101

 ALTER TABLE <tablename> ADD COLUMN(<fieldname> datatype);


It is used to add new column at the end of existing tablename.
SQL>> ALTER TABLE Student ADD COLUMN(marks INT);

XII – I.T. Kumar Gourab Page 6


email : [email protected]
Unit – 1 Database Concepts – RDBMS Tools
It is used to add marks column in Student table.

 ALTER TABLE <tablename> ADD COLUMN (<fieldname> datatype) AFTER


<columnname>;
It is used to add new column after given column name in the existing
tablename.
SQL>> ALTER TABLE Student ADD COLUMN (marks INT) AFTER dob;
It is used to add marks column after dob in Student table.

 ALTER TABLE <tablename> ADD COLUMN(<fieldname> datatype) first;


It is used to add new column at the beginning of each columns in the existing
tablename.
SQL>> ALTER TABLE Student ADD COLUMN(marks INT) first;
It is used to add marks column as first column in Student table.

 ALTER TABLE <tablename> MODIFY (<oldfieldname> <newdatatype>);


It is used to modify datatype and size of existing column in existing
tablename.
SQL>> ALTER TABLE Student MODIFY (sname VARCHAR(30));
It is used to modify sname column size in Student table.

 ALTER TABLE <tablename> CHANGE (<oldfieldname> <newfieldname>);


It is used to change name of existing column in the given tablename.
SQL>> ALTER TABLE Student CHANGE (marks phy_marks);
It is used to rename marks column to phy_marks in Student table.

 ALTER TABLE <tablename> DROP COLUMN(<fieldname> datatype);


It is used to delete the given column in the existing tablename.
SQL>> ALTER TABLE Student DROP COLUMN marks;
It is used to delete marks column in Student table.

 DROP TABLE <tablename>;


It is used to delete entire table with structure and release memory space.
SQL>> DROP TABLE Student;

To insert data from one table to another table


SQL>> INSERT INTO Student1 SELECT * FROM Student WHERE admno>100;
This command is used to store records of Student table whose admno is greater
than 100 into Student1 table.

Questions/Answers
1. Differentiate between DBMS and RDMS.
Ans 
(i) DBMS stands for Data Base Management System but RDBMS stands
for Relational Data Base Management System.
(ii) DBMS stores data in the form of files but RDBMS stores data in the
form of table.
(iii) DBMS is capable to handle small amount of data but RDBMS can
handle huge amount of data.

XII – I.T. Kumar Gourab Page 7


email : [email protected]
Unit – 1 Database Concepts – RDBMS Tools
(iv) DBMS allows a single user to work at a time but RDBMS allows
multiple users to work simultaneously.
2. Differentiate between DDL and DML.
Ans  DDL stands for Data Definition Language and DML stands for Data
Manipulation Language. DDL provides commands for defining structure of
database or table but DML is used for modifying data of table.
3. Differentiate between Update and Alter command.
Ans  Update command is an example of DML but Alter command is an
example of DDL. Update command modifies value of table but Alter command
modifies structure of table.
4. Mr. Kumar has created a table Student with 3 rows and 4 columns. He added
1 more row to it and deleted one column. What is the Cardinality and Degree
of the table Student?
Ans  Total rows of table = 3 rows + 1 row = 4 rows
Total columns of table = 4 columns – 1 column = 3 columns
Hence Cardinality = 4 and Degree = 3
5. Differentiate between Primary Key and Foreign Key.
Ans  Primary key is used to uniquely identifies rows of a table but Foreign
Key is used to create relationship between two tables. We can have only one
primary key in a table but we can have two or more foreign keys in a table.
6. Differentiate between Drop and Delete command.
Ans  Drop is an example of DDL but delete is an example of DML. Drop
command is used to delete entire table with its structure but delete command
is used to delete records of a table.

XII – I.T. Kumar Gourab Page 8


email : [email protected]

You might also like