Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DB Report

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

Report on Database

What is Database?
Database is a collection of records .Database stored the data in rows and
columns format this is also known as RDBMS(Relational Database
Management System).

RDBMS: RDBMS also known as Relational database management system


which can be represent rows and columns and also known as table

Types of Database :
1) Centralized Database: It is the type of database that stores data
at a centralized database system. It comforts the users to access the stored
data from different locations through several applications.
2) Distributed Database: These database systems are connected via
communication links. Such links help the end-users to access the data
easily. 
3) Relational Database: This database is based on the relational data
model, which stores data in the form of rows(tuple) and
columns(attributes), and together forms a table(relation).
4) NOSQL Database: Non-SQL/Not Only SQL is a type of database
that is used for storing a wide range of data sets
5) Cloud Database: A type of database where data is stored in a
virtual environment and executes over the cloud computing platform

Key concepts ( constraint ):


key is an attribute or a set of attributes that help to uniquely identify a tuple
(or row) in a relation (or table)
Types of Keys:
1) Primary key: Primary key is a candidate key that is used for unique
identification of entities the table. Primary key cannot be null

create table school(s_id int primary key,s_name varchar(255),Mobile_number


varchar(255),father_name varchar(255));

insert into school values(1,'Sonu','23145645','Vikash');

insert into school values(2,'Sonu','23145645','Vikash');

insert into school values(3,'Raju','45622451','Vishal');


2) Super key : If we add any attribute with roll number like name ,age
etc that is called super keys.

create table school2(s1_id int,s1_name varchar(255), s1_fathername


varchar(255),mobile_number varchar(255));

insert into school2 values(1,'vishal','kishan','997546522');

insert into school2 values(2,'monu','mohit','6945225365');

insert into school2 values(3,'GK','Badruddin','945012321');


3) Foreign key: It is attributes or set of attributes, that references to
primary key of same table or another table

Query:
1) create table student(id int primary key,name varchar(255),city
varchar(255));

insert into student values(1,'Raju','Allahabad');

insert into student values(2,'mohan','Phulpur');

insert into student values(3,'mukesh','Bhadohi');

insert into student values(4,'Rehan','Mumbai');

2) create table fees(id int primary key, amount varchar(255),date


varchar(255), s_id int );

insert into fees values(1,'10000','10/02/2022'1);

insert into fees values(2,'10023','12/02/2022');

insert into fees values(3,'12200','14/04/2022');

insert into fees values(4,'42412','02/03/2022');

3) select * from fees where s_id=1;

4) Candidate key: A key


in which the name is same but
their number is different is
called candidate's
5) Composite key : When one field of the table is not capable of forming
primary, then two or more field are joined together and from composite key.

6) Alternate key: The alternate key of any table are those


candidate keys which are not currently selected as the primary
key.

Database Command:
• DDL : Data definition language : which are used to create the structure
of the database as well as related activities are called DDL commands
like create table commands and alter commands

• DML: Data manipulation language : like insert into commands,


update ,delete commands and select commands .

• DQL: Data query language

• DCL: Data control language

• TCC: Transactional control commands

JOIN Command: There are four types:


INNER JOIN: we will create two different table and then take will a
common data from both table that is called inner join
Query:
select * from student inner join fees on

student.id=fees.s_id;

LEFT JOIN:
the left join table all return from the left table and the matched record from
the right table
Query: select*from student left join fees on student.id=fees.s_id

RIGHT JOIN:
The right join table all return from the right table and the matched record
from the left table

Query:
select*from student Right join fees on student.id=fees.s_id;
Cross join:
The SQL ORDER BY Keyword: The Order By keyword is
used to sort the result-set in ascending or descending order .

Query
create table student (id int primary key,name varchar(255),city
varchar(255));
insert into student values(1,'Raju','Allahabad');
insert into student values(2,'mohan','Phulpur');
insert into student values(3,'mukesh','Bhadohi');
insert into student values(4,'Rehan','Mumbai');

Ascending order:
1) Query
select name from student order by name asc;

2)  Descending order.
3) Query
select name from student order by name desc;
EXAMPLE
select * from student order by city;:
 ;
Operater: There are Three Types

 AND, OR and NOT Operators:


The AND and OR operators are used to filter records based on
more than one condition.

 AND Opreater:
 The AND operator displays a record if all the conditions
separated by AND are TRUE.
 Query
 select*from student1 where name='monu' and
address='USA';






 EXAMPLE:
 select*from student1 where age='22' and address='USA';


OR Operators:
The OR operator displays a record if any of the conditions
separated by OR is TRUE.

 Query:

 select*from student1 where name='monu' or
address='USA';














 NOT Operators: The NOT operator displays a record


if the condition(s) is NOT TRUE.
 Query:
 select*from student1 where Not Address='USA';


















 SQL UPDATE Statement:


The UPDATE statement is used to modify the existing records in
a table.

 Query:
update student set name='sunil' where id='1';

1. Query
update student1 set age='22', name='rohit'where id='5';
SQL DELETE Statement:
The DELETE statement is used to delete existing records in a
table.
1. Query:
delete from student1 where name='rohit';
SQL MIN() and MAX() Functions:
1)MIN()
The MIN() function returns the smallest value of the selected
column.
1. Query:
select min(age) from student1;
MAX:
The MAX() function returns the largest value of the selected
column.

1. Query:
select max(age) from student1;
SQL COUNT(), AVG() and SUM() Functions:
The COUNT() function returns the number of rows that matches
a specified criterion

(count function are used to count data each row and each
column of table)
AVG():
He AVG() function returns the average value of a numeric
column. 

Query:
select avg(marks)from student2 where id='1';

EXAMPLE:select avg(marks) ,avg(marks1)from student2


where id='1';
SUM():
The SUM() function returns the total sum of a numeric column

Query:
select sum(marks)from student2;
SQL ALTER TABLE Statement: I

The ALTER TABLE statement is used to add, delete, or modify


columns in an existing table.

The ALTER TABLE statement is also used to add and drop


various constraints on an existing table.

ALTER TABLE - ADD Column:


Query:
SELECT * FROM public.student2
ALTER TABLE - DROP COLUMN:
To delete a column in a table.

Query:
alter table student1 DROP COLUMN Email;

You might also like