What Is A Database (DB) ?
What Is A Database (DB) ?
1-
Database management system(DBMS)
1-
Amazon Database diagram
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?
1-
D.M.R.T.D
1-
Using DDL(Data Definition Language)
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
• Update
• Delete
1-
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
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
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.
1-
USING DELETE
Syntax:
Delete <table_name> where <condition>;
Ex:
SQL> delete student;
If you are not specifying any condition this will delete entire table.
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
a) IMPLICIT
b) EXPLICIT
Syntax:
Commit or commit work;
* When ever you committed then the transaction was completed.
1-
USING 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-