SlideShare a Scribd company logo
DataBase
What is Data?
 data can be Unprocessed,UnOrganized,Meaningless,raw facts related to any
object in consideration.
 For example your name, age, height, weight, etc are some data related to
you.
 A picture , image , file , pdf etc can also be considered data.
What is Database?
Database is a systematic collection of data.
Databases support storage and manipulation of data.
Each database has one or more distinct APIs for creating, accessing,
managing, searching and replicating the data it holds.
Databases make data management easy. Let's discuss few examples.
An online telephone directory would definitely use database to store
data pertaining to people, phone numbers, other contact details, etc.
Your electricity service provider is obviously using a database to
manage billing , client related issues, to handle fault data, etc.
10/31/2017 1Information Science Dept. DB Lab Class Note
Cont…
What is a Database Management System (DBMS)?
• Database Management System (DBMS) is a collection of programs
which enables its users to access database, manipulate data, reporting
/ representation of data and control access to the database.
Types of DBMS
1. Hierarchical
 It employs the "parent-child" relationship of storing data.
 Its has tree like structure.
 It is rarely used nowadays.
2. Relational DBMS
 It defines database relationships in the form of tables.
 This is the most popular DBMS type in the market.
 Eg:MySQL, Oracle, and Microsoft SQL Server database.
3. Object Oriented Relation DBMS
 It supports storage of new data types.
 The data to be stored is in the form of objects.
 The objects to be stored in the database have attributes(i.e.
gender…) .
 Eg:c++,java,c#,c… etc.
