D Practical 2
D Practical 2
● Importance: Listing all available databases is a fundamental operation that allows database
administrators and users to see what databases exist within the DBMS environment. This is
crucial for managing multiple databases, ensuring that the correct database is being used, and
avoiding conflicts or redundant data storage.
● Concepts: In most DBMS, there is a specific command or set of commands that can be used to
view all databases. Understanding these commands helps in navigating the DBMS and managing
databases effectively.
Creating a Database:
● Importance: Creating a new database is often one of the first steps in setting up a new project or
application. This involves defining a new database in which tables, views, and other database
objects will be created.
● Concepts: When creating a database, it's essential to choose a meaningful name that reflects its
purpose. This helps in maintaining clarity and organization, especially when dealing with
multiple databases.
● Importance: After selecting a database, it's necessary to understand its structure by viewing all
the tables it contains. This operation is essential for understanding the schema, relationships, and
the types of data stored.
● Concepts: Tables are the primary storage objects in a database, holding the data in rows and
columns. Knowing how to list all tables provides insight into the organization and complexity of
the database.
● Importance: Tables are where data is stored within a database. Creating tables with well-defined
structures and constraints ensures data integrity, consistency, and accuracy.
● Concepts:
○ Basic Table Creation: Involves defining the columns and their data types. This forms the
basic structure of the table.
○ Constraints: Constraints are rules applied to columns to enforce data integrity:
■ Primary Key Constraint: A primary key uniquely identifies each record in a
table. It ensures that no two rows can have the same primary key value, providing
a unique identifier for each row.
■ Foreign Key Constraint: A foreign key is a column or set of columns that
creates a link between the data in two tables. It ensures referential integrity by
requiring that a value in one table matches a value in another table.
■ Not Null Constraint: Ensures that a column cannot contain a NULL value. This
is useful for columns that must always have a value, such as a primary key or a
required field.
■ Unique Constraint: Ensures that all values in a column are unique across the
table. This is often used for columns that require unique values, such as email
addresses or usernames.
CRUD Operations:
● Create (Insert): The process of adding new records to a table. This operation is fundamental for
populating tables with data. Each insert operation adds a new row to the table, with values for
each column.
● Read (Select): Retrieving data from a table. This is one of the most commonly used operations,
allowing users to query the database and view the data stored within. Select queries can be
simple, retrieving all data from a table, or complex, involving multiple conditions and joins
between tables.
● Update: Modifying existing records in a table. This operation allows for the correction and
updating of data. Update operations can target specific rows based on conditions, and change one
or more column values.
SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE
Department of Computer
Affiliated to University of Mumbai
● Delete: Removing records from a table. This operation is used to clean up data, removing rows
that are no longer needed. It can target specific rows based on conditions, ensuring that only the
intended data is deleted.
Code:
1.
2.
3.
4. Without Constraints
SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE
Department of Computer
Affiliated to University of Mumbai
With Constraints:
5.a.
b.
c.
SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE
Department of Computer
Affiliated to University of Mumbai
d.
Output:
1.
2.
SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE
Department of Computer
Affiliated to University of Mumbai
3.
4. Without Constraints
With Constraints:
5.a.
SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE
Department of Computer
Affiliated to University of Mumbai
b.
c.
d.
SHRI G.P.M. DEGREE COLLEGE OF SCIENCE & COMMERCE
Department of Computer
Affiliated to University of Mumbai
Learning Outcomes:
1.We understood how to execute commands to manage databases and tables.
2.We learned how to define and enforce constraints within tables.
3.We developed skills in performing CRUD operations to manipulate data within the database.
Course Outcomes:
Student will be able to view all databases, create a database, view all tables in a database, create tables
with and without constraints, perform CRUD operations.
Conclusion:
Viva Questions:
1. What is the significance of viewing all databases in a DBMS?
2. Why is it important to create a database with a meaningful name?
3. How do constraints enhance data integrity in a database?
4. Can you explain the differences between primary key and foreign key constraints?
5. What are the basic CRUD operations and why are they essential in database management?
For Faculty use: