0% found this document useful (0 votes)
45 views15 pages

Prectical 1

1) The document discusses various SQL DDL commands like CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE TABLE, and RENAME TABLE. It provides syntax and examples of using each command. 2) Several tables are created with different data types in the examples to demonstrate the DDL commands. Columns are added and modified using ALTER TABLE and tables are renamed, structured details are shown, and tables are dropped in the examples. 3) The document concludes by stating that various SQL DDL commands have been performed through examples to create, modify and delete database tables as part of an SQL lab practical.

Uploaded by

shivsaicable67
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)
45 views15 pages

Prectical 1

1) The document discusses various SQL DDL commands like CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE TABLE, and RENAME TABLE. It provides syntax and examples of using each command. 2) Several tables are created with different data types in the examples to demonstrate the DDL commands. Columns are added and modified using ALTER TABLE and tables are renamed, structured details are shown, and tables are dropped in the examples. 3) The document concludes by stating that various SQL DDL commands have been performed through examples to create, modify and delete database tables as part of an SQL lab practical.

Uploaded by

shivsaicable67
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/ 15

RDBMSPRACTICAL: 1 ENROLLMENTNO:226010307005

PRACTICALNO:01
AIM:ImplementSQLqueriestoperformvariousDDLCommands.(Createminimum5tabl
eswithdifferent datatypesandoperateuponthem) [04– Hours]

Proposition1:SQL-StructuredQueryLanguage:

SQLisadatabaselanguageusedformanipulationofdatainarelationaldatabase.

Proposition2:DDL -DataDefinitionLanguage:

DDLcommandsaretheSQLcommandusedtocreate,alter,drop,truncatedifferentdatabaseobjectsinan
ORACLEdatabase.

Proposition3:DatabaseObjects: TherearedifferentDatabaseobjects:

TABLE/ENTITY:Tableisadatabaseobjectthatholdsdataintheformofrowsandcolumns.Itisreprese
ntedbysetofattributes.

ATTRIBUTE:Attributesaredescriptivepropertypossessedbyeachmemberofentityset.

DOMAIN:Setofsamevalueinacolumniscalleddomain.

PRIMARYKEY:Anattributewhichuniquelydefinestherecord.

TUPLE:Itisasinglerow/recordofatable.

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page1
RDBMSPRACTICAL: 1 ENROLLMENTNO:226010307005

Proposition4: OracleDataTypes:

DataType Description
Char The char datatype is used when fixed length character string is required. It can
storealphanumericvalues.Thecolumnlengthofsuchadatatypecanvarybetween
1-2000bytes.Bydefaultitisonebyte.
Iftheuserentersavalueshorterthanthespecifiedlengththenthedatabaseblank-
padstothefixedlength.

Varchar2 The varchar2 datatype supports avariable length character string. It also
storesalphanumeric values. The size for this datatype ranges from 1 - 4000 bytes.
Usingvarchar2savesdiskspacewhencomparedtochar.Thisstatement
canbejustifiedwiththehelpofanexample.

Long This datatype is used to store variable character length. Maximum size is
2GB.Longdatatypehasseveralcharacterssimilartovarchar2datatype.

Number TheNumberdatatypecanstorepositivenumbers,negativenumber,zeroes,fixed
pointnumber,andfloatingpointnumberswithaprecisionof38.

Date Date datatype is used to store date and time in a table. Oracle database makes use
ofitsownformat tostoredateinafixedlengthof7byteseachforcentury,
month,day,year,hour,minuteandsecond.

Proposition5:
DDLCommands
1. CREATETABLE. 2. ALTERTABLE.
3. DROP 4. TRUNCATETABLE. 5.
TABLE.RENA
ME

CREATETABLECOMMAND:
Syntax:
createtable<table_name>(
column_name1 datatype(size),
column_name2 datatype(size),
: : :
: : :
: : :
column_namen datatype(size)
);

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page2
RDBMSPRACTICAL: 1 ENROLLMENTNO:226010307005

ALTERTABLECOMMAND:

Itisusedtoaddnewattributesortomodifytheexistingattributeinthetable.

SYNTAX:

CASE1:[ADDNEWCOLUMN]
altertable<table_name>

add(column_name1datatype(size), column_name2datatype(size),

: : :

: : :

column_namendatatype(size));

CASE -2:[COLUMNSIZEMODIFYCLAUSE]
altertable<table_name>

modify(column_name1datatype(size), column_name2datatype(size),

: : :

: : :

column_namendatatype(size));

ALTERTABLEcommandcanbe used for


addingcolumnstoatablewithaddclauseortochangethecolumnwithmodifyclause.

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page3
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

ALTERTABLEcommandcanbeusedforaddingcolumnstoatablewithaddcla
useortochangethecolumnwithmodifyclause.

TRUNCATETABLECOMMAND:

Thetruncatetablecommandisusedtoremoveallrowsfromatableandtoreleasethestorage
spaceusedbythetablekeepingthetabledefinitionintact.

Syntax:

truncatetable<table_name>;R

ENAMETABLECOMMAND:

Renamestatementisusedtorenameatable,view,sequence,orasynon
ym.Syntax:

Rename<oldtable_name>to<newtable_name>;

DROPTABLECOMMAND:

Thedroptablecommandremovesthedataaswellasdefinition(structure)
of an Oracle table. When you drop a table, the database loses
allthedatainthetableandalltheindexesassociatedwithit.

Syntax: droptable<table_name>;

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page4
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

SAMPLEEXAMPLES:C

REATETABLE:

TocreateatableSTUDENT_INFOwiththecolumnstud_id,stud_name,dat
e_of_birth,city,activity,leader,ssc_per,branch_name,ent_grade.

ForExample:
createtableSTUDENT_INFO22005
(
stud_idnumber(4),
stud_namevarchar2(15),
DOBdate,
Cityvarchar2(10),
activityvarchar2(10),
leadernumber(4),
ssc_pernumber(4,2),
branch_codechar(2),
ent_gradechar(2)
);
TheaboveSQLstatementwillcreateatableSTUDENT_INFOwiththegivencolumn
s.
ForExample:
descSTUDENT_INFO22005;

OUTPUT:

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page5
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

ALTERTABLE:

Toaddnewattributesemail_idtothetableSTUDENT_INFO:
ForExample:
alter table STUDENT_INFO22005

add(email_idvarchar2(12));

output :

To modifythe lengthofstud_namefieldto12
intheSTUDENT_INFOtable:ForExample:
alter tableSTUDENT_INFO22005modify(stud_name varchar2(12));
OUTPUT:
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page6
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

SYNTAX:desctemp:
ForExample:
createtabletempasselect*fromSTUDENT_INFO
createtabletempasselect*fromSTUDENT_INFO22005;
OUTPUT:

RENAME:

TochangethenameofthetableSTUDENT_INFOtoSTUD_INFO:ForE

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page7
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

xample:
renameSTUDENT_INFO22005toSTUD_INFO7005;

OUTPUT:

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page8
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

DropTable:
ForExample:
droptabletemp;
OUTPUT:

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page9
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

QUESTIONS:(STUDENTASSIGNEMENT)

1. Createatablelab_datawiththefollowingattributes:
Column DataType
Item_code char(5)
Item_name varchar2(20)
Quantity number(3)
Make varchar2(10)

2. Addnewattributestatuswithdatatypechar(15)toabovetable.
3. Createatablebranch_detailsforthefollowing:
Column DataType
Branch_code char(3)
Branch_name varchar2(10)
Location char(6)
Fees Number(7,2)
4. Modifythewidthofbranch_nameto20forabovetable.
5. CreateatableBook_detailsforthefollowing
Column Datatype
Book_id number(5)
Title varchar2(20)
Author varchar2(20)
Publication varchar2(20)

6. AddnewattributeQuantityinthetableBook_details.
7. CreateatableAccountforthefollowing:

Column DataType
Account_id number(5)
Balance number(6,2)

8. RenamethetableAccounttoBank_Account.

9. GivestructuredetailsoftableBank_Account.

10. RemovethetabledefinitionofBank_Account.
ANSWER1:-

OUTPUT:

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page1
0
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

ANSWER2:-

OUTPUT:

ANSWER3:-

OUTPUT:

ANSWER4:

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page11
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

OUTPUT:

ANSWER5:-

OUTPUT:

ANSWER6:-

OUTPUT:

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page12
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

ANSWER7:-

OUTPUT:

ANSWER8:-

OUTPUT:

ANSWER9:-

OUTPUT:

ANSWER 10:-

OUTPUT:

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page13
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

CONCLUSION:HenceWePerformedVariousTypesOfDDL

CommandsInSQLQueriesByVariousExample

ProgressiveAssessmentSheetasperRubrics
RegularA LevelofUn
Attendance Presentation Total
ssessment derstanding

Sign:
Date:

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page14
RDBMSPRACTICAL: 1 ENROLLMENTNO:216010307005

A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page15

You might also like