10/31/2017 2Information Science Dept. DB Lab Class Note
Cont…
What is SQL?
SQL stands for Structured Query language .
• MySQL is a fast, easy-to-use RDBMS being used
for many small and big businesses on the market.
• MySQL is developed,marketed, and supported by
MySQL AB, which is a Swedish company.
• MySQL is becoming so popular .
How can we use MYSQL in Database
Program.
10/31/2017 3Information Science Dept. DB Lab Class Note
Cont…
MYSQL Exercise
• Use MYSQL Command Line Client provided
by MYSQLServer5.0/MY SQL Query
Browser.
• mysql > SHOW DATABASES;
Creating a database
• mysql > CREATE DATABASE database_name;
Eg: create database Section;
10/31/2017 4Information Science Dept. DB Lab Class Note
Cont…
Deleting a database
• mysql > DROP DATABASE database_name;
– Eg: Drop database Section;
To select a particular database
• mysql > USE database_name;
– Eg: use section;
10/31/2017 5Information Science Dept. DB Lab Class Note
Cont…
TO see tables in a database
• mysql >SHOW TABLES;
To create a new table in mysql
• mysql > CREATE TABLE table_name;
– Eg:CREATE TABLE student (id INT(3) NOT NULL PRIMARY
KEY , name VARCHAR(20), address VARCHAR(30), mobile
INT(10));
To see structure of Table in a mysql database
• mysql > DESCRIBE/DESC table_name;
– Eg: desc student;
10/31/2017 6Information Science Dept. DB Lab Class Note
Cont…
To insert data into a table
• mysql > INSERT INTO table_name;
– Eg:INSERT INTO student (id,Name,Address,Mobile) VALUES (01,
"John", "America","098765431”);
To insert more than one record at once, we can do this,
with each set of field values separated by a comma.
• Mysql>INSERT INTO table_name (column_1, column_2,
column_3, other_value) VALUES (value1, value2, value3, …),
(value1, value2, value3, …), (value1, value2, value3, …);
– Eg:INSERT INTO student VALUES(03,”Teklay
Brhane”,”Axum”,094856095),(04,”Brhane
kfle”,”Mekelle”,0914008514),(…);
To Make a copy of table
– INSERT INTO table_name SELECT * FROM table_name;
10/31/2017 7Information Science Dept. DB Lab Class Note
Cont…
To See contents inside a table
• mysql > SELECT * FROM table_name;
• Eg:Select * from student;
To Update a record in a table
• mysql > UPDATE table_name SET column1=value,
column2=value2,...
WHERE some_column=some_value;
• Eg: UPDATE student SET name = “John Mc”
WHERE id ='01';
10/31/2017 8Information Science Dept. DB Lab Class Note
Cont…
To Delete a record from a table
• mysql > DELETE from [table_name] where [column
name]=[field text];
• Eg: delete from student where id=“02”;
To delete all records at the same way from a table
• for slowly deletting data use:
– mysql>delete from table_name;
• for quickly daletting data use:
– Mysql>TRUNCATE TABLE table_name;
• for deletting the hole data from the table:
– Mysql>Delete from table-name;
10/31/2017 9Information Science Dept. DB Lab Class Note
Cont…
To Add a column in a table
• mysql > ALTER TABLE table_name ADD email
VARCHAR(40) AFTER mobile;
• Eg: ALTER TABLE student ADD email
VARCHAR(40) AFTER mobile;
10/31/2017 10Information Science Dept. DB Lab Class Note
Cont..
To modify a column in a table
• mysql> ALTER TABLE table_name MODIFY
Column_name Column Definition
• Eg:ALTER TABLE student MODIFY name
varchar(20);
To Change a column in a table
• mysql> ALTER TABLE table_name change Column_name
Column Definition
– Eg:ALTER TABLE student change name F_Nmae
varchar(20);
10/31/2017 11Information Science Dept. DB Lab Class Note
Cont…
To drop a column in a table
• mysql > ALTER TABLE table_name DROP
column_name
– Eg: ALTER TABLE student DROP
Fname;
10/31/2017 12Information Science Dept. DB Lab Class Note
SQL Constraints
• SQL constraints are used to specify rules
for the data in a table.
• If there is any violation between the
constraint and the data action, the action is
aborted by the constraint.
• Constraints can be specified when the table
is created (inside the CREATE TABLE
statement) or after the table is created
(inside the ALTER TABLE statement).
10/31/2017 13Information Science Dept. DB Lab Class Note
Cont…
• In SQL, we have the following constraints:
• NOT NULL - Indicates that a column cannot store NULL
value
• UNIQUE - Ensures that each row for a column must have a
unique value
• PRIMARY KEY - A combination of a NOT NULL and
UNIQUE. Ensures that a column (or combination of two or
more columns) have a unique identity which helps to find a
particular record in a table more easily and quickly
• FOREIGN KEY - Ensure the referential integrity of the
data in one table to match values in another table
• CHECK - Ensures that the value in a column meets a
specific condition
• DEFAULT - Specifies a default value for a column
10/31/2017 14Information Science Dept. DB Lab Class Note
SQL Not Null
• By default, a table column can hold
NULL values.
• The NOT NULL constraint enforces
a column to NOT accept NULL values.
• Eg: CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255));
10/31/2017 15Information Science Dept. DB Lab Class Note
SQL DEFAULT
• To create a Default constraint on creating a table
– Eg: CREATE TABLE Persons
(
P_Id int NOT NULL default”0”,
LastName varchar(255) NOT NULL default”YES”,
FirstName varchar(255),
Address varchar(255),
City varchar(255));
• To create a DEFAULT constraint on the "City" column when the
table is already created, use the following SQL:
• Mysql>alter table table_name alter column_name set default””;
– Eg: ALTER TABLE student ALTER id SET DEFAULT “0”;
• To drop a DEFAULT constraint, use the following SQL:
• Mysql> alter table table_name alter column_name drop default;
– Eg: ALTER TABLE student ALTER id DROP DEFAULT;
10/31/2017 16Information Science Dept. DB Lab Class Note
SQL Primary Key
• The PRIMARY KEY constraint uniquely
identifies each record in a database table.
• Primary keys must contain UNIQUE
values.
• A primary key column cannot contain NULL
values.
• Most tables should have a primary key, and
each table can have only ONE primary key.
10/31/2017 17Information Science Dept. DB Lab Class Note
Cont…
• SQL PRIMARY KEY Constraint on CREATE TABLE
– Eg: CREATE TABLE Person(P_Id int NOT NULL,FirstName
varchar(255) NOT NULL,LastName varchar(255),PRIMARY KEY
(P_Id));
• SQL PRIMARY KEY Constraint on ALTER TABLE
• Mysql>alter table table_name add primary key(column_name);
– Eg: Alter table person add primary
key(p_id);
• To DROP a PRIMARY KEY Constraint
• Mysql>Alter table table-name drope primary key;
– Eg: Alter table person drop primary key;
10/31/2017 18Information Science Dept. DB Lab Class Note
SQL UNIQUE
• The UNIQUE constraint uniquely identifies each record in a
database table.
• SQL UNIQUE Constraint on CREATE TABLE
– Eg: CREATE TABLE Person(P_Id int NOT NULL,FirstName
varchar(255) NOT NULL,LastName varchar(255),UNIQUE
(P_Id));
• SQL UNIQUE Constraint on a already created TABLE
• Mysql> alter table table-name add unique(column_name);
– Eg:Alter table person add unique(FirstName);
• SQL To DROP a UNIQUE Constraint form a database
table
• Mysql> alter table table-name drop index (column_name);
– Eg:ALTER TABLE Person DROP INDEX FirstName;
10/31/2017 19Information Science Dept. DB Lab Class Note
SQL Foreign Key
• A FOREIGN KEY in one table points to a PRIMARY KEY in another
table
• SQL FOREIGN KEY Constraint on CREATE TABLE
• CREATE TABLE Orders
(
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
PRIMARY KEY (O_Id),
FOREIGN KEY (P_Id) REFERENCES Persons(P_Id)
)
• SQL FOREIGN KEY Constraint on ALTER TABLE
• Mysql>alter table table_name add index fk_(column_name);
• Eg: alter table student add index fk_(section);
• To DROP a FOREIGN KEY Constraint
• Mysql>alter table table_name drop index(column_name);
• Eg: ALTER TABLE Orders
DROP FOREIGN KEY fk_PerOrders
10/31/2017 20Information Science Dept. DB Lab Class Note
Questions???
Field Type Null Key Default Extra
Stu_ID
firstname
lastname
Address
Email
mobile
int (4)
char(15)
char(15)
varchar(50)
varchar(30)
int(10)
NO
NO
YES
YES
YES
YES
PRIM
UNI
MUL
0
NO
YES
YES
YES
YES
Auto increment
1) Create a table called Mytable in database called Mydatabase (given below is definition of table)
2) Enter four rows of data into the tables
3) Delete column from above table
4) Drop primary key from above table
5) Modify column name firstname to fname and lastname to lname
6) Add new column grade after column mobile & make varchar datatype. Set your default
value “NO”. And then insert any value to Mobile column.
10/31/2017 21Information Science Dept. DB Lab Class Note
• Create table orders like below:
• Create table customers like below:
10/31/2017 Information Science Dept. DB Lab Class Note 22
SQL JOIN
• INNER JOIN: Returns all rows when
there is at least one match in BOTH tables
• LEFT JOIN: Return all rows from the left
table, and the matched rows from the
right table
• RIGHT JOIN: Return all rows from the
right table, and the matched rows from
the left table
• FULL JOIN: Return all rows when there is
a match in ONE of the tables
10/31/2017 Information Science Dept. DB Lab Class Note 23
SQL Inner Join
• The INNER JOIN keyword selects all
rows from both tables as long as there is a
match between the columns in both tables.
• PS! INNER JOIN is the same as JOIN.
10/31/2017 Information Science Dept. DB Lab Class Note 24
SQL Inner Join
• SQL INNER JOIN Syntax
• Mysql>SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
• Example
• SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
INNER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
10/31/2017 Information Science Dept. DB Lab Class Note 25
SQL Left Join
• The LEFT JOIN keyword returns all rows
from the left table (table1), with the
matching rows in the right table (table2).
The result is NULL in the right side when
there is no match.
• PS! In some databases LEFT JOIN is called LEFT OUTER
JOIN.
10/31/2017 Information Science Dept. DB Lab Class Note 26
SQL Left Join
• SQL LEFT JOIN Syntax
• Mysql>SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
• Example
• SELECT Orders.order_id, Customers.CustomerName,
Orderd.OrderDate
FROM customers
LEFT JOIN orders
ON Orders.customer_id=Customers.customer_id order by
Customers.CustomerName;
10/31/2017 Information Science Dept. DB Lab Class Note 27
SQL Right Join
10/31/2017 Information Science Dept. DB Lab Class Note 28
• The RIGHT JOIN keyword returns all rows
from the right table (table2), with the
matching rows in the left table (table1).
The result is NULL in the left side when
there is no match.
• PS! In some databases RIGHT JOIN is called RIGHT OUTER
JOIN.
SQL RIGHT JOIN
• SQL RIGHT JOIN Syntax
• Mysql>SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;
• Example
• SELECT Orders.order_id,
Customers.CustomerName, Orders.OrderDate
• FROM orders
• RIGHT JOIN customers
• ON Orders.customer_id=Customers.customer_id
order by Customers.CustomerName;
10/31/2017 Information Science Dept. DB Lab Class Note 29
SQL Full Join
• The FULL OUTER JOIN keyword
returns all rows from the left table
(table1) and from the right table
(table2).
• PS! FULL OUTER JOIN = LEFT + RIGHT joins.
10/31/2017 Information Science Dept. DB Lab Class Note 30
SQL FULL OUTER JOIN
• SQL FULL OUTER JOIN Syntax
• Mysql>SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
• Example
• SELECT Customers.CustomerName,
Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;
•
10/31/2017 Information Science Dept. DB Lab Class Note 31
SQL Union
• The UNION operator is used to
combine the result-set of two or more
SELECT statements.
• Notice that each SELECT statement
within the UNION must have the same
number of columns.
• The columns must also have similar
data types. Also, the columns in each
SELECT statement must be in the
same order.
10/31/2017 Information Science Dept. DB Lab Class Note 32
SQL Union
• SQL UNION Syntax
• Mysql>SELECT column_name(s) FROM table1
UNION ALL
SELECT column_name(s) FROM table2;
• All keyword allows dupicationof values but not union
keyword.
• Example
SELECT customer_id
FROM Customers
union
select customer_id from orders;
10/31/2017 Information Science Dept. DB Lab Class Note 33
Ad

