Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Assignment No. 2-A Title

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

Database Management System TE Computer Engineering (2021-

Laboratory 22)

Assignment No. 2-a


Design and Develop SQL DDL statements which
Title demonstrate the use of SQL objects such as Table, View,
Index, Sequence,
Synonym
Roll No. 19123070
Class T.E. (C.E.)
Date
Subject Database Management System Laboratory

Signature

Page 1
Assignment No. 2
Title: Design and Develop SQL DDL statements which demonstrate the use of SQL objects
such as Table, View , Index, Sequence, Synonym

Objectives: To study SQL DDL statements

Theory: SQL – Structured Query Language

Data Definition in SQL


Creating Tables
Syntax:-
Create table<table name>
(colume_name 1 datatype size(),
colume_name 2 datatype size(),
….
colume_name n datatype size());

e.g. Create table student with the following fields(name,roll,class,branch)


Create table student
(name char(20),
Roll number(5),
Class char(10),
Branch char(15));
A table from a table
• Syntax :

CREATE TABLE <TableName> (<ColumnName>, <Columnname>) AS


SELECT <ColumnName>, <Columnname> FROM <TableName>;
- If the source table contains the records, then new table is also created with the same
records present in the source table.

• If you want only structure without records then select statement must have
condition. Syntax:

CREATE TABLE <TableName> (<ColumnName>, <Columnname>) AS


SELECT <ColumnName>, <Columnname> FROM <TableName> WHERE
1=2; (Or)

CREATE TABLE <TableName> (<ColumnName>, <Columnname>) AS


SELECT <ColumnName>, <Columnname> FROM <TableName> WHERE
ColumnName =NULL;
Constraints
The definition of a table may include the specification of integrity constraints. Basically
two types of constraints are provided: column constraints are associated with a single
column whereas table constraints are typically associated with more than one column. A
constraint can be named. It is advisable to name a constraint in order to get more
meaningful information when this constraint is violated due to, e.g., an insertion of a
tuple that violates the constraint. If no name is specified for the constraint, Oracle
automatically generates a name of the pattern SYS C<number>.Rules are enforced on
data being stored in a table, are called Constraints.

Both the Create table & Alter Table SQL can be used to write SQL sentences that
attach constraints.
Basically constraints are of three types
1) Domain
- Not Null
- Check
2) Entity
- Primary Key
- Unique
3) Referential
- Foreign key

4) Not Null:-Not null constraint can be applied at column level only.

We can define these constraints

1) at the time of table creation Syntax :

CREATE TABLE <tableName> (<ColumnName>


datatype(size) NOT NULL,
<ColumnName> datatype(size),….
);
2) After the table creation

ALTER TABLE <tableName> Modify(<ColumnName>


datatype(size) NOT NULL );
Check constraints
- Can be bound to column or a table using CREATE TABLE or ALTER TABLE
command.
Database Management System TE Computer Engineering (2021-
Laboratory 22)
- Checks are performed when write operation is performed .
- Insert or update statement causes the relevant check constraint.
- Ensures the integrity of the data in tables.
Syntax :
• Check constraints at column
level Syntax :
CREATE TABLE <tableName>
(<ColumnName>datatype(size)CHECK(columnName
condition),<columnname datatype(size));
CREATE TABLE <tableName>
(<ColumnName> datatype(size) CONSTRAINT <constraint_name>
CHECK (columnName condition),..
);
• Check constraints at table
level Syntax :
CREATE TABLE <tableName>
(<ColumnName> datatype(size),
<ColumnName> datatype(size),
CONSTRAINT <constraint_name> CHECK (columnName condition),..);
• Check constraints at table level
Syntax :

CREATE TABLE
<tableName>
(<ColumnName>
datatype(size),
<ColumnName> datatype(size),….,
CHECK (columnName condition));
After table creation
Alter table tablename
Add constraints constraintname ckeck(condition)
The PRIMARY KEY Constraint
A primary key is one or more column(s) in a table used to uniquely identify each row in
the table.
• A table can have only one primary key.
• Can not be left blank

Page 4
• Data must be UNIQUE.
• Not allows null values
• Not allows duplicate values.
• Unique index is created automatically if there is a primary
key. Primary key constraint defined at column level
Syntax:
CREATE TABLE <TableName>
(<ColumnName1> <DataType>(<Size>)PRIMARY
KEY,<columnname2
<datatype(<size>),…..);
• Primary key constraint defined at Table
level Syntax:
CREATE TABLE <TableName>
(<ColumnName1> <DataType>(<Size>) ,…,
PRIMARY
KEY(<ColumnName1> <ColumnName2>));
• key constraint defined at Table level
Syntax:
CREATE TABLE <TableName>
(<ColumnName1> <DataType>(<Size>) <columnname2
datatype<(size)<,<columnname3 datatype<size>constraint constraintname
PRIMARY KEY(<ColumnName1>));
After table creation
Alter table tablename
Add(constraint constraintname primary key(columnname));
The Unique Key Constraint

- The unique column constraint permits multiple entries of NULL into


the column.
- Unique key not allowed duplicate values
- Unique index is automatically created.
- Table can have more than one unique key.
• UNIQUE constraint defined at column
level Syntax :
Create table tablename(<columnname> <datatype>(<Size>
UNIQUE),<columnname> datatype(<size>)...............);
UNIQUE constraint defined at table
level Syntax :

CREATE TABLE tablename (<columnname> <datatype>(<Size>),


<columnname> <datatype>(<Size>), UNIQUE(<columnname>,
<columnname> ));

After table creation


Alter table tablename
Add constraint constraintname unique(columnname);
 The Foreign Key (Self Reference) Constraint Foreign key represents
relationships between tables.

A foreign key is a column( or group of columns) whose values are derived from
primary key or unique key of some other table.

Foreign key constraint defined at column


level Syntax:
<columnName> <DataType> (<size>) REFERENCES
<TableName>[(<ColumnName>)] [ON DELETE CASCADE]
• If the ON DELETE CASCADE option is set, a DELETE operation in
the master table will trigger a DELETE operation for corresponding
records in all detail tables.
• If the ON DELETE SET NULL option is set, a DELETE operation in the
master table will set the value held by the foreign key of the detail tables
to null.
Foreign key :
ALTER TABLE <child_tablename> ADD CONSTRAINT <constraint_name> FOREIGN
KEY (<columnname in child_table>) REFERENCES <parent table name>;
1) FOREIGN KEY constraint at table level

2) FOREIGN KEY constraint defined with ON DELETE CASCADE


