DBMS Commands DDL DML DCL ENTITY RELATIONSHIP.pptx

Tulasi72 93 views 37 slides Jul 06, 2024
Slide 1
Slide 1 of 37
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37

About This Presentation

DBMS commands


Slide Content

DATABASE MANAGEMENT systems LAB

DBMS LAB SYLLABUS

ex 1: Design a database for enterprise applications with the various Data Models Aim: Enterprise Application : College STUDENT ( USN , SName , Address, Phone, Gender ) SEMSEC ( SSID , Sem, Sec ) CLASS ( USN , SSID ) SUBJECT ( Subcode , Title, Sem, Credits ) IAMARKS ( USN , Subcode , SSID , Test1, Test2, Test3, FinalIA ) Solution: E-R Diagram Schema Diagram

Example Banking Enterprise Hospital Management System Library Management system University Enterprise Employee Management System

College Enterprise – ER Diagram

College Enterprise – Schema Diagram

Ex 2 : DDL commands Creating , Modifying, Deleting Relations Using SQL

DDL The Data Definition Language (DDL): This subset of SQL supports the creation, deletion, and modification of definitions for tables and views. Create table Alter table ADD Column MODIFY Data type DROP Column RENAME Column Drop Table Rename Table Truncate

DDL - CREATE CREATE TABLE: This is used to create a new relation (table) Syntax: CREATE TABLE < relation_name / table_name > (field_1 data_type (size), field_2 data_type (size)); Example: CREATE TABLE Students ( sid NUMBER (3), name CHAR (10), login CHAR (5), age INTEGER, GPA real);

DDL - ALTER 1) ADD...: This is used to add some extra fields into existing relation. Syntax: ALTER TABLE relation_name ADD (new field_1 data_type (size), new field_2 data_type (size),..); Example: ALTER TABLE std ADD (Address CHAR(10));

DDL - ALTER 2) MODIFY...: This is used to change the width as well as data type of fields of existing relations. Syntax: ALTER TABLE relation_name MODIFY (field_1 newdata_type (Size), field_2 newdata_type (Size),.... field_newdata_type (Size)); Example: ALTER TABLE student MODIFY( sname VARCHAR(10), login VARCHAR(5));

DDL - ALTER 3) DROP...: This is used to remove any field of existing relations. Syntax: ALTER TABLE relation_name DROP COLUMN ( field_name ); Example: ALTER TABLE Students DROP column (name);

DDL - ALTER 4) RENAME: This is used to change the name of fields in existing relations. Syntax: ALTER TABLE relation_name RENAME COLUMN (OLD field_name ) to (NEW field_name ); Example: ALTER TABLE Students RENAME COLUMN name to sname ;

DDL - DROP DROP TABLE: This is used to delete the structure of a relation. It permanently deletes the records in the table. Syntax: DROP TABLE relation_name ; Example: DROP TABLE Students;

DDL - TRUNCATE DROP TABLE : This statement in sql causes the table to be deleted from database. Even the name of table under database is deleted. TRUNCATE : This statement in sql deletes all the rows (instances) of the table leaving behind structure of table(schema) and relationship.  The name of table under database and also schema is retained.  Only data is deleted .

DDL - TRUNCATE Truncate is a DDL command & delete is a DML command. Syntax: TRUNCATE TABLE <Table name> Example TRUNCATE TABLE Students;

DDL- RENAME RENAME: It is used to modify the name of the existing database object. Syntax: RENAME TABLE old_relation_name TO New_relation_name ; Example: RENAME TABLE Students TO Students1;

Ex 3: DML commands The Data Manipulation Language (DML): This subset of SQL allows users to pose queries and to insert, delete, and modify rows. INSERT UPDATE DELETE

DML – INSERT INSERT INTO: This is used to add records into a relation. These are three type of INSERT INTO queries which are as Inserting a single record Syntax: INSERT INTO < relation/table name> (field_1,field_2…… field_n )VALUES (data_1,data_2,........ data_n ); Example: INSERT INTO Students ( sid,name,login,age,gpa )VALUES (50000,’Dave’,’dave@cs’,19,3.2);

Tuples are inserted ,using the INSERT command. We can insert a single tuple into the Students table as follows:

Inserting all records from another relation Syntax: INSERT INTO relation_name_1 SELECT Field_1,field_2,field_n FROM relation_name_2 WHERE field_x =data; Example: INSERT INTO Students SELECT sno , sname FROMstudent1 WHERE name = ‘ Ramu ‘;

Inserting multiple records Syntax: INSERT INTO relation_name field_1,field_2,..... field_n ) VALUES (&data_1, &data_2,........ & data_n ); Example: INSERT INTO Students ( sid , name, login, age, gpa ) VALUES (& sid , ’&name’, ’&login’, &age, & gpa ); Enter value for sid : 53666 Enter value for name: Jones Enter value for login: jones@cs Enter value for age: 18 Enter value for gpa : 3.2

DML - UPDATE UPDATE-SET-WHERE: This is used to update the content of a record in a relation. Syntax: UPDATE relation name SET Field_name1=data, field_name2=data, WHERE field_name =data; Example: UPDATE Students SET name = ‘James’ WHERE sid =53650;

We can modify the column values in an existing row using the UPDATE command. For example, we can increment the age and decrement the gpa of the student with sid 53688:

DML - DELETE DELETE-FROM : This is used to delete all the records of a relation but it will retain the structure of that relation. 1.) DELETE-FROM : This is used to delete all the records of relation. Syntax: DELETE FROM relation_name ; Example: DELETE FROM Students;

DML - DELETE DELETE -FROM-WHERE: This is used to delete a selected record from a relation. Syntax: DELETE FROM relation_name WHERE condition; Example: DELETE FROM Students WHERE sid = 53650;

We can delete tuples using the DELETE command. We can delete all Students tuples with name equal to Smith using the command:

QUERYING RELATIONAL DATA

To Retrieve data from one or more tables. SELECT FROM: To display all fields for all records. Syntax : SELECT * FROM relation_name ; Example : select * from Students;

select * from Students;

SELECT FROM: To display a set of fields for all records of relation. Syntax: SELECT a set of fields FROM relation_name ; Example: select sid , name, gpa from Students;

SELECT - FROM -WHERE: This query is used to display a selected set of fields for a selected set of records of a relation. Syntax: SELECT a set of fields FROM relation_name WHERE condition;   Example: select * FROM Students S WHERE S.age <18;

We can also combine information in the Students and Enrolled relations

We can also combine information in the Students and Enrolled relations. Output: name cid Smith Topology112
Tags