0% found this document useful (0 votes)
22 views

Practical 2 1.PDF.pdf

Uploaded by

atharvamble7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Practical 2 1.PDF.pdf

Uploaded by

atharvamble7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Name : Pranav Vijay Pisal

Subject : DBMSL
Class : TE COMP
Batch : T2
Roll no : 0031
Date Of Submission :
Remarks :
ASSIGNMENT 2

• Title : SQL Queries

• Date Of Completion :

• Problem Statement :

Design and Develop SQL DDL statements which demonstrate the use of SQL
objects such as Table, View, Index, Sequence, Synonym, different constraints
Write at least 10 SQL queries on the suitable database application using SQL
DML statements.
• Theory :

1. Table :
Various operations that can be performed on a table are
create,drop,delete,modify,alter,add column,add constraint.

2. View :

Views in SQL are a kind of virtual table. A view also has rows and
columns like tables, but a view doesn’t store data on the disk like a
table. A view defines a customized query that retrieves data from one
or more tables and represents the data as if it was coming from a
single source.

We can create a view by selecting fields from one or more tables


present in the database. A view can either have all the rows of a table
or specific rows based on certain conditions.
3.Sequence :
A sequence in SQL is a database object designed to generate a
sequence of unique numeric values, typically used to auto-generate
primary key values or unique identifiers. It provides a way to
automatically generate unique numbers in a sequential order.

4.Index :

An index in SQL is a database object that improves the speed of data


retrieval operations on a table at the cost of additional space and
potentially slower writes. Indexes work similarly to an index in a
book: they allow the database to quickly locate rows without having
to scan the entire table.

5.Synonym :

A synonym is an alternative name for a database object such as a


table, view, sequence, or stored procedure. It allows you to refer to an
object using a different name, which can be useful for simplifying
queries or providing backward compatibility.

• SQL Queries :

1.Create Table :

Syntax :

CREATE TABLE table_name

( column1 data_type constraints,

column2 data_type constraints,

... [table_constraints] );
Example :

CREATE TABLE IF NOT EXISTS Customer (

Customer_Id INT PRIMARY KEY,

Name VARCHAR(50),

Address VARCHAR(30),

Email VARCHAR(50) NOT NULL,

Register_Date DATE,

Phone_Number VARCHAR(15) NOT NULL,

UNIQUE (Phone_Number)

);

2.Create View

Syntax :

CREATE VIEW view_name AS

SELECT column1, column2, ...

FROM table_name

WHERE condition;

Example :

CREATE VIEW recent_customers AS

SELECT Customer_Id, Name, Email, Register_Date


FROM Customer

WHERE Register_Date > '2024-01-01';

3.Drop Table

Syntax :

DROP TABLE table_name;

Example :

DROP TABLE Customer;

4.Drop Column

Syntax :

DROP COLUMN column_name;

Example :

DROP COLUMN roll_no;

5.Truncate

Syntax :

TRUNCATE TABLE table_name;

Example :

TRUNCATE TABLE Menu;


6.Alter Command

Syntax:

ALTER TABLE table_name

ADD column_name data_type [constraints];

7.Create Index

CREATE INDEX index_name

ON table_name (column1, column2, ...);

Example :

CREATE UNIQUE INDEX idx_unique_phone

ON Customer (Phone_Number);

8.Create Synonyms :

Syntax :

CREATE SYNONYM synonym_name

FOR schema_name.object_name;

Example :

CREATE SYNONYM emp

FOR hr.employees;
9.Create Sequence

Syntax :

CREATE SEQUENCE sequence_name

[ INCREMENT BY increment_value ]

[ START WITH start_value ]

[ MAXVALUE max_value ]

[ MINVALUE min_value ]

[ CYCLE | NOCYCLE ]

[ CACHE cache_size | NOCACHE ];

Example :

CREATE SEQUENCE customer_seq

START WITH 1

INCREMENT BY 1;

10.Add a column

Syntax :

ALTER TABLE table_name

ADD column_name data_type [constraints];

Example :

ALTER TABLE employees

ADD birth_date DATE;


Conclusion :
In this practical, we explored several essential SQL concepts and operations
that are fundamental to effective database management. The exercises
provided a hands-on approach to understanding and implementing various SQL
objects and statements:

You might also like