FOREIGN KEY(<ColumnName>[,<columnname>]) REFERENCES
<TableName> [(<ColumnName>, <ColumnName>) ON DELETE
CASCADE

• FOREIGN KEY constraint defined with ON DELETE SET NULL


FOREIGN KEY(<ColumnName>[,<columnname>]) REFERENCES
<TableName> [(<ColumnName>, <ColumnName>) ON DELETE
SET NULL
• To view the
constraint Syntax:

Select constraint_name, constraint_type, search_condition from


user_constraints where table_name=<tablename>;
Select constraint_name, column_name from user_cons_columns
where table_name=<tablename>;

To drop the
constraints Syntax:-
Drop constraint constraintname;
Describe commands
To view the structure of the table created use the DESCRIBE command.The
command displays the column names and datatypes
Syntax:-
Desc[ribe]<table_name>
e.g desc student
Restrictions for creating a table:
1.Table names and column names must begin with a letter.
2.Table names and column names can be 1 to 30 characters long.

3.table names must contain only the characters A-Z,a-z,0-9,underscore_,$ and #


4.Table name should not be same as the name of another database object.
5.Table name must not be an ORACLE reserved word.
6.Column names should not be duplicate within a table definition.
Alteration of
TABLE:- Alter table
command Syntax:-
Case1:-
Alter table <table_name>
Add( colume_name 1 datatype size(),
colume_name 2 datatype size(),

colume_name n datatype size());


Database Management System TE Computer Engineering (2021-
Laboratory 22)

Case2:-
Alter table <table_name>
Modify(colume_name 1 datatype size(),
colume_name 2 datatype size(),
…...
colume_name n datatype size());

After you create a table, you may need to change the table structures because you need to have
a column definition needs to be changed. Alter table statement can be used for this purpose.
You can add columns to a table using the alter table statement with the ADD clause.

E.g. Suppose you want to add enroll_no in the student table then we write
Alter table student Add(enroll_no number(10));

You can modify existing column in a table by using the alter table statement with
modify clause.

E.g. Suppose you want to modify or chang the size of previously defined field name in
the student table then we write

Alter table student modify(name


char(25)); Dropping a column from a table
Syntax :
ALTER TABLE <Tablename> DROP COLUMN <ColumnName> ;

Drop table command Syntax:-


Drop table <table_name>

Drop table command remnoves the definitions of an oracle table.When you drop a table
,the database loses all the data in the table and all the indexes associated with it.
e.g drop table student;
Truncate table
command Syntax:-
Trunc table<table_name>

The truncate table statement is used to remove all rows from a table and to release the storage
space used by the table.
e.g.Trunc table student;

Rename table
command Syntax:-

Page 8
Rename<oldtable_name> to<newtable_name>

Rename statement is used to rename a table,view,sequence,or synonym. e.g.


Rename student to stud;
Database objects:-
Index
An index is a schema object that can speed up retrieval of rows by using pointer. An index
provides direct & fast access to rows in a table. Index can be created explicitly or automatically.

Automatically :- A unique index is created automatically when you define a primary key or
unique key constraint in a table definition.

Manually :- users can create non unique indexes or columns to speed up access time to the rows.
Syntax:
Create index<index_name> On table(column[ , column]…);
Eg. Create index emp_ename_idx On emp(ename);
When to create an index
a) The column is used frequently in the WHERE clause or in a join condition.
b) The column contains a wide range of values.
c) The column contains a large number of values.
To display created index of a

table eg.

Select ic.index_name, ic.column_name, ic.colun_position col_pos, ix.uniqueness from


user_indexes ix, user_ind_columns ic where ic.index_name=ix.index_name
and ic.table_name=‟emp‟;

Removing an Index
Syntax:-
Drop index <index_name>; eg. Drop
index emp_name_idx;
Note: 1) we cannot modify indexes.
2) To change an index, we must drop it and the re-create it.
Views
View is a logical representation of subsets of data from one or more tables. A view takes the
output of a query and treats it as a table therefore view can be called as stored query or a
virtual table.The tables upon which a view is based are called base tables. In Oracle the SQL
command to create a view (virtual table) has the form
Create [or replace] view <view-name> [(<column(s)>)] as
<select-statement> [with check option [constraint <name>]];

The optional clause or replace re-creates the view if it already exists. <column(s)> names the
columns of the view. If <column(s)> is not specified in the view definition, the columns of
the view get the same names as the attributes listed in the select statement (if possible).
Example: The following view contains the name, job title and the annual salary of
employees working in the department 20:
Create view DEPT20 as
select ENAME, JOB, SAL 12 ANNUAL SALARY from EMP where DEPTNO = 20;

In the select statement the column alias ANNUAL SALARY is specified for the expression
SAL∗12 and this alias is taken by the view. An alternative formulation of the above view
definition is
Create view DEPT20 (ENAME, JOB, ANNUAL SALARY) as select ENAME, JOB, SAL
12 from EMP where DEPTNO = 20;

A view can be used in the same way as a table, that is, rows can be retrieved from a view(also
respective rows are not physically stored, but derived on basis of the select statement inthe view
definition), or rows can even be modified. A view is evaluated again each time it is accessed. In
Oracle SQL no insert, update, or delete modifications on views are allowed
that use one of the following constructs in the view definition:
• Joins
• Aggregate function such as sum, min, max etc.
• set-valued subqueries (in, any, all) or test for existence (exists)
• group by clause or distinct clause

In combination with the clause with check option any update or insertion of a row into the view
is rejected if the new/modified row does not meet the view definition, i.e., these rows would not
be selected based on the select statement. A with check option can be named using the
constraint clause.

A view can be deleted using the command delete <view-name>. To


describe the structure of a view
e.g. Describe stud;

To display the contents of view e.g. Select * from stud


Removing a view:
Syntax:- Drop view <view_name>
e.g. Drop view stud
Sequence:
A sequence is a database object, which can generate unique, sequential integer values. It can be
used to automatically generate primary key or unique key values. A sequence can be either in
an ascending or descending order.
Syntax :
Create
sequence<sequence_name>
[increment by n]
[start with n]
[{maxvalue n |
nomaxvalue}] [{minvalue n|
nominvalue}] [{cycle |
nocycle}]
[{cache n| nocache}];
Increment by n Specifies the interval between
sequence number where n is an
integer. If this clause is omitted, the
sequence is increment by 1.
Start with n Specifies the first sequence number to
be generated. If this clause is omitted
,
the sequence is start with 1.
Maxvalue n Specifies the maximum value, the
sequence can generate
Nomax value n Specifies the maximum value of
10e27-1 for an ascending sequence &
- 1 for descending sequence. This is a
default option.
Minvalue n Specifies the minimum sequence
value.
Nominvalue n Specifies the minimum value of 1 for
an ascending & 10e26-1 for
descending sequence. This is a
default
option.
Cycle Specifies that the sequence continues
to generate values from the beginning
after reaching either its max or min
value.
Nocycle Specifies that the sequence can not
generate more values after reaching
either its max or min value. This is
a
default option.
Cache / nocache Specifies how many values the
oracle server will preallocate & keep
in memory. By default, the oracle
server
will cache 20 values.

After creating a sequence we can access its values with the help of pseudo
columns like curval & nextval.
Nextval : nextval returns initial value of the sequence when reference to for the
first time. Last references to the nextval will increment the sequence using the
increment by clause & returns the new value.
Curval : curval returns the current value of the sequence which is the value
returned by the last reference to last value.
Modifyning a sequence:
The sequence can be modified when we want to perform the following :
□ 
 Set or eliminate minvalue or maxvalue
□ 


Change the increment value.

Change the number of cache sequence number.


 Syntax :

Alter sequenc e <sequence_name>


 [increment by n]  

 [start with n]
[{maxvalue n | nomaxvalue}]
[{minvalue n| nominvalue}]

 [{cycle | nocycle}] 
[{cache n| nocache}];

Synonym:
A synonym is a database object,which is used as an alias(alternative name)for a
table,view or sequence.
Syntax:-

Create[public]synonym
<synonym_name>for<table_name>;
In the
syntax

Public:-Creates a synonym accessible to all users.


Synonym:-Is the name of the synonym to be
created.

Synonym can either be private or public.A private synonym is created by normal


user,which is available to that persons.

A public synonym is created by a database administrator(DBA),which can be availed by


any other database user.
Uses:-
1.Simplify SQL statements.

2.Hide the name and owner of an


object. 3.Provide public access to an
object.
Guidelines:-

1.User can do all DML manipulations such as insert ,delete,update on synonym.


2.User cannot perform any DDL operations on the synonym except dropping the
synonym.
3.All the manipulations on it actually affect the table
e.g Create synonym stud1 for student;

SQL, pronounced SEQUEL, is the standard language to access relational databases.SQL is an


abbreviation for Structured Query Language. I'll just add that SQL is composed of DML and
DDL. DML are the keywords you use to access and manipulate data, hence the name
DataManipulation Language. DDL are the keywords you use to create objects such as views,
tables and procedures, hence the name Data Definition Language.

Tables
In relational database systems (DBS) data are represented using tables (relations). A query issued
against the DBS also results in a table. A table has the following structure:

Column 1 Column 2 ... Column n Attributes

← Tuple Record)
(or

………. ………. ………. ………..


A table is uniquely identified by its name and consists of rows that contain the stored
information, each row containing exactly one tuple (or record). A table can have one or more
columns.
Database Management System TE Computer Engineering (2021-
Laboratory 22)
A column is made up of a column name and a data type, and it describes an attribute of the
tuples. The structure of a table, also called relation schema, thus is defined by its attributes.The
type of information to be stored in a table is defined by the data types of the attributes at table
creation time.SQL uses the terms table, row, and column for relation, tuple, and attribute,
respectively.
A table can have up to 254 columns which may have di fferent or same data types and sets of
values (domains), respectively. Possible domains are alphanumeric data (strings), numbers and
date formats.

Max
Max Max PL/SQL
Size: Max Size:
Datatype Description Size: Size: Subtypes/
Oracle Oracle 9
Oracle 7 8 PL/SQL Synonyms
Variable length
character string
having 2000 4000 32767
STRING
VARCHAR2(s maximum bytes bytes 4000 bytes bytes
VARCHA
ize) length size minimum minimu minimum is 1 minimum
R
bytes. is 1 m is 1 is 1
You must
specify size
Variable length
national
character set
4000 32767
string having STRING
NVARCHAR2 bytes 4000 bytes bytes
maximum N/A VARCHA
(size) minimu minimum is 1 minimum
length size R
m is 1 is 1
bytes.
You must
specify size
Now deprecated
- VARCHAR is
a synonym for
VARCHAR VARCHAR2 - - -
but this usage
may change in
future versions.
Fixed length
character data of 2000 32767
length size 255 bytes
bytes bytes
bytes. This Default 2000 bytes
Default Default
and Default and CHARAC
CHAR(size) should be used and and
minimum minimum size TER
for fixed length minimu minimum
data. Such as size is 1 is 1 byte.
m size is size is 1
codes A100, byte.
1 byte. byte.
B102...
Fixed length 2000 2000 bytes 32767
NCHAR
national N/A bytes Default and bytes
(size)
character set Default minimum size Default

Page 16
data of length and is 1 byte. and
size bytes. This minimu minimum
should be used m size is size is 1
for fixed length 1 byte. byte.
data. Such as
codes A100,
B102...
Magnitud
e
1E-130 ..
10E125

maximum
precision
fixed-point
of 126
numbers:
binary
DEC
digits,
DECIMAL
which is
NUMERIC
roughly
equivalen
floating-
t to 38
The point:
decimal
The precisio DOUBLE
digits
precision n p can PRECISIO
The precision The scale
p can range N FLOAT
p can range s can
range from 1 binary_dou
from 1 to 38. range
Number having from 1 to to 38. ble
from -84
NUMBER(p,s) precision p and 38. binary_floa
The scale s to 127.
scale s. The scale The scale t
can range For
s can s can
from -84 to floating
range range integers:
127. point
from -84 from -84 INTEGER
don't
to 127. to 127. INT
specify
SMALLIN
p,s
T
REAL
simple_inte
has a
ger(10g)
maximum
precision
BOOLEA
of 63
N
binary
REAL
digits,
which is
roughly
equivalen
t to 18
decimal
digits
signed integers magnitud
PLS_INTEGE PLS_INTEGER PL/SQL PL/SQL e range is
PL/SQL only
R values require only only -
less storage and 21474836
provide better 47 ..
performance 21474836
than NUMBER 47
values.
So use
PLS_INTEGER
where you can!
NATURA
magnitud L
signed integers e range is NATURA
(older slower - LN
BINARY_INT
version of 21474836 POSITIVE
EGER
PLS_INTEGER 47 .. POSITIVE
) 21474836 N
47 SIGNTYP
E
32760
bytes Note
Character data this is
of variable smalller
2 2 Gigabytes -
length (A bigger 2 than the
LONG Gigabyt but now
version the Gigabytes maximum
es deprecated
VARCHAR2 width of a
datatype) LONG
column

from
from January 1,
from
January 4712 BC
January 1,
1, 4712 from January to
4712 BC
BC to 1, 4712 BC to December
DATE Valid date range to
Decemb December 31, 31, 9999
December
er 31, 9999 AD. AD.
31, 4712
9999 (in
AD.
AD. Oracle7 =
4712 AD)
Accepted
the number of
TIMESTAMP values of
digits in the
(fractional_sec fractional_sec
fractional part of - -
onds_precision onds_precisio
the SECOND
) n are 0 to 9.
datetime field. (default = 6)
TIMESTAMP Accepted
(fractional_sec As above with values of
onds_precision time zone fractional_sec
- -
) WITH displacement onds_precisio
{LOCAL} value n are 0 to 9.
TIMEZONE (default = 6)
INTERVAL Time in years - - Accepted
Database Management System TE Computer Engineering (2021-
Laboratory 22)
YEAR and months, values are 0 to
(year_precision where 9. (default =
) TO MONTH year_precision 2)
is the number of
digits in the
YEAR datetime
field.
Time in days,
hours, minutes,
and seconds.
day_precision
INTERVAL day_precision is may be 0 to 9.
DAY the maximum (default = 2)
(day_precision) number of digits
TO SECOND in 'DAY' - - fractional_sec
(fractional_sec onds_precisio
onds_precision fractional_secon n may be 0 to
) ds_precision is 9. (default =
the max number 6)
of fractional
digits in the
SECOND field.
Raw binary data
of length size Maximu
Maximum Maximum
bytes. m size is 32767
RAW(size) size is 255 size is 2000
You must 2000 bytes
bytes. bytes
specify size for bytes
a RAW value.
32760
bytes Note
this is
Raw binary data smalller
of variable 2 2 2 Gigabytes - than the
LONG RAW length. (not Gigabytes Gigabyt but now maximum
intrepreted by . es. deprecated width of a
PL/SQL) LONG
RAW
column

Hexadeci
Hexadecimal
mal string
string
representi
representing the
ng the
unique address
unique
of a row in its
ROWID 8 bytes 10 bytes 10 bytes address of
table. (primarily
a row in
for values
its table.
returned by the
(primarily
ROWID
for values
pseudocolumn.) returned

Page 19
by the
ROWID
pseudocol
umn.)
universal
rowid -
UROWID
Hex string
representi
ng the
logical
The See
Hex string address of
maximu CHARTO
representing the The maximum a row of
m size ROWID
logical address size and defaultan index-
N/A and and the
of a row of an is 4000 bytes organized
default is package:
index-organized table,
4000 DBMS_R
table either
bytes OWID
physical,
logical, or
foreign
(non-
Oracle)

Binary format of
an operating
system
MLSLABEL label.This
datatype is used
with Trusted
Oracle7.
Character Large 4Gigabyte 4Gigaby 4Gigabyt
CLOB Object s tes 4Gigabytes es
National
Character Large 4Gigaby 4Gigabyt
NCLOB 4Gigabytes
Object tes es
Binary Large 4Gigaby 4Gigabyt
BLOB 4Gigabytes
Object tes es
The size
of a
BFILE is
system
dependent
pointer to binary 4Gigaby but cannot
BFILE 4Gigabytes
file on disk tes exceed
four
gigabytes
(2**32 -
1 bytes).
Populate
with
XML
from a
CLOB or
VARCH
XMLType XML data - - 4Gigabytes AR2.

or query
from
another
XMLTyp
e column.

Conclusion: Thus we have studied how to use SQL DDL Statements.

FAQ : Consider relational schema


• TRAIN(Train_no,Name,Seat_Sleeper,Seat_first_class_Ac,Seat_second_class_Ac,
Seat_third_class_Ac,wifi, food, Run_on_Sunday, Run_on_Manday,
Run_on_Tuesday, Run_on_Wednesday, Run_on_Thursday, Run_on_Friday,
Run_on_Saturday)
• PASSENGER(Passenger_id,First_Name,Last_Name, gender,Phone_no,
Ticket_no,Age,class),
• STATION (Station_code, Station_Name)
• STOPPAGE (Train_no,Station_code,Arrival_time,Departure_time)
• TICKET (Ticket_no, Train_no,Date_of_journey,Username)
• ACCOUNT (Username, Password,Email_id,address)
• CONTACT (Username, Phone_no)

Develop SQL DDL statements.

1.Create tables ;

create table account (username varchar (20) PRIMARY KEY, password varchar (20) NOT NULL,
email_id varchar (30) NOT NULL, address varchar (40) NOT NULL);
2.Insert values in tables.
insert into Account values(‘Ajit’,’Ajit222’,’Ajit@gmail.com’,’Goa’);
insert into Account values(‘Akash’,’Akash678’,’Akash@gmail.com’,’Chennai’);
insert into Account values(‘Amit’,’Amit’,’Amit@gmail.com’,’Bhopal’);
insert into Account values(‘Alisha’,’Alish555,’Alisha@gmail.com’,’Pune’);
insert into Account values(‘Chaitanya’,’Chaitanya111,’Chaitanya@gmail.com’,’Banglore);
insert into Account values(‘Swapnil’,’Swapnil123’,’Swapnil@gmail.com’,’Delhi’);
insert into Account values(‘Smith’,’Smith123’,’Smith@gmail.com’,’Mumbai’);

3.Add a new attribute in s record using alter statement.


alter table Account ADD Date_Of_Birth date;

4.Drop attribute from table.


alter table Account drop column Date_Of_Birth;
5.Update with where constraint;
update table Account set address = ‘Pune’ where username = ‘Ajit’;

6.Delete from account record of account whose name is Ajit;


delete from Account where username = ‘Ajit’;
7.Create view for table;
create view Account_view AS SELECT username,password,email_id from Account;

8.Create index on train no in train table.


create INDEX train_ind on train(Train_No);

9.Create sequence on train/account table.

CREATE SEQUENCE User_seq


START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;
10.Create synonym on table.

CREATE SYNONYM Users


FOR Account;
Mini Project –
BUS RESERVATION SYSTEM
Team Members –
1. Jamnerkar Chaitanya - 19123072
2. Vibhute Akash - 19123071
3. Dhavale Alisha - 19123070

1.Create tables ;

create table conductor (Conductor_ID int(5) PRIMARY KEY, First_Name varchar(20), Last_Name
varchar(20));

2.Insert values in tables.


insert into Account values(123,’Suresh’,’Gill’);
insert into Account values(124,’Ramesh’,’Patil’);
insert into Account values(125,’Mahesh’,’Singh’);

3.Add a new attribute in s record using alter statement.


alter table conductor ADD Gender char(1);
4.Drop attribute from table.
alter table conductor drop column Gender;

5.Update with where constraint;


update conductor set Last_Name='Kumar' where Conductor_ID=125;

6.Delete from account record of account whose name is Suresh;


delete from conductor where First_Name='Suresh';
7.Create view for table;
create view Conductor_view AS SELECT First_Name, Last_Name from conductor;

8.Create index on train no in train table.


create INDEX conductor_ind on conductor(Conductor_ID);

9.Create sequence on table.

CREATE SEQUENCE User_seq


START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;
10.Create synonym on table.

CREATE SYNONYM Users


FOR Conductor;

You might also like