Lab Manual for Database Management Systems (DBMS), Lab Reports of Database Management Systems (DBMS)

This is a Lab Manual for Database Management Systems (DBMS)

Typology: Lab Reports

2019/2020
On special offer
30 Points
Discount

Limited-time offer


Uploaded on 10/09/2021

vaibhav-ankolekar
vaibhav-ankolekar 🇮🇳

4

(3)

1 document

1 / 73

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
BHARATI VIDYAPEETH
COLLEGE OF ENGINEERING
DEPARTMENT OF INFORMATION TECHNOLOGY
ACADEMIC YEAR: 2019-2020
COURSE NAME: SQL Lab
COURSE CODE
ITL302
EXPERIMENT NO.
1
EXPERIMENT TITLE.
Introduction of E-R diagram
NAME OF STUDENT
Ankolekar Vaibhav Pandurang
ROLL NO.
1
CLASS
SE-IT
SEMESTER
III
GIVEN DATE
SUBMISSION DATE
CORRECTION DATE
REMARK
TIMELY
SUBMISSION
PRESENTATION
UNDERSTANDING
TOTAL
MARKS
04
07
15
NAME& SIGN.
OF FACULTY
Prof. H.A. Chavan
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
Discount

On special offer

Partial preview of the text

Download Lab Manual for Database Management Systems (DBMS) and more Lab Reports Database Management Systems (DBMS) in PDF only on Docsity!

BHARATI VIDYAPEETH

COLLEGE OF ENGINEERING

DEPARTMENT OF INFORMATION TECHNOLOGY

ACADEMIC YEAR: 201 9 - 2020

COURSE NAME: SQL Lab

COURSE CODE ITL 302

EXPERIMENT NO. 1

EXPERIMENT TITLE. Introduction of E-R diagram

NAME OF STUDENT Ankolekar Vaibhav Pandurang

ROLL NO. 1

CLASS SE-IT

SEMESTER III

GIVEN DATE

SUBMISSION DATE

CORRECTION DATE

REMARK

TIMELY

SUBMISSION

PRESENTATION UNDERSTANDING

TOTAL

MARKS

NAME& SIGN.

OF FACULTY

Prof. H.A. Chavan

EXPERIMENT NO : 1

AIM : Introduction of E-R diagram

THEORY :

The Entity-Relationship (E-R) data model perceives the real world as consisting of basic objects, called entities, and relationships among these objects. It was developed to facilitate database design by allowing specification of an enterprise schema, which represents the overall logical structure of a database. The E-R data model is one of several semantic data models; the semantic aspect of the model lies in its representation of the meaning of the data. The E-R model is very useful in mapping the meanings and interactions of real-world enterprises onto a conceptual schema. Because of this usefulness, many database-design tools draw on concepts from the E-R model. An entity is a “thing” or “object” in the real world that is distinguishable from all other objects. For example, each person in an enterprise is an entity. An entity has a set of properties, and the values for some set of properties may uniquely identify an entity. An entity is represented by a set of attributes. Attributes are descriptive properties possessed by each member of an entity set. The designation of an attribute for an entity set expresses that the database stores similar information concerning each entity in the entity set; however, each entity may have its own value for each attribute. Mapping cardinalities, or cardinality ratios, express the number of entities to which another entity can be associated via a relationship set. For a binary relationship set R between entity sets A and B, the mapping cardinality must be one of the following:

  • One to one: An entity in A is associated with at most one entity in B, and an entity in B is associated with at most one entity in A.
  • One to many: An entity in A is associated with any number (zero or more) of entities in B. An entity in B, however, can be associated with at most one entity in A.
  • Many to one: An entity in A is associated with at most one entity in B. An entity in B, however, can be associated with any number (zero or more) of entities in A.
  • Many to many: An entity in A is associated with any number (zero or more) of entities in B, and an entity in B is associated with any number (zero or more) of entities in A. A relationship is an association among several entities. The collection of all entities of the same type is an entity set, and the collection of all relationships of the same type is a relationship set. A superkey of an entity set is a set of one or more attributes that, taken collectively, allows us to identify uniquely an entity in the entity set. We choose a minimal superkey for each entity set from among its superkeys; the minimal superkey is termed the entity set’s primary key. Similarly, a relationship set is a set of one or more attributes that, taken collectively, allows us to identify uniquely a relationship in the relationship set. Likewise, we choose a minimal superkey for each relationship set from among its superkeys; this is the relationship set’s primary key.

E-R DIAGRAM :

CONCLUSION :

With the help of Entity-Relationship diagram we can create the required database and perform queries. For example, in case of Airline Reservation System we can make queries like

to find the schedule time of a flight, number of booked seats in a flight, flight fares etc. with the help of query language like SQL Relational Algebra, Relational Calculus etc. We can represent a database that conforms to an E-R database schema by a collection of tables. For each entity set and for each relationship set in database, there is a unique table to which we can assign the name of the corresponding entity set and relationship set. Each table has multiple columns, each of which has a unique name. Both the E-R model and the relational-database model are abstract, logical representations of real-world enterprises. Thus, we have studied how to construct an E-R diagram.

EXPERIMENT NO : 2

AIM : DDL Statements and Integrity Constraints

THEORY :

Data-definition language (DDL). The SQL DDL provides commands for defining relation schemas, deleting relations, and modifying relation schemas. The SQL standard supports a variety of built-in types, including:

  • char(n): A fixed-length character string with user-specified length n. The full form, character, can be used instead.
  • varchar(n): A variable-length character string with user-specified maximum length n. The full form, character varying, is equivalent.
  • int: An integer (a finite subset of the integers that is machine dependent). The full form, integer, is equivalent.
  • smallint: A small integer (a machine-dependent subset of the integer type).
  • numeric(p, d): A fixed-point number with user-specified precision. The number consists of p digits (plus a sign), and d of the p digits are to the right of the decimal point. Thus, numeric(3,1) allows 44.5 to be stored exactly, but neither 444.5 nor 0. can be stored exactly in a field of this type.
  • real, double precision: Floating-point and double-precision floating-point numbers with machine-dependent precision.
  • float(n): A floating-point number with precision of at least n digits Integrity constraints ensure that changes made to the database by authorized users do not result in a loss of data consistency. Thus, integrity constraints guard against accidental damage to the database. an integrity constraint can be an arbitrary predicate pertaining to the database. However, arbitrary predicates may be costly to test. Thus, most database systems allow one to specify only those integrity constraints that can be tested with minimal overhead. The allowed integrity constraints include: PRIMARY KEY (Ak1 , Ak2 , …, Akm): The primary-key specification says that attributes (Ak1 , Ak2 , …, Akm) form the primary key for the relation. The primary-key attributes are required to be nonnull and unique; that is, no tuple can have a null value for a primary-key attribute, and no two tuples in the relation can be equal on all the primary-key attributes. Although the primary-key specification is optional, it is generally a good idea to specify a primary key for each relation. FOREIGN KEY (Ak1 , Ak2 , …, Akn) references s: The foreign key specification says that the values of attributes (Ak1 , Ak2 , …, Akn) for any tuple in the relation must correspond to values of the primary key attributes of some tuple in relation s. NOT NULL: The not null constraint on an attribute specifies that the null value is not allowed for that attribute; in other words, the constraint excludes the null value from the domain

of that attribute. For example, in Figure 3.1, the not null constraint on the name attribute of the instructor relation ensures that the name of an instructor cannot be null. DDL Commands :

  1. CREATE is used to create the database or its objects (like table, index, function, views, store procedure and triggers). CREATE DATABASE Syntax : CREATE DATABASE database_name; CREATE TABLE Syntax : CREATE TABLE table_name ( Column1_name datatype, Column2_name datatype .. Integrity Constraints, Integrity Constraints);
  2. ALTER is used to alter the structure of the database. Adding Column Syntax : ALTER TABLE table_name ADD new_Column_name Column_definition [FIRST/AFTER Column_name]; Modify Existing Column Syntax : ALTER TABLE table_name MODIFY Column_name Column_definition [FIRST/AFTER Column_name]; Rename Column Syntax : ALTER TABLE table_name CHANGE old_Column_name new_Column_name Column_definition; Rename Table Syntax : ALTER TABLE table_name RENAME TO new_table_name;
  3. DROP is used to delete objects from the database. DROP DATABASE Syntax : DROP DATABASE [IF EXISTS] database_name; DROP TABLE Syntax : DROP TABLE [IF EXISTS] table_name;

important role as the give characteristics to the table and columns. Storing different types of data in table is only possible due to integrity contraints. Thus, we have studied the DDL Statements and Integrity Constraints.

BHARATI VIDYAPEETH

COLLEGE OF ENGINEERING

DEPARTMENT OF INFORMATION TECHNOLOGY

ACADEMIC YEAR: 201 9 - 2020

COURSE NAME: SQL Lab

COURSE CODE ITL 302

EXPERIMENT NO. 3

EXPERIMENT TITLE.

Perform Data Manipulations operation on

populated database

NAME OF STUDENT Ankolekar Vaibhav Pandurang

ROLL NO. 1

CLASS SE-IT

SEMESTER III

GIVEN DATE

SUBMISSION DATE

CORRECTION DATE

REMARK

TIMELY

SUBMISSION

PRESENTATION UNDERSTANDING

TOTAL

MARKS

NAME& SIGN.

OF FACULTY

Prof. H.A. Chavan

SET column_name1 = newValue1, column_name2 = newValue2, ... column_nameN = newValueN WHERE condition;

PROGRAM :