More Related Content

What's hot (19)

Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
CPD INDIA
 
Ch9
Ch9Ch9
Ch9
Welly Dian Astika
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
webhostingguy
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
Pongsakorn U-chupala
 
Introduction to (sql)
Introduction to (sql)Introduction to (sql)
Introduction to (sql)
Dattatray Ghorpade
 
Avinash database
Avinash databaseAvinash database
Avinash database
avibmas
 
Sql server T-sql basics ppt-3
Sql server T-sql basics  ppt-3Sql server T-sql basics  ppt-3
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
Data concepts
Data conceptsData concepts
Data concepts
Sachidananda M H
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
Sankhya_Analytics
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
enosislearningcom
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
PT- Oracle session01
PT- Oracle session01 PT- Oracle session01
PT- Oracle session01
Karthik Venkatachalam
 
Introduction to mysql part 1
Introduction to mysql part 1Introduction to mysql part 1
Introduction to mysql part 1
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
Ehsan Hamzei
 

Similar to Data base.ppt (20)

xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
NilamHonmane
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
SuhaniSinha9
 
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATIONSQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
deeptanshudas100
 
SQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) commandSQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) command
sonali sonavane
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
Sankhya_Analytics
 
Mysql-overview.pptx
Mysql-overview.pptxMysql-overview.pptx
Mysql-overview.pptx
TamilHunt
 
Lecture - MY-SQL/ SQL Commands - DDL.pptx
Lecture - MY-SQL/ SQL Commands - DDL.pptxLecture - MY-SQL/ SQL Commands - DDL.pptx
Lecture - MY-SQL/ SQL Commands - DDL.pptx
umershah0263
 
Database management and System Development ppt
Database  management and System Development pptDatabase  management and System Development ppt
Database management and System Development ppt
michaelkasule
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
metsarin
 
Module 3
Module 3Module 3
Module 3
cs19club
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
SQL basics.pptx
SQL basics.pptxSQL basics.pptx
SQL basics.pptx
ZakReeceJames
 
Unit - II.pptx
Unit - II.pptxUnit - II.pptx
Unit - II.pptx
MrsSavitaKumbhare
 
Les10.ppt
Les10.pptLes10.ppt
Les10.ppt
AlhassanFederated
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
Saeid Zebardast
 
SQL for Data Science Tutorial | Data Science Tutorial | Edureka
SQL for Data Science Tutorial | Data Science Tutorial | EdurekaSQL for Data Science Tutorial | Data Science Tutorial | Edureka
SQL for Data Science Tutorial | Data Science Tutorial | Edureka
Edureka!
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
Anusha sivakumar
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
Ahsan Kabir
 
My sql
My sqlMy sql
My sql
Muhammad Umar
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATIONSQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
SQL _UNIT_DBMS_PRESENTSTATION_SQL _UNIT_DBMS_PRESENTSTATION
deeptanshudas100
 
SQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) commandSQL: Data Definition Language(DDL) command
SQL: Data Definition Language(DDL) command
sonali sonavane
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
Sankhya_Analytics
 
Mysql-overview.pptx
Mysql-overview.pptxMysql-overview.pptx
Mysql-overview.pptx
TamilHunt
 
Lecture - MY-SQL/ SQL Commands - DDL.pptx
Lecture - MY-SQL/ SQL Commands - DDL.pptxLecture - MY-SQL/ SQL Commands - DDL.pptx
Lecture - MY-SQL/ SQL Commands - DDL.pptx
umershah0263
 
Database management and System Development ppt
Database  management and System Development pptDatabase  management and System Development ppt
Database management and System Development ppt
michaelkasule
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
metsarin
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
SQL for Data Science Tutorial | Data Science Tutorial | Edureka
SQL for Data Science Tutorial | Data Science Tutorial | EdurekaSQL for Data Science Tutorial | Data Science Tutorial | Edureka
SQL for Data Science Tutorial | Data Science Tutorial | Edureka
Edureka!
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
Anusha sivakumar
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
Ahsan Kabir
 
Ad

Recently uploaded (20)

CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
ThanushsaranS
 
LLM finetuning for multiple choice google bert
LLM finetuning for multiple choice google bertLLM finetuning for multiple choice google bert
LLM finetuning for multiple choice google bert
ChadapornK
 
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnTemplate_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
cegiver630
 
Stack_and_Queue_Presentation_Final (1).pptx
Stack_and_Queue_Presentation_Final (1).pptxStack_and_Queue_Presentation_Final (1).pptx
Stack_and_Queue_Presentation_Final (1).pptx
binduraniha86
 
Geometry maths presentation for begginers
Geometry maths presentation for begginersGeometry maths presentation for begginers
Geometry maths presentation for begginers
zrjacob283
 
DPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdfDPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdf
inmishra17121973
 
183409-christina-rossetti.pdfdsfsdasggsag
183409-christina-rossetti.pdfdsfsdasggsag183409-christina-rossetti.pdfdsfsdasggsag
183409-christina-rossetti.pdfdsfsdasggsag
fardin123rahman07
 
Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..
yuvarajreddy2002
 
How to join illuminati Agent in uganda call+256776963507/0741506136
How to join illuminati Agent in uganda call+256776963507/0741506136How to join illuminati Agent in uganda call+256776963507/0741506136
How to join illuminati Agent in uganda call+256776963507/0741506136
illuminati Agent uganda call+256776963507/0741506136
 
Deloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit contextDeloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit context
Process mining Evangelist
 
chapter3 Central Tendency statistics.ppt
chapter3 Central Tendency statistics.pptchapter3 Central Tendency statistics.ppt
chapter3 Central Tendency statistics.ppt
justinebandajbn
 
Medical Dataset including visualizations
Medical Dataset including visualizationsMedical Dataset including visualizations
Medical Dataset including visualizations
vishrut8750588758
 
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptxPerencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
PareaRusan
 
Flip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptxFlip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptx
mubashirkhan45461
 
03 Daniel 2-notes.ppt seminario escatologia
03 Daniel 2-notes.ppt seminario escatologia03 Daniel 2-notes.ppt seminario escatologia
03 Daniel 2-notes.ppt seminario escatologia
Alexander Romero Arosquipa
 
Data Analytics Overview and its applications
Data Analytics Overview and its applicationsData Analytics Overview and its applications
Data Analytics Overview and its applications
JanmejayaMishra7
 
Ch3MCT24.pptx measure of central tendency
Ch3MCT24.pptx measure of central tendencyCh3MCT24.pptx measure of central tendency
Ch3MCT24.pptx measure of central tendency
ayeleasefa2
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
computer organization and assembly language.docx
computer organization and assembly language.docxcomputer organization and assembly language.docx
computer organization and assembly language.docx
alisoftwareengineer1
 
C++_OOPs_DSA1_Presentation_Template.pptx
C++_OOPs_DSA1_Presentation_Template.pptxC++_OOPs_DSA1_Presentation_Template.pptx
C++_OOPs_DSA1_Presentation_Template.pptx
aquibnoor22079
 
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
ThanushsaranS
 
LLM finetuning for multiple choice google bert
LLM finetuning for multiple choice google bertLLM finetuning for multiple choice google bert
LLM finetuning for multiple choice google bert
ChadapornK
 
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnTemplate_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
cegiver630
 
Stack_and_Queue_Presentation_Final (1).pptx
Stack_and_Queue_Presentation_Final (1).pptxStack_and_Queue_Presentation_Final (1).pptx
Stack_and_Queue_Presentation_Final (1).pptx
binduraniha86
 
Geometry maths presentation for begginers
Geometry maths presentation for begginersGeometry maths presentation for begginers
Geometry maths presentation for begginers
zrjacob283
 
DPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdfDPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdf
inmishra17121973
 
183409-christina-rossetti.pdfdsfsdasggsag
183409-christina-rossetti.pdfdsfsdasggsag183409-christina-rossetti.pdfdsfsdasggsag
183409-christina-rossetti.pdfdsfsdasggsag
fardin123rahman07
 
Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..Secure_File_Storage_Hybrid_Cryptography.pptx..
Secure_File_Storage_Hybrid_Cryptography.pptx..
yuvarajreddy2002
 
Deloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit contextDeloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit context
Process mining Evangelist
 
chapter3 Central Tendency statistics.ppt
chapter3 Central Tendency statistics.pptchapter3 Central Tendency statistics.ppt
chapter3 Central Tendency statistics.ppt
justinebandajbn
 
Medical Dataset including visualizations
Medical Dataset including visualizationsMedical Dataset including visualizations
Medical Dataset including visualizations
vishrut8750588758
 
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptxPerencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
PareaRusan
 
Flip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptxFlip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptx
mubashirkhan45461
 
Data Analytics Overview and its applications
Data Analytics Overview and its applicationsData Analytics Overview and its applications
Data Analytics Overview and its applications
JanmejayaMishra7
 
Ch3MCT24.pptx measure of central tendency
Ch3MCT24.pptx measure of central tendencyCh3MCT24.pptx measure of central tendency
Ch3MCT24.pptx measure of central tendency
ayeleasefa2
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
computer organization and assembly language.docx
computer organization and assembly language.docxcomputer organization and assembly language.docx
computer organization and assembly language.docx
alisoftwareengineer1
 
C++_OOPs_DSA1_Presentation_Template.pptx
C++_OOPs_DSA1_Presentation_Template.pptxC++_OOPs_DSA1_Presentation_Template.pptx
C++_OOPs_DSA1_Presentation_Template.pptx
aquibnoor22079
 
Ad

Data base.ppt

  • 1. DataBase What is Data?  data can be Unprocessed,UnOrganized,Meaningless,raw facts related to any object in consideration.  For example your name, age, height, weight, etc are some data related to you.  A picture , image , file , pdf etc can also be considered data. What is Database? Database is a systematic collection of data. Databases support storage and manipulation of data. Each database has one or more distinct APIs for creating, accessing, managing, searching and replicating the data it holds. Databases make data management easy. Let's discuss few examples. An online telephone directory would definitely use database to store data pertaining to people, phone numbers, other contact details, etc. Your electricity service provider is obviously using a database to manage billing , client related issues, to handle fault data, etc. 10/31/2017 1Information Science Dept. DB Lab Class Note
  • 2. Cont… What is a Database Management System (DBMS)? • Database Management System (DBMS) is a collection of programs which enables its users to access database, manipulate data, reporting / representation of data and control access to the database. Types of DBMS 1. Hierarchical  It employs the "parent-child" relationship of storing data.  Its has tree like structure.  It is rarely used nowadays. 2. Relational DBMS  It defines database relationships in the form of tables.  This is the most popular DBMS type in the market.  Eg:MySQL, Oracle, and Microsoft SQL Server database. 3. Object Oriented Relation DBMS  It supports storage of new data types.  The data to be stored is in the form of objects.  The objects to be stored in the database have attributes(i.e. gender…) .  Eg:c++,java,c#,c… etc. 10/31/2017 2Information Science Dept. DB Lab Class Note
  • 3. Cont… What is SQL? SQL stands for Structured Query language . • MySQL is a fast, easy-to-use RDBMS being used for many small and big businesses on the market. • MySQL is developed,marketed, and supported by MySQL AB, which is a Swedish company. • MySQL is becoming so popular . How can we use MYSQL in Database Program. 10/31/2017 3Information Science Dept. DB Lab Class Note
  • 4. Cont… MYSQL Exercise • Use MYSQL Command Line Client provided by MYSQLServer5.0/MY SQL Query Browser. • mysql > SHOW DATABASES; Creating a database • mysql > CREATE DATABASE database_name; Eg: create database Section; 10/31/2017 4Information Science Dept. DB Lab Class Note
  • 5. Cont… Deleting a database • mysql > DROP DATABASE database_name; – Eg: Drop database Section; To select a particular database • mysql > USE database_name; – Eg: use section; 10/31/2017 5Information Science Dept. DB Lab Class Note
  • 6. Cont… TO see tables in a database • mysql >SHOW TABLES; To create a new table in mysql • mysql > CREATE TABLE table_name; – Eg:CREATE TABLE student (id INT(3) NOT NULL PRIMARY KEY , name VARCHAR(20), address VARCHAR(30), mobile INT(10)); To see structure of Table in a mysql database • mysql > DESCRIBE/DESC table_name; – Eg: desc student; 10/31/2017 6Information Science Dept. DB Lab Class Note
  • 7. Cont… To insert data into a table • mysql > INSERT INTO table_name; – Eg:INSERT INTO student (id,Name,Address,Mobile) VALUES (01, "John", "America","098765431”); To insert more than one record at once, we can do this, with each set of field values separated by a comma. • Mysql>INSERT INTO table_name (column_1, column_2, column_3, other_value) VALUES (value1, value2, value3, …), (value1, value2, value3, …), (value1, value2, value3, …); – Eg:INSERT INTO student VALUES(03,”Teklay Brhane”,”Axum”,094856095),(04,”Brhane kfle”,”Mekelle”,0914008514),(…); To Make a copy of table – INSERT INTO table_name SELECT * FROM table_name; 10/31/2017 7Information Science Dept. DB Lab Class Note
  • 8. Cont… To See contents inside a table • mysql > SELECT * FROM table_name; • Eg:Select * from student; To Update a record in a table • mysql > UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value; • Eg: UPDATE student SET name = “John Mc” WHERE id ='01'; 10/31/2017 8Information Science Dept. DB Lab Class Note
  • 9. Cont… To Delete a record from a table • mysql > DELETE from [table_name] where [column name]=[field text]; • Eg: delete from student where id=“02”; To delete all records at the same way from a table • for slowly deletting data use: – mysql>delete from table_name; • for quickly daletting data use: – Mysql>TRUNCATE TABLE table_name; • for deletting the hole data from the table: – Mysql>Delete from table-name; 10/31/2017 9Information Science Dept. DB Lab Class Note
  • 10. Cont… To Add a column in a table • mysql > ALTER TABLE table_name ADD email VARCHAR(40) AFTER mobile; • Eg: ALTER TABLE student ADD email VARCHAR(40) AFTER mobile; 10/31/2017 10Information Science Dept. DB Lab Class Note
  • 11. Cont.. To modify a column in a table • mysql> ALTER TABLE table_name MODIFY Column_name Column Definition • Eg:ALTER TABLE student MODIFY name varchar(20); To Change a column in a table • mysql> ALTER TABLE table_name change Column_name Column Definition – Eg:ALTER TABLE student change name F_Nmae varchar(20); 10/31/2017 11Information Science Dept. DB Lab Class Note
  • 12. Cont… To drop a column in a table • mysql > ALTER TABLE table_name DROP column_name – Eg: ALTER TABLE student DROP Fname; 10/31/2017 12Information Science Dept. DB Lab Class Note
  • 13. SQL Constraints • SQL constraints are used to specify rules for the data in a table. • If there is any violation between the constraint and the data action, the action is aborted by the constraint. • Constraints can be specified when the table is created (inside the CREATE TABLE statement) or after the table is created (inside the ALTER TABLE statement). 10/31/2017 13Information Science Dept. DB Lab Class Note
  • 14. Cont… • In SQL, we have the following constraints: • NOT NULL - Indicates that a column cannot store NULL value • UNIQUE - Ensures that each row for a column must have a unique value • PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Ensures that a column (or combination of two or more columns) have a unique identity which helps to find a particular record in a table more easily and quickly • FOREIGN KEY - Ensure the referential integrity of the data in one table to match values in another table • CHECK - Ensures that the value in a column meets a specific condition • DEFAULT - Specifies a default value for a column 10/31/2017 14Information Science Dept. DB Lab Class Note
  • 15. SQL Not Null • By default, a table column can hold NULL values. • The NOT NULL constraint enforces a column to NOT accept NULL values. • Eg: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255)); 10/31/2017 15Information Science Dept. DB Lab Class Note
  • 16. SQL DEFAULT • To create a Default constraint on creating a table – Eg: CREATE TABLE Persons ( P_Id int NOT NULL default”0”, LastName varchar(255) NOT NULL default”YES”, FirstName varchar(255), Address varchar(255), City varchar(255)); • To create a DEFAULT constraint on the "City" column when the table is already created, use the following SQL: • Mysql>alter table table_name alter column_name set default””; – Eg: ALTER TABLE student ALTER id SET DEFAULT “0”; • To drop a DEFAULT constraint, use the following SQL: • Mysql> alter table table_name alter column_name drop default; – Eg: ALTER TABLE student ALTER id DROP DEFAULT; 10/31/2017 16Information Science Dept. DB Lab Class Note
  • 17. SQL Primary Key • The PRIMARY KEY constraint uniquely identifies each record in a database table. • Primary keys must contain UNIQUE values. • A primary key column cannot contain NULL values. • Most tables should have a primary key, and each table can have only ONE primary key. 10/31/2017 17Information Science Dept. DB Lab Class Note
  • 18. Cont… • SQL PRIMARY KEY Constraint on CREATE TABLE – Eg: CREATE TABLE Person(P_Id int NOT NULL,FirstName varchar(255) NOT NULL,LastName varchar(255),PRIMARY KEY (P_Id)); • SQL PRIMARY KEY Constraint on ALTER TABLE • Mysql>alter table table_name add primary key(column_name); – Eg: Alter table person add primary key(p_id); • To DROP a PRIMARY KEY Constraint • Mysql>Alter table table-name drope primary key; – Eg: Alter table person drop primary key; 10/31/2017 18Information Science Dept. DB Lab Class Note
  • 19. SQL UNIQUE • The UNIQUE constraint uniquely identifies each record in a database table. • SQL UNIQUE Constraint on CREATE TABLE – Eg: CREATE TABLE Person(P_Id int NOT NULL,FirstName varchar(255) NOT NULL,LastName varchar(255),UNIQUE (P_Id)); • SQL UNIQUE Constraint on a already created TABLE • Mysql> alter table table-name add unique(column_name); – Eg:Alter table person add unique(FirstName); • SQL To DROP a UNIQUE Constraint form a database table • Mysql> alter table table-name drop index (column_name); – Eg:ALTER TABLE Person DROP INDEX FirstName; 10/31/2017 19Information Science Dept. DB Lab Class Note
  • 20. SQL Foreign Key • A FOREIGN KEY in one table points to a PRIMARY KEY in another table • SQL FOREIGN KEY Constraint on CREATE TABLE • CREATE TABLE Orders ( O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY KEY (O_Id), FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) ) • SQL FOREIGN KEY Constraint on ALTER TABLE • Mysql>alter table table_name add index fk_(column_name); • Eg: alter table student add index fk_(section); • To DROP a FOREIGN KEY Constraint • Mysql>alter table table_name drop index(column_name); • Eg: ALTER TABLE Orders DROP FOREIGN KEY fk_PerOrders 10/31/2017 20Information Science Dept. DB Lab Class Note
  • 21. Questions??? Field Type Null Key Default Extra Stu_ID firstname lastname Address Email mobile int (4) char(15) char(15) varchar(50) varchar(30) int(10) NO NO YES YES YES YES PRIM UNI MUL 0 NO YES YES YES YES Auto increment 1) Create a table called Mytable in database called Mydatabase (given below is definition of table) 2) Enter four rows of data into the tables 3) Delete column from above table 4) Drop primary key from above table 5) Modify column name firstname to fname and lastname to lname 6) Add new column grade after column mobile & make varchar datatype. Set your default value “NO”. And then insert any value to Mobile column. 10/31/2017 21Information Science Dept. DB Lab Class Note
  • 22. • Create table orders like below: • Create table customers like below: 10/31/2017 Information Science Dept. DB Lab Class Note 22
  • 23. SQL JOIN • INNER JOIN: Returns all rows when there is at least one match in BOTH tables • LEFT JOIN: Return all rows from the left table, and the matched rows from the right table • RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table • FULL JOIN: Return all rows when there is a match in ONE of the tables 10/31/2017 Information Science Dept. DB Lab Class Note 23
  • 24. SQL Inner Join • The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables. • PS! INNER JOIN is the same as JOIN. 10/31/2017 Information Science Dept. DB Lab Class Note 24
  • 25. SQL Inner Join • SQL INNER JOIN Syntax • Mysql>SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name; • Example • SELECT Customers.CustomerName, Orders.OrderID FROM Customers INNER JOIN Orders ON Customers.CustomerID=Orders.CustomerID ORDER BY Customers.CustomerName; 10/31/2017 Information Science Dept. DB Lab Class Note 25
  • 26. SQL Left Join • The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match. • PS! In some databases LEFT JOIN is called LEFT OUTER JOIN. 10/31/2017 Information Science Dept. DB Lab Class Note 26
  • 27. SQL Left Join • SQL LEFT JOIN Syntax • Mysql>SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name=table2.column_name; • Example • SELECT Orders.order_id, Customers.CustomerName, Orderd.OrderDate FROM customers LEFT JOIN orders ON Orders.customer_id=Customers.customer_id order by Customers.CustomerName; 10/31/2017 Information Science Dept. DB Lab Class Note 27
  • 28. SQL Right Join 10/31/2017 Information Science Dept. DB Lab Class Note 28 • The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match. • PS! In some databases RIGHT JOIN is called RIGHT OUTER JOIN.
  • 29. SQL RIGHT JOIN • SQL RIGHT JOIN Syntax • Mysql>SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name=table2.column_name; • Example • SELECT Orders.order_id, Customers.CustomerName, Orders.OrderDate • FROM orders • RIGHT JOIN customers • ON Orders.customer_id=Customers.customer_id order by Customers.CustomerName; 10/31/2017 Information Science Dept. DB Lab Class Note 29
  • 30. SQL Full Join • The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2). • PS! FULL OUTER JOIN = LEFT + RIGHT joins. 10/31/2017 Information Science Dept. DB Lab Class Note 30
  • 31. SQL FULL OUTER JOIN • SQL FULL OUTER JOIN Syntax • Mysql>SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name=table2.column_name; • Example • SELECT Customers.CustomerName, Orders.OrderID FROM Customers FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID ORDER BY Customers.CustomerName; • 10/31/2017 Information Science Dept. DB Lab Class Note 31
  • 32. SQL Union • The UNION operator is used to combine the result-set of two or more SELECT statements. • Notice that each SELECT statement within the UNION must have the same number of columns. • The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order. 10/31/2017 Information Science Dept. DB Lab Class Note 32
  • 33. SQL Union • SQL UNION Syntax • Mysql>SELECT column_name(s) FROM table1 UNION ALL SELECT column_name(s) FROM table2; • All keyword allows dupicationof values but not union keyword. • Example SELECT customer_id FROM Customers union select customer_id from orders; 10/31/2017 Information Science Dept. DB Lab Class Note 33