Dbms Ex8
Dbms Ex8
Description:
Views: A View is a virtual table created by a SQL query that combines data from one or more tables. It
does not store data itself but provides a way to simplify complex queries by encapsulating them into a
single object. Views help in abstracting the complexity and can also be used to limit data access to
certain users.
Syntax:
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Sequences A sequence is a database object that generates a sequence of unique numbers, typically used
for automatically generating primary key values. Sequences are independent of tables and are useful for
auto-incrementing fields such as user IDs or invoice numbers. Once created, they can be referenced to
get the next value or the current value.
Syntax:
CREATE SEQUENCE sequence_name
START WITH start_value
INCREMENT BY increment_value;
Indexes
An index is a database object that improves the speed of data retrieval on a table by providing a faster
lookup method for specific columns. While it speeds up searches, it can also slow down insert, update,
or delete operations because the index must be maintained. Indexes are commonly created on columns
that are frequently used in WHERE clauses or joins.
Syntax:
CREATE INDEX index_name
ON table_name (column_name);
Synonyms
A synonym is an alias for another database object such as a table, view, or sequence. It simplifies access
to objects, especially when referencing objects in remote databases or with complex names. Synonyms
can make queries more readable and allow changes to underlying object names without impacting
dependent applications.
Syntax:
CREATE SYNONYM synonym_name
FOR object_name;
20CS2016L - Database Management
Systems Lab URK22CS3013
Questions:
1. Design a view that present a list of venues along with the cities.
2. Create a view that combines data from the user and Events tables to display the name of each user
along with the event names.
20CS2016L - Database Management
Systems Lab URK22CS3013
3. Build a view that shows a summary of the number of events in each venue.
6. Create a sequence that generates unique user IDs starting from 1001 and incrementing by 1 for each
new user added to the users table. Add 3 new records using the sequence.
8. Alter the sequence to increment by 10. Add 3 records to the users table using the sequence.
9. Create an index on the userid column of the users table and check the access time with userid in the
where clause.
Result:
The other database objects like views, sequence, indexes and synonyms are created successfully.