Professional Documents
Culture Documents
DBMS Ppts Unit2.1
DBMS Ppts Unit2.1
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Formal Relational Query
Languages
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
SQL COMMANDS
INTRODUCTION
Structure Query Language(SQL) is a database query
language used for storing and managing data in
Relational DBMS.
SQL was the first commercial language introduced
for E.F Codd's Relational model of database.
Today almost all RDBMS(MySql, Oracle, Infomix,
Sybase, MS Access) use SQL as the standard
database query language.
SQL is used to perform all types of data operations
in RDBMS.
DDL: Data Definition Language
• Example:
CREATE TABLE Person ( PersonID int, LastName
varchar(255), FirstName varchar(255), Address
varchar(255), City varchar(255) );
Create table using another table
• A copy of an existing table can be created
using a combination of the CREATE TABLE
statement and the SELECT statement.
Syntax:
CREATE TABLE new_table_name AS SELECT
column1, column2,...
FROM existing_table_name;
Example of creating table from another table:
Syntax:
ALTER TABLE table_name ADD column_name
datatype;
Example:
ALTER TABLE Person ADD weight_in_Kgs int;
• To delete a column in an existing table:
Syntax:
Example:
ALTER TABLE Person DROP COLUMN
weight_in_Kgs;
• To rename a column in an existing table:
Syntax:
Example:
ALTER TABLE Person RENAME COLUMN
weight_in_Kgs To Wght_in_kgs;
• To modify a table by changing the data type
of a column in a table
Syntax:
Example:
ALTER TABLE Person MODIFY Wght_in_kgs
varchar(90);
TRUNCATING TABLES
It empties a table completely.
Syntax:
TRUNCATE TABLE tablename;
Example:
Truncate table person;
DESTROYING TABLES
Drop table statement with table name can destroy a
specific table
Syntax:
DROP TABLE tablename;
Example:
DROP TABLE person;
RENAME TABLE
COMMAND
Syntax-
ALTER TABLE table_name
RENAME to new_table_name;
DML: Data Manipulation
Language
• DML commands are used for manipulating
the data stored in the table and not the table
itself.
• DML commands are not auto-committed. It
means changes are not permanent to
database, they can be rolled back.
INSERTING DATA INTO TABLE:
The insert operation on inserting a single row:
• Creates an empty row in database table
• Loads the value passed by insert command into the
specified columns
Syntax:
INSERT INTO tablename (Column_name1,
Column_name2…) values (expression1, expression2);
Example:
INSERT INTO person (personID, firstname, lastname,
address) VALUES (23, ‘ravi’, ‘dubey’, ‘patiala’ );
• Inserting data into a table from another table
INSERT INTO <tablename> select
<columnname1>,<columnname2> from
<tablename>;
VIEWING DATA IN TABLES
The select command is used to retrieve rows
selected from one or more tables
To select all rows and all columns:
SELECT Column1,… , Column2 from tablename;
OR
SELECT * from tablename;
Example:
SELECT * FROM person;
Selected columns and all rows
Select<columnname1>,<columnname2>, from
<tablename>;
Select <columnname1>,<columnname2>
from <tablename> where <condition>;
Example: Select name,roll no from student
where roll no=1;
Eliminating duplicate rows while
using select statement
Select distinct
<columnname1>,<columnname2> from
<tablename>;
Select distinct * from student;
DELETE OPERATIONS
Delete command deletes rows from table that
satisfies given condition represented by where clause
and returns number of records deleted.
Example:
DELETE FROM person;
Removal of Specific Rows
129