Professional Documents
Culture Documents
RDBMS:
SQL
DBMS RDBMS
DBMS application store data RDBMS application store data in
as File a Tabular Form
Normalization is not present Normalization is present
It doesn’t support distributed It support distributed database
database
DBMS doesn’t apply any security RDBMS defines the integrity
with regards to data manipulation constraint for the purpose of
ACID (Atomicity, Consistency,
Isolation and Durability)
property
DBMS is meant to be for small RDBMS is designed to handle
organization and deal with small large amount of data.
data, it supports single users It supports Multiple data
Ex. File System, XML Ex. My sql, postgres, sql server,
oracle
SQL PL/SQL
SQL is a query execution or PL/SQL is a complete programming
commanding language language
SQL is data oriented language PL/SQL is a procedural language
SQL is very declarative in nature PL/SQL has a procedural nature
It is used for manipulating data It is used for creating applications
We can execute one statement at a We can execute block of statements in
time in SQL PL/SQL
SQL tells database, what to do? PL/SQL tells database how to do
We can embed SQL in PL/SQL We can not embed PL/SQL in SQL
*DML: This language is used to manipulate the data you have stored. It is
collection of four commands.
INSERT, UPDATE, DELETE, MERGE
*DRL: This language is used to retrieve the data from the database. It is
collection of only one command.
SELECT
CREATE TABLE :
The CREATE TABLE statement is used to create a new table in a database.
Syntax:- CREATE TABLE table_name(
column1 datatype,
column2 datatype,
);
1. The column parameters specify the names of the columns of the
table.
2. The data type parameter specifies the type of data the column can
hold (e.g. varchar, integer, date, etc.).
Ex:- create table student( s_id int(10), s_name varchar(20), s_age int (2));
Note: NOTNULL :- the field cant be empty.
3) DROP: This command is used to rename the table from the database.
Syntax: DROP TABLE <TABLE_NAME>;
Ex:
DROP table student;
DROP table emp;
4) TRUNCATE: This command is used to remove all the rows (only data in the
table will be removed) from the table.
Syntax: TRUNCATE TABLE <TABLE_NAME>;
Ex: TRUNCATE table student;
Select * from TAB; // ALL TABLE NAME’S ARE DISPLAYED
DELETE TRUNCATE
We can Roll Back the data. We cannot Roll Back the data.
Rows are deleting temporally. Rows are deleting
permanently.
Where clause can be used. Where clause cannot be used.
Delete is sub language DML. Delete is sub language DDL.
Syntax: Delete from table_name ; Syntax:- Truncate table table-name;
or
Delete from table_name
[where condition];
NOTE: When we use a Truncate command the table gets dropped and re-
created. As the structure is effected is called as a DDL command.
All DDL command are permanent.
All DML command are Temporary.
DML is short name of Data Manipulation Language which deals with
data manipulation and includes most common SQL statements such
SELECT, INSERT, UPDATE, DELETE, etc., and it is used to store, modify,
retrieve, delete and update data in a database.
SELECT - retrieve data from a database
INSERT :
The INSERT INTO statement is used to insert new records in a table.
It is possible to write the INSERT INTO statement in two ways.
The first way specifies both the column names and the values to be
inserted:
1. INSERT INTO table_name (column1,column2,column3, ...)
VALUES(value1,value2,value3, ...);
2. INSERT INTO table_name
VALUES (value1,value2,value3, ...);
INSERT MULTIPLE ROWS
INSERT INTO student (ID, NAME)
VALUES (1, 'ARMAAN');
INSERT INTO student (ID, NAME)
VALUES (2, 'BILLY');
INSERT INTO student (ID, NAME)
VALUES (3, 'CHARLIE');
SQL UPDATE
The SQL commands (UPDATE and DELETE) are used to modify the data
that is already in the database. The SQL DELETE command uses a WHERE
clause.
SQL UPDATE statement is used to change the data of the records held by
tables. Which rows is to be update, it is decided by a condition. To specify
condition, we use WHERE clause.
Syntax:
UPDATE table_name
SET column_name = expression
WHERE conditions
Example:
UPDATE students
SET User_Name = 'beinghuman'
WHERE Student_Id ='3'
Syntax:-
SELECT COUNT (expression)
1.FROM tables
2.WHERE conditions;
1. SELECT COUNT(name) FROM employee_table;
It will return the total number of names of employee_table. But null fields
will not be counted.
SQL SELECT COUNT(*)
1. SELECT COUNT(*) FROM employee_table;
The "select count(*) from table" is used to return the number of records in
table.
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Operator Description
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal.
Note: In some versions of SQL this
operator may be written as !=
BETWEEN Between a certain range
LIKE Search for a pattern
IN To specify multiple possible values
for a column
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
mysql> SELECT * FROM student WHERE s_id='101' AND s_age=56;
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 101 | xyz | 56 |
+------+--------+-------+
1 row in set (0.00 sec)
mysql> SELECT * FROM student WHERE NOT s_age=56 and not s_id=200;
+------+--------+-------+
| s_id | s_name | s_age |
+------+--------+-------+
| 10 | devraj | 29 |
| 20 | abc | 19 |
| 11 | tt7f | 78 |
| 11 | tt7f | 78 |
| 106 | Anand | 16 |
| 210 | Bindhu | 747 |
| 110 | abhi | 37 |
+------+--------+-------+
7 rows in set (0.00 sec)