Professional Documents
Culture Documents
DBMS Lab Manual PDF
DBMS Lab Manual PDF
DBMS Lab Manual PDF
Upon successful completion of this Lab the student will be able to:
AIM:
To create a DDL to perform creation of table, alter, modify and drop column.
CREATION OF TABLE:
SYNTAX:
EXAMPLE:
Table created.
1 row created.
1 row created.
OUTPUT:
Table created.
1 row created.
SYNTAX:
EXAMPLE:
OUTPUT:
ID NAME GAME
1 Mercy Cricket
SYNTAX:
EXAMPLE:
OUTPUT:
MODIFY
desc student;
DROP:
EXAMPLE:
SQL>Table dropped.
RESULT:
1. The Create Table Command: - it defines each column of the table uniquely. Each column has
minimum of three attributes, a name , data type and size.
Syntax:
Create table <table name> (<col1> <datatype>(<size>),<col2>
<datatype><size>));
Ex:
create table emp(empno number(4) primary key, ename char(10));
2. Modifying the structure of tables.
a) Add new columns
Syntax:
Alter table <tablename> add(<new col><datatype(size),<new
col>datatype(size));
Ex:
alter table emp add(sal number(7,2));
Syntax:
Alter table <tablename> drop column <col>;
7. Destroying tables.
Syntax:
Drop table <tablename>;
Ex:
drop table emp;
DML COMMANDS
AIM:
To create a view for the purpose of display in order to hide the data.
VIEW:
A view is a logical data table that allows us to view data from other tables and values.
TABLE:
SPOID GAME
1 Cricket
2 Basketball
4 Tennis
QUERIES:
OUTPUT:
View created.
OUTPUT:
DROP VIEW:
To remove a view from the database, one has to use drop view.
view dropped;
RESULT:
1. Inserting Data into Tables: - once a table is created the most natural thing to do is load this
table with data to be manipulated later.
Syntax:
insert into <tablename> (<col1>,<col2>) values(<exp>,<exp>);
2. Delete operations.
b) unique constraint
Syntax:
Unique constraint at column level.
<col><datatype>(size)unique;
h) Check constraint
check constraint constraint at column level.
Syntax: <col><datatype>(size) check(<logical expression>)
The grant statement provides various types of access to database objects such as tables, views and
sequences and so on.
Syntax:
GRANT <object privileges>
ON <objectname>
TO<username>
[WITH GRANT OPTION];
Syntax:
REVOKE<object privilege> ON FROM<user name>;
Result:
Thus the DCL commands have been successfully executed and the results are verified.
AIM:
QUERY:
CHARACTER FUNCTIONS:
SYNTAX:
ascii (string)
OUTPUT:
ASCII(‘A’)
65
INSTR:
SYNTAX:
i) instr(string/column name,x)
OUTPUT:
POSITION
2
POSITION
2
LENGTH:
SYNTAX:
i) length(string)
OUTPUT:
LENGTH(‘INDIA’)
5
OUTPUT:
LENGTH(NAME)
3
4
6
LPAD:
It pads the leading space to the left side of the column and fill with given character to the total
width of n.
SYNTAX:
i) lpad(char1,n,[,char2])
OUTPUT:
LPAD(‘ABC’)
*******ABC
OUTPUT:
LPAD(DEPTNAME,10,’*’)
*****sales
***account
****manager
CONCAT:
SYNTAX:
i) concat(x1,x2)
OUTPUT:
CONCAT(‘GOOD’,’EVENING’)
Goodevening
OUTPUT:
CHR:
SYNTAX:
i) chr(x)
OUTPUT:
CHR(‘97’)
a
OUTPUT:
CHR(DEPTNO)
e
f
g
RPAD:
It pads the leading space to the right side of the column and fills with blank space to the width
of n.
i) rpad(char1,n,[,char2])
OUTPUT:
RPAD(‘ABC’)
abc*******
OUTPUT:
RPAD(DEPTN AME,10,’*’)
Sales*****
Account***
Manager****
LTRIM:
It removes the leading occurrences of that character from the string from left side position.
SYNTAX:
i) ltrim(string[,char(s)])
OUTPUT:
LTRIM(‘ABC’,’A’)
bc
OUTPUT:
LTRIM(DEPTNAME,’A’)
Sales
ccount
Manager
RTRIM:
It removes the leading occurrences of the character from the string from right side position.
SYNTAX:
i) rtrim(string,[,char(s)])
OUTPUT:
RTRIM(‘ABC’,’A’)
ab
OUTPUT:
RTRIM(DEPTNAME,’T’)
Sales
Accoun
Manager
REPLACE:
It replaces the character c2 with a given string c3 and returns the character c1.
SYNTAX:
OUTPUT:
REPLACE(‘MADURAI’)
ijdurai
OUTPUT:
REPLACE(DEPTNAME,’A’,’C’)
Scles
ccount
Mcncger
SUBSTRING:
It returns the substring from string z, the length equal to y starting at position x.
SYNTAX:
i) substr(z,x[,y])
OUTPUT:
SUBSTR(MADURAI)
adur
OUTPUT:
SUBSTR(DEPTNAME)
le
co
na
NUMERIC FUNCTIONS:
ABS:
SYNTAX:
abs(x)
OUTPUT:
ABS(-8)
8
OUTPUT: ABS(DEPTNO)
101
102
103
SIN:
SYNTAX:
sin(x)
OUTPUT:
SIN(45)
.850903525
OUTPUT:
SIN(DEPTNO)
.452025787
.994826791
.622988631
COS:
SYNTAX:
cos(x)
OUTPUT:
COS(60)
-.95241298
OUTPUT:
MOD:
SYNTAX:
mod(x,y)
OUTPUT:
OUTPUT:
MOD
1
0
1
POWER:
SYNTAX:
power(x,y)
OUTPUT:
OUTPUT:
POWER
10201
10404
10609
EXP:
SYNTAX:
exp(x)
OUTPUT:
EXP(5)
148.413159
OUTPUT:
EXP(DEPTNO)
SQRT:
SYNTAX:
sqrt(x)
OUTPUT:
square_root
8
OUTPUT:
SQUARE_ROOT(DEPTNO)
10.0498756
10.0995049
10.1488916
TRUNC:
SYNTAX:
OUTPUT:
OUTPUT:
TRUNC(DEPTNO,3)
101
102
103
RESULT:
PL/SQL
declare
n number(10);
i number(10);
m number(10);
f number(10):=0;
begin
n:=&n;
m:=n;
for i in 2..m/2
loop
f:=f+1;
end if;
end loop;
if(f=0) then
else
prime');
end if;
OUTPUT:
RESULT:
PROGRAM:
declare
n number(10);
m number(10);
s number(10);
r number(10);
begin
n:=&n;
m:=n;
s:=0;
while(n>0)
loop
s:=(s*10)+r;
n:=floor(n/10);
end loop;
if(m=s) then
palindrome');
palindrome');
end if;
end;
OUTPUT:
RESULT:
TABLE:
Table created.
PROGRAM:
declare
veno emp5.empno%type:=&empno;
vename emp5.ename%type:='&ename';
vdeptno emp5.deptno%type;
begin
Cs2258 DBMS LAB MANUAL CSE DEPARMENT JCET Page 30
select empno,ename,deptno into veno,vename,vdeptno from
dbms_output.put_line('deptno is '||vdeptno);
exception
end;
OUTPUT:
deptno is1
no records found
RESULT:
PROGRAM:
declare
a number(3);
begin
a:=&a;
a:=a/0;
exception
end;
OUTPUT:
RESULT:
TABLE:
Table created.
PROGRAM:
declare
veno emp5.empno%type:=&empno;
vename emp5.ename%type:='&ename';
vdeptno emp5.deptno%type;
begin
dbms_output.put_line('deptno is '||vdeptno);
exception
dbms_output.put_line('error');
end;
OUTPUT:
deptno is 1
eno is 101
ename is aaa
error
RESULT:
TABLE:
Table created.
PROGRAM:
declare
vsal emp7.sal%type:=4000;
vcomm emp7.comm%type:=2000;
invalid_commission exception;
begin
if vcomm<vsal then
else
raise invalid_commission;
end if;
end;
OUTPUT:
TABLE:
Table created.
PROGRAM:
declare
begin
for i in cur
loop
if i.years<=2 then
where accno=i.accno;
else
accno=i.accno;
end if;
end loop;
end;
OUTPUT:
RESULT:
TABLE:
Table created.
PROGRAM:
declare
begin
for i in cur
loop
if i.units<=100 then
ebno=i.ebno;
ebno=i.ebno;
else
ebno=i.ebno;
end if;
end loop;
end;
OUTPUT:
RESULT:
TABLE:
Table created.
PROGRAM:
declare
x stu11.regno%type;
a stu11.mark1%type;
b stu11.mark2%type;
f stu11.mark3%type;
d stu11.mark4%type;
e stu11.mark5%type;
t stu11.tot%type;
v stu11.avg%type;
begin
loop
dbms_output.put_line('Rollno:'||x);
dbms_output.put_line('mark1:'||a);
dbms_output.put_line('mark2:'||b);
dbms_output.put_line('mark3:'||f);
dbms_output.put_line('mark4:'||d);
dbms_output.put_line('mark5:'||e);
tot=(mark1+mark2+mark3+mark4+mark5)where regno=x;
end loop;
close c;
end;
OUTPUT:
roll: 101
m1: 50
m3: 70
m4: 80
m5: 90
roll: 102
m1: 30
m2: 40
m3: 50
m4: 60
m5: 70
roll: 103
m1: 45
m2: 55
m3: 65
m4: 75
m5: 85
m1: 55
m2: 65
m3: 75
m4: 85
m5: 95
RESULT:
TABLE:
Table created.
Table created.
PROGRAM:
declare
begin
for i in cur
i.tot,i.avg);
end loop;
end;
OUTPUT:
RESULT:
AIM:
Algorithm:
1. Define a function along with the arguments with its appropriate data types.
2. Select command, re level, max level from the table and copy the same values to the new
variables which have been declared.
3. Add qty hand and re level is less than max level and if again max value to arguments.
4. If it is not less, add the values of qty hand and re level and assign into arguments.
Queries:
TABLE:
Table created.
PROCEDURE DEFINITION:
begin
ac_no=ac_no1;
end;
begin
end;
PROGRAM:
declare
choice number;
ac_no1 number(5);
amount number(5);
begin
ac_no1:= &ac_no1;
choice:= &choice;
amount:= &amount;
if choice=1 then
depositt(ac_no1,amount);
else
withdraww(ac_no1,amount);
end if;
end;
OUTPUT:
RESULT:
TABLE:
Table created.
Table altered.
PROCEDURE DEFINITION:
begin
end;
PROGRAM:
declare
choice number;
eno1 number(5);
begin
eno1:= &eno1;
choice:= &choice;
if choice=1 then
net(eno1);
else
end if;
end;
RESULT:
FUNCTION BODY:
r number(10);
a number(10);
b number(10);
c number(10);
begin
b:=0;
c:=n;
while(c>0)
loop
b:=b+(r*r*r);
c:=floor(c/10);
end loop;
return b;
end armstrong;
PROGRAM:
n number(10);
m number(10);
o number(10);
begin
n:=&n;
o:=n;
m:=armstrong(n);
if(m=o) then
else
number');
end if;
end;
OUTPUT:
RESULT:
AIM:
ALGORITHM:
Step 1:
Open VB 6.0.
Step 2:
Open a form in Visual Basic. Go to Addins - Visual Data manager- New Database->
Microsoft Access->version 7.0 mdb
Step 3:
Give the name for database and right click it and give-> New Table.
Click Add fields-> and add the required fields with appropriate data types..
Goto record source tab. And choose the 2-adCmdTable option. Select the table.
Step 5:
Place a Data Control and set the properties like data source and recordset
Coding :
Add = "insert into sm values('" & Text1 & "'," & Val(Text2) & "," & Val(Text3) & "," & Val(Text4) & ","
& Val(Text5) & "," & Val(Text6) & "," & Val(Text7) & "," & Val(Text8) & ",'" & Text9 & "')"
dbstu.execute Add
Text3.Text = ""
Text1.SetFocus
End Sub
Set rsstu = dbstu.OpenRecordset(" select * from sm where sname = '" & stname & "' ")
Else
Text1 = rsstu(0)
Text2 = rsstu(1)
Text3 = rsstu(2)
Text4 = rsstu(3)
Text5 = rsstu(4)
Text6 = rsstu(5)
Text7 = rsstu(6)
Text8 = rsstu(7)
End If
Else
rsstu.Close
End If
End Sub
Text1.SetFocus
End Sub
Set rsstu = dbstu.open.Recordset(" select * fromsm where sno = " & Text2 & " ")
If rsstu.recordcount = 0 Then
Else
rsstu(0) = Text1
rsstu(1) = Val(Text2.Text)
rsstu(2) = Val(Text3.Text)
rsstu(3) = Val(Text4.Text)
rsstu(4) = Val(Text5.Text)
rsstu(5) = Val(Text6.Text)
rsstu(6) = Val(Text7.Text)
rsstu.Update
End If
End Sub
Unload Me
End Sub
Text8.Enabled = False
Text9.Enabled = False
End Sub
If Val(Text3.Text) >= 50 And Val(Text4.Text) >= 50 And Val(Text5.Text) >= 50 And Val(Text6.Text) >=
50 And Val(Text7.Text) >= 50 Then
Text9.Text = "pass"
Else
Text9.Text = "fail"
End If
End Sub
DATABASE CONNECTION :
Result: Thus the database connectivity using VB/MS Access in successfully executed and verified
AIM:
ALGORITHM:
Click the menu editor button on the toolbar or right click on the form a pop up menu appears from
that choose menu editor.
The menu editor appears, now you’ll add to the program a file menu that includes new, open,
save, close and exit.
Click the caption text box, type &File, press tab, type mnufile and then click the next button.
4. Type &new, press tab, type mnunewitem and then click the next button.
5 Similarly add the other three sub menus of the menu File.
6. Follow the step 3 and 4 to add edit menu that includes cut, copy and paste.
1. On the project menu, click the components command and then click the control tab.
2. Scroll down the list of controls until u see the Microsoft common dialog control 6.0. and
Microsoft Rich Textbox control 6.0
PROGRAM:
End Sub
cd1.filter = filter
cd1.Action = 1
rt1.LoadFile (cd1.FileName)
Exit Sub
errortrap:
Exit Sub
End Sub
name = cd1.FileName
rt1.SaveFile name, 1
End Sub
Clipboard.SetText rt1.SelRTF
rt1.SelRTF = ""
End Sub
Clipboard.SetText rt1.SelRTF
End Sub
rt1.SelRTF = Clipboard.GetText
End Sub
UnsavedChanges = True
End Sub
cd1.CancelError = True
cd1.ShowSave
End If
End If
UnsavedChanges = False
End Sub
End
End Sub
Result: Thus the menu has been created , executed and verified
AIM:
ALGORITHM:
RESULT:
EXAMPLE
The File menu, shown below, will have the following level-two items below it: New, Open, Save,
Save As, Print, and Exit. Note that separator bars appear above the Save, Print, and Exit items.
The Help menu contains just one level-two item below it, About.
To build a menu for use with your VB program, you use the Menu Editor, which appears as an
icon in the toolbar of the VB IDE. It is the circled item in the screen shot below:
1. Start a new VB project and invoke the Menu Editor using either method shown above (click the
Menu Editor toolbar icon or select the Menu Editor option from the Tools menu). The
Menu Editor screen appears, as shown below:
2. For "Caption", type &File (by placing the ampersand to the left of the "F", we establish "F" as
an access key for the File item it enables the user to drop down the File menu by keying
"Alt+F" on the keyboard in addition to clicking the "File" item with the mouse).
3. Click the "right-arrow" button (shown circled below). A ellipsis (...) will appear as the next item
in the menu list, indicating that this item is a level-two item (below "File").
For "Caption", type &New; for "Name", type mnuNew, and for "Shortcut", select Ctrl+N.
By specifying a shortcut, you allow the user to access the associated menu item by pressing
that key combination.
4. For "Caption", type &Open; for "Name", type mnuOpen, and for "Shortcut", select Ctrl+O.
Your Menu Editor screen should look like this:
5. For "Caption", type - (a hyphen), and for "Name", type mnuFileBar1. A single hyphen as the
Caption for a menu item tells VB to create a separator bar at that location. Your Menu
Editor screen should look like this:
7. For "Caption", type Save &As ..., and for "Name", type mnuSaveAs. Your Menu Editor screen
should look like this:
8. For "Caption", type -, and for "Name", type mnuFileBar2. Your Menu Editor screen should
look like this:
10. For "Caption", type -; and for "Name", type mnuFileBar3. Your Menu Editor screen should
look like this:
11. For "Caption", type E&xit, and for "Name", type mnuExit. Your Menu Editor screen should
look like this:
12. Click the "left-arrow" button (shown circled below). The ellipsis (...) no longer appears,
meaning we are back to the top-level items.
For "Caption", type &Help; and for "Name", type mnuHelp. Your Menu Editor screen should
look like this:
13. Click the "right-arrow" button to create a level-two item below "Help". For "Caption", type
&About; and for "Name", type mnuAbout. Your Menu Editor screen should look like this:
14. At this point, we are done creating our menu entries, so click the OK button. That will dismiss
the menu editor and return focus to the VB IDE.
15. Back in the VB IDE, your form will now have a menu, based on what you have set up in the
Menu Editor. If you click on a top-level menu item (File for example), the level-two menu
will drop down:
In thePlace mnuFileNew_Click event, place the code you want to execute when the user clicks the
New menu item. Since this is just a demo, we will place a simple MsgBox statement in the
event procedure:
End Sub
End Sub
MsgBox "Code for 'Save As' goes here.", vbInformation, "Menu Demo"
End Sub
End Sub
18. For the Exit menu item Click event, code the statement Unload Me.
Unload Me
End Sub
19. For the About menu item Click event, code as shown below:
End Sub
20. Run the program. Note how the code executes when you click on the various menu
items. Also test the use of the access keys (e.g., Alt+F, N) and shortcut keys (e.g., Ctrl-O).
CODING
SUB FORMS :
OUTPUT:
FORM WINDOW
FORM 2:
FORM 3 :
FORM4 WINDOW :
FORM5:
PRINT OPTION:
FORM 6:
EXIT OPTION:
ABOUT OPTION :
Form 7: