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

Class XII Database

A database is a collection of organized data that allows users to easily retrieve, update, insert, and delete data whenever required. Databases store data in tables which have columns, rows, fields, and records. Databases are used to store large amounts of data, secure data, maintain data accuracy and integrity, and easily retrieve data.

Uploaded by

grey
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Class XII Database

A database is a collection of organized data that allows users to easily retrieve, update, insert, and delete data whenever required. Databases store data in tables which have columns, rows, fields, and records. Databases are used to store large amounts of data, secure data, maintain data accuracy and integrity, and easily retrieve data.

Uploaded by

grey
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1/5

DATABASE: - Collection of data in well organized manner, So that we can


easily retrieve, update, insert, delete, search whenever required.

Database store data in the form of tables.

Why database?

 To store use amount of data


 To secure our data
 To maintain accuracy of data
 Easy retrieval of data
 To maintain integrity of data

Note:Table,report,form ,query are database objects

Database: Employee Management

Table: Employee table


FOREIGN KEY
pk
EMPID EMPNAME DESIGNATION DOJ DEPT Aadh Pan
ar
101 HARSH MANAGER 12.03.1999 10 998 Am5
0…. 700
h
102 AYUSHI EMPLOYEE 13.04.2010 20 123 Qert
4… 700
103 AAROHI Clerk 14.05.2000 20 456 Qwt
7… y670
0
104 ARPIT Admin 15.08.2004 30 345 Asdf
6… g780
0
COLUMNS/ATTRIBUTES/FIELD: 5
RECORDS/TUPLE/ROWS: 4
FIELD NAME: EMPID,EMPNAME……..
3/5
DEGREE: NO. OF ATTRIBUTES IN A RELATION(TABLE).
CARDINALITY: NO. OF TUPLES IN A RELATION(TABLE).

DBMS: It stands for Database Management System.It is a


software which enables creation,insertion,updation and
deletion of the data in a table.
Ex; mysql,oracle,DB2 etc.
RDBMS: It stands for Relational database management
system. It is used to create link between tables to fetch the
data from more than one tables.
Database Model
1. Network model
2. Relational model(table)
3. Hierarchical model(tree)
4. Object oriented model(class and object)
4/5
KEYS:
1. Primary key
2. Unique key
3. Candidate key
4. Foreign key
5. Alternate key
6. Composite key
Primary key: A column which uniquely determines
the record is called primary key.It takes unique value
and doesn’t allow null value.
e.g EmpId
candidate key: Set of keys which is having capability
to be a primary key.
e.g:(EmpId,Aadhar,PAN)
Alternate key: Out of candidate keys if one is chosen
as a primary key then other act as a alternate key.
e.g:(Aadhar,PAN)
Composite Key: When two or more than two
columns together can act as a primary key, that is
known as composite key.
Unique key: It takes unique value but can allow null
allow.
Foreign Key: A key which act as a primary key for
other table.
Table: Department
dept location
PK 10 Delhi
20 Mumbai
30 Delhi

SQL: STRUCTURED QUERY LANGUAGE


Database as a backend
Python as a frontend
H.W Read about SQL
5/5
SQL: This is the acronym of STRUCTURED QUERY
LANGUAGE.
This sql is used by various database management
software
i.e : mYsql
oracle
db2 etc.
Mysql:
Features of Mysql:
1. Open source software
2. Security
3. It act as a backend for various programming
language.
Like: PYTHON, .NET(C sharp),java etc.
4. Portable: It can run on various platform.
5. This is the first choice for internet based
database.
Apcahe,php

Sql:
Sql commands is divided into 4 parts:
1. DDL:(Data Definition Language)
Create, alter, drop, rename, truncate.
** It works on table structure not the table
data.
2. DML:(Data Manipulation Language)
Select,insert, update,delete
** It works on table data rather than table
structure.
3. TCL: (Transaction control language)
Commit, rollback, savepoint
4. DCL:(Data Control Language):
Grant, revoke

Data type used in SQL


1. Numeric
1.int
2. decimal
2. Character
1. Char: fixed length character
0 to 255
2. Varchar: variable length character
0 to 255.
3. Date: dddd-mm-yy
Dddd: 1000 to 9999
4. time

6/5

Mysql> Show databases;


** It will list all the databases present in the Mysql
Mysql> Use databasename;
Mysql> Show tables;
** It will list all the tables present in that particular
database
Create :
Mysql>create database employee management;
Mysql> Use employeemanagement;
Mysql> create table emp
(empid int(8) primary key,
,empname varchar(15), doj date,deptno int(2),Aadhar
numeric(12)) ;
Note: to see the structure of the table we use describe or
desc command;
Mysql> desc emp;
Mysql> insert into emp values(101, “akshay”, “ 2000-02-
01”,10,997654321000);

Note: To check whether the records are inserted in the table


or not we use select command.
** select command is used to fetch the record of the table.
Mysql> select * from emp;
Mysql> select * from emp where empid=101;
** it will fetch only one record of empid 101;
To see the particular field from table emp
Mysql> Select empname, aadhar from emp;
To remove the table from the database we have to use drop
command.
Mysql> drop table emp;
8/5
Constraint: It is a restriction to a field which avoid unwanted
entries.
1. primary key: unique value ,does not null value.
2. unique : it also takes unique value but can allow null value
3. check : it will check the entries according to the condition
or not.
Check Salary>=10000
4. default: if we are not passing any value related to that
particular field it will take default value:
dept default 10
5. foreign key: this key act as a primary key for other table.
6. not null: it will not allow null value.

Ex : create table emp


(empid int(8) primary key,
empname varchar(15) not null,
doj date unique,
dept int(2) default 10,
Salary numeric(7) check salary>=10000,
Foreign Key(dept) References Department(deptid)
);
(other table) (PK)

10/5
UPDATE COMMAND:
Update emp set salary=salary+2000 ;
Update emp set salary=salary+2000 where empid=101;

Alter Command:
Alter with Add: to add column PH in the table
Alter table emp ADD (PH int(10));
Alter with modify : it will modify the given datatype,its
size,constraint etc.
Alter table emp Modify empname varchar(15);

Alter with drop: it can remove column ,constraint etc.


Alter table emp drop column PH;
Alter table emp drop primary key;

Delete command: it can delete single or all records of the


table.
Delete from emp; (it will delete all the records from table)
Delete from emp where empid=101;

Select command:
1)Select * from emp; (it will display whole records of the
table)
2)Select * from emp where empid=102;(it will display all
data of empid 102)
3) operator:
a) Between: give the records based on certain ranges.
b) like: pattern matching
c) in: It works on range of values
not in: just opposite of IN
c) not null

between:
Q. Fetch the records of those employee whose salary
ranges between 10000 and 50000;
Select * from emp where salary between 10000 and 50000;
Note: both ranges included

IN:
Q. Display the records of those employee who either
belongs to dept no 10 or 20
Ans: Select * from emp where dept IN(10,20);
Not IN is just opposite to IN operator
Or
Select * from emp where dept = 10 or dept=20;

LIKE: Pattern matching


%-> Any no of characters Wild card operator
_-> only one character
Q. DISPLAY the record of those employee whose name
starting with character ‘A’.
Ans: Select * from emp where empname LIKE “A%”;

Last character ‘A’:


Select * from emp where empname LIKE “%A”;
Second Character ‘A’
Select * from emp where empname LIKE “_A%”;

NOT NULL
Q: Display the details of those employee whose dept is not
null.
Ans: Select * from emp where dept is NOT NULL;
NULL
Select * from emp where dept is NULL;
12/5
AGGREGATE FUNCTION: ONLY WORK FOR THE GROUP OF
VALUES
1. MAX()
2. MIN()
3. SUM()
4. COUNT()
5. AVG()
13/5
OPERATOR:
ARITHMETIC OPERATOR: + , - ,*,/
RELATIONAL OPERATOR: >,<,>=,<=
LOGICAL OPERATOR: AND, OR, NOT
ORDER BY CLAUSE:- To Arrange the data either in
ascending or descending (by default: ascending(asc)
For descending we have to use desc command along with
order by).
Q: arrange the records in ascending order of dept.
Select * from emp order by dept asc;
Q: arrange the records in descending order of dept.
Select * from emp order by dept desc;

Distinct command: this command will display the record by


removing duplicacy.
As keyword: it will create the alias(second name) of field
name.
Select salary+5000 AS incrementedsalary from emp;
Q . Display the different dept number from table EMP.
Select dept from emp;
Ans: Select distinct dept from emp;
Group by clause: It will grouping the data and display the
result on that basis. Group by clause always works with
aggregate function.
Q. Display the total salary of each dept.
Ans: select dept,sum(salary) from emp group by dept;

Having Clause: it is used to give the condition with group


by
Q. Display the total salary of every dept less than 30.
Ans: select dept,sum(salary) from emp group by dept
having dept<30;

You might also like