Inserting data into table user INSERT INTO project2.user (UserID, FirstName, LastName, DOB, Contact) VALUES ('192160', 'Adam', 'Smith', '1998- 03 - 18', '9876543210'); INSERT INTO project2.user (UserID, FirstName, LastName, DOB, Contact) VALUES ('192161', 'Roger', 'Lewis', '1992- 11 - 24', '8182760123'); INSERT INTO project2.user (UserID, FirstName, LastName, DOB, Contact) VALUES ('192162', 'Angelika', 'Felix', '2001- 03 - 18', '9819487141'); INSERT INTO project2.user (UserID, FirstName, LastName, DOB, Contact) VALUES ('192163', 'Daniel', 'Blair', '1994- 07 - 01', '7210217434'); INSERT INTO project2.user (UserID, FirstName, LastName, DOB, Contact) VALUES ('192164', 'Mayson', 'Briggs', '1992- 09 - 13', '8898853976'); INSERT INTO project2.user (UserID, FirstName, LastName, DOB, Contact) VALUES ('192165', 'Will', 'Terner', '2000- 05 - 01', '9833834968'); Updating data into table user UPDATE project2.user SET FirstName = 'James' WHERE (UserID = '192164'); Deleting data from table user DELETE FROM project2.user WHERE (UserID = '192164');

OUTPUT :

Inserting data into table user Updating data into table user Deleting data from table user

CONCLUSION :

A database is incomplete without the data in it. Storing data in the main part of the database. These data manipulation commands help us to do so. Insertion, updating and deletion are the basic purpose of an application and user data. These DML helps to simply manipulation of data. Thus, we studied the Data Manipulation Commands.

EXPERIMENT NO : 4

AIM : Perform Authorization using Grant and Revoke

THEORY :

Data Controlling Language (DCL) helps users to retrieve and modify the data stored in the database with some specified queries. Grant and Revoke belong to these types of commands of the Data controlling Language. Granting of authorization for data access. By granting different types of authorization, the database administrator can regulate which parts of the database various users can access. The authorization information is kept in a special system structure that the database system consults whenever a user tries to access the data in the system. We may assign a user several forms of authorizations on parts of the database. Authorizations on data include:

  • Authorization to read data.
  • Authorization to insert new data.
  • Authorization to update data.
  • Authorization to delete data. Each of these types of authorizations is called a privilege. We may authorize the user all, none, or a combination of these types of privileges on specified parts of a database, such as a relation or a view. Grant SQL Grant command is specifically used to provide privileges to database objects for a user. This command also allows users to grant permissions for other users too. When a user submits a query or an update, the SQL implementation first checks if the query or update is authorized, based on the authorizations that the user has been granted. If the query or update is not authorized, it is rejected. The SQL standard includes the privileges select, insert, update, and delete. The privilege all privileges can be used as a short form for all the allowable privileges. A user who creates a new relation is given all privileges on that relation automatically. The SQL data-definition language includes commands to grant and revoke privileges. The grant statement is used to confer authorization. The basic form of this statement is: GRANT <privilege-list> ON <relation-name or view-name> TO <user/role-list>; The privilege list allows the granting of several privileges in one command. Revoke Revoke command withdraw user privileges on database objects if any granted. It does operations opposite to the Grant command. When a privilege is revoked from a particular user

U, then the privileges granted to all other users by user U will be revoked. To revoke an authorization, we use the revoke statement. It takes a form almost identical to that of grant: REVOKE <privilege-list> ON <relation-name or view-name> FROM <user/role-list>; Revocation of privileges is more complex if the user from whom the privilege is revoked has granted the privilege to another user.

OUTPUT :

Creating new user and setting privileges Root is the username of Local Instance. ‘->’ this symbol indicates that the query is executed by that User. GoTo Sever and then click Users and Privileges Created User1 and only SELECT privilege given to it. Creating new connection and using to access database.

Executing UPDATE query by User1: User 1 - > UPDATE game SET price= 1300 WHERE gameid= 9141 ; User 1 - > SELECT * FROM game; Creating another user User2 using SQL. root - > CREATE USER 'User2'@'localhost' IDENTIFIED BY 'User234@'; root - > GRANT ALL PRIVILEGES ON game TO 'User2'@'localhost'; User2 is given authorization to perform All queries. Creating connection of User

User2 - > UPDATE game SET price= 1400 WHERE gameid= 9141 ; root - > REVOKE UPDATE ON game TO 'User2'@'localhost'; User2 - > UPDATE game SET price= 1500 WHERE gameid= 9141 ;

CONCLUSION :

Data security is very important in Database creation. As database is connected to various applications, the data of the user must be safe. The data authorization is required so only those users who have proper authorization can access the data, because some databases are so complex that any small change can destroy or crash the data. These grant and revoke are used so that only some part of database can be viewed by others as stated by the authorizer of database. Thus, we have studies importance of authorization in Database.