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

Assign 1 DBMS

Uploaded by

PRATIK DAREKAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assign 1 DBMS

Uploaded by

PRATIK DAREKAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Batch: B2

Name : Jaideep Rajput


Roll No. - 222053
GR No. -21910250
Name: Pratik Darekar
Roll no. : 222052
Gr. No. : 21910953

Assignment No. 1

Aim :
Design and develop SQL DDL statements which demonstrates the use of SQL
objects such as Table, View, Index, Sequence, Synonym.

Theory :

DDL Statements
These are the SQL Statements used to define the database structure or
schema.
Ex :
Command Description
CREATE To create objects in database
ALTER To alter the structure of database
DROP To delete objects from database
TRUNCATE To remove all elements from table
RENAME To rename an object

1) CREATE :
Syntax : Create table table_name
(
Col_name datatype;

);

Ex : CREATE TABLE movies


(
title VARCHAR(100),
year VARCHAR(100),
director VARCHAR(50),
genre VARCHAR(20),
rating VARCHAR(100)
);

2) ALTER :
Syntax : Alter table table_name add( col_name datatype(size), …); Alter
table table_name modify( colname data type (size), … );

Ex :
ALTER TABLE movies DROP rating

3) DROP :

Syntax : Drop table table_name;

Ex : Drop table movies;


4) TRUNCATE :

Syntax : Truncate table table_name;

Ex : Truncate table movies;


5) RENAME :

Synatx : Rename table old_table_name to new_table_name;

Ex : Rename table students to VIIT_Students;

View :
View is simply a subset of table which are stored logically in a database
means a view is a virtual table in a database whose contents are defined by
query.

Syntax : (i) create view view_name as select query;


(ii) create or replace view_name as select query;

Ex: CREATE OR REPLACE VIEW 2008_movies as SELECT * FROM movies


WHERE year="2008"
Dropping a view :
Syntax :
Drop view view_name;
Index :
Indexes are used to access the data from the table in faster manner so that the
efficiency will be increase.
Consider following table :
Empno Ename Salary

R1 1010 Raj 55000


R2 2010 Mukesh 30000
R3 3010 Geeta 35000

In the above table if we retrieve data on the basis of salary it will take time
because it is not sorted so,in such cases we can apply index to the column.

Syntax : create index index_name on table_name (col_name asc | desc);


Ex: create index sal_index on employee (Salary asc);

Salary Row_Address
30000 R2
35000 R3
55000 R1

Sequence :
Sequence object generates a sequence of numeric values in ascending and
descending order. These values are often used to generate numbers for primary
or unique keys.

Syntax : create sequence seq_name


[starts with intval]
[increment by intval]
[maxvalue intval]
[minvalue intval]
[cycle/nocycle]

Pseudo Column in sequence :


a) CURRVAL : returns current value of sequence
b) NEXTVAL : returns next value of sequence

Ex : create sequence seq_rollno


minvalue 1
maxvalue 10
increment by 1
insert into students values(seq_rollno.nextval , ‘Jack’ ,’computer’);

Synonym :
In SQL we can provide temporary alternative name to table name or
column name. Synonym are referral to original objects.

Syntax : create Synonym syn_name for database_objects;

Ex :
create Synonym films for movies;

Creating synonym is not possible in mysql.

Conclusion :
Thus , In this way we have performed DDL statements which
demonstrates the use of SQL objects such as Table, View, Index, Sequence,
Synonym.

You might also like