Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

What Is A Database (DB) ?

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

What Is A Database (DB) ?

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

What is a Database(DB)?

•Any Collection of related •Databases can be stored in


information. different ways.
•Phone book. •On paper
•Shopping list. •In your mind.
•To do list. •On a computer/smart Apps

1-
Database management system(DBMS)

A special software program that helps to users create and


maintain a database.

• Makes it easy to manage large amount data.


• Handles security(like validations).
• Backups
• Importing/exporting data.
• Concurrency(the ability to execute more than one
task)
• Interacts with software apps

1-
Amazon Database diagram

Amazon.com will interacts with the DBMS in order to create,


read, update and delete the information.

1-
Two types of Databases

1-
C.R.U.D
Create Read Update Delete

1-
Relational database(SQL)

1-
Relational databases(SQL)

1-
Non-relational databases(noSQL/not just SQL)

1-
What is SQL?

• SQL stands for Structured Query Language


• SQL lets you access and manipulate databases
• SQL became a standard of the American National
Standards Institute (ANSI) in 1986, and of the
International Organization for Standardization
(ISO) in 1987.
• SQL is a standard language for accessing and
manipulating databases.

1-
D.M.R.T.D

 Data Definition Language (DDL)


 Data Manipulation Language (DML)
 Data Retrieval Language (DRL)
 Transaction Control Language (TCL)
 Data Control Language (DCL)

DDL -- create, alter, drop, truncate, rename


DML -- insert, update, delete, merge
DRL -- select
TCL -- commit, rollback, savepoint
DCL -- grant, revoke

1-
Using DDL(Data Definition Language)

create: It is used to create a table, i.e. to specify the meta


data, i.e. the DT of the column, constraints of the
column.
Alter: It is used to add or delete or modify a column.
drop: It is used to delete a table (Entire table is deleted.
i.e. the data and also the meta data)
truncate: It is used to delete only the data of the table and
also the constraint such as identity/autoincrement.

1-
CREATE TABLE Syntax

Syntax:
Create table <table_name> (col1 datatype1, col2
datatype2 …coln datatypen);
Ex:
SQL> create table student (no number (2), name
varchar (10), marks number (3));

1-
USING DML(Data Manipulation Language )

• INSERT

This will be used to insert the records into table.


We have two methods to insert.
 By value method
 By address method

• Update
• Delete

1-
USING VALUE METHOD

USING VALUE METHOD

Syntax:
insert into <table_name) values (value1, value2, value3 …. Valuen);

Ex:
SQL> insert into student values (1, ’sudha’, 100);
SQL> insert into student values (2, ’saketh’, 200);

• To insert a new record again you have to type entire insert command, if there are lot of
records this will be difficult.
• This will be avoided by using address method.

1-
USING ADDRESS METHOD

USING ADDRESS METHOD

Syntax:
insert into <table_name) values (&col1, &col2, &col3 …. &coln);
This will prompt you for the values but for every insert you have to use forward slash.

Ex:
SQL> insert into student values (&no, '&name', &marks);
Enter value for no: 1
Enter value for name: Jagan
Enter value for marks: 300
old 1: insert into student values(&no, '&name', &marks)
new 1: insert into student values(1, 'Jagan', 300)

SQL> /
Enter value for no: 2
Enter value for name: Naren
Enter value for marks: 400
old 1: insert into student values(&no, '&name', &marks)
new 1: insert into student values(2, 'Naren', 400)

1-
USING UPDATE

USING UPDATE

This can be used to modify the table data.

Syntax:
Update <table_name> set <col1> = value1, <col2> = value2 where <condition>;

Ex:
SQL> update student set marks = 500;
If you are not specifying any condition this will update entire table.

SQL> update student set marks = 500 where no = 2;


SQL> update student set marks = 500, name = 'Venu' where no = 1;

1-
USING DELETE

This can be used to delete the table data temporarily.

Syntax:
Delete <table_name> where <condition>;

Ex:
SQL> delete student;
If you are not specifying any condition this will delete entire table.

SQL> delete student where no = 2;

1-
USING DRL(Data Retrieval Language)

SELECTING DATA
Syntax:
Select * from <table_name>; -- here * indicates all columns
or
Select col1, col2, … coln from <table_name>;
Ex:
SQL> select * from student;

NO NAME MARKS
--- ------ --------
1 Sudha 100
2 Saketh 200
1 Jagan 300
2 Naren 400
3 Ramesh
4 Madhu
5 Visu
6 Rattu

1-
USING TCL(Transaction Control Language)

• COMMIT
• ROLLBACK
• SAVEPOINT

1-
USING COMMIT
USING COMMIT

This will be used to save the work.


Commit is of two types.
 Implicit
 Explicit

a) IMPLICIT

This will be issued by oracle internally in two situations.


 When any DDL operation is performed.
 When you are exiting from SQL * PLUS.

b) EXPLICIT

This will be issued by the user.

Syntax:
Commit or commit work;
* When ever you committed then the transaction was completed.

1-
USING ROLLBACK

This will undo the operation.


This will be applied in two methods.
 Upto previous commit
 Upto previous rollback

Syntax:
Roll or roll work;
Or
Rollback or rollback work;
* While process is going on, if suddenly power goes then oracle will rollback the transaction.

1-
USING SAVEPOINT

You can use savepoints to rollback portions of your current set of transactions.

Syntax:
Savepoint <savepoint_name>;

Ex:
SQL> savepoint s1;
SQL> insert into student values(1, ‘a’, 100);
SQL> savepoint s2;
SQL> insert into student values(2, ‘b’, 200);
SQL> savepoint s3;
SQL> insert into student values(3, ‘c’, 300);
SQL> savepoint s4;
SQL> insert into student values(4, ‘d’, 400);

1-

You might also like