Study of Basic SQL Commands
Study of Basic SQL Commands
AIM:
PROCEDURE:
STEP 1: Start
STEP 4: Execute different Commands and extract information from the table.
STEP 5: Stop
SQL COMMANDS
Command is used to remove all the records in the table including the space allocated for the
table.
COMMAND DESCRIPTION:
TYPES OF COMMANDS:
1. CREATE
2. ALTER
3. DROP
4. TRUNCATE
5. COMMENT
6. RENAME
SELECT
INSERT
UPDATE
DELETE
GRANT
REVOKE
COMMANDS EXECUTION
SQL> create table employee (Employee_name varchar2 (10), employee_no number (8),
dept_name varchar2 (10), dept_no number (5), date_of_join date);
Table created.
TABLE DESCRIPTION
SQL> desc employee;
EMPLOYEE_NAME VARCHAR2(10)
EMPLOYEE_NO NUMBER(8)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
------------------------------------------------------------
SQL> create table employee1 (Employee_name varchar2 (10), employee_no number (8) primary
key, dept_name varchar2 (10), dept_no number (5),date_of_join date);
Table created.
TABLE DESCRIPTION
------------------------------
DATE_OF_JOIN DATE
INSERTION OF TABLE VALUES
--------------------------------------------
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
----------------------------------------------------
-----------------------------------------
SQL> update employee1 set employee_no=300 where dept_no=67;
1 row updated.
--------------------------------------
Table altered.
EMPLOYEE_NAME VARCHAR2(10)
DEPT_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)
DATE_OF_JOIN DATE
-------------------------------------------------------------------------
Table altered.
EMPLOYEE_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)
DATE_OF_JOIN DATE
Table altered.
SQL> desc employee;
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
----------------------------------------------------------------------------
Note: For creation of foreign key, both the table should possess primary key with same
attributes. Similarly for dropping employee 1 as well as employee table ,first the
relationship i.e., primary key has to be removed from both the tables.
SQL> alter table employee1 add foreign key (employee_no) references employee
(employee_no); Table altered.
EMPLOYEE_NAME VARCHAR2(10)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
-------------------------------------------------------------------------------------------
SQL> select * from employee1;
---------------------------------------------------
1 row updated.
1 row updated.
1 row updated.
----------------------------------------------------------------------------------------------
Note: Before modifying the character of a column,first set the column values to null.The
feature of a column can be altered only if all its values become null or empty.
1 row updated.
1 row updated.
1 row updated.
---------------------------------------------------
Table altered.
1 row updated.
1 row updated.
1 row updated.
SALARY
SALARY
--------------
100 90 134
----------------------------------------------------
Comment created.
-------------------------------------------------------
---------------------------------------------------------
Comment created.
COMMENTS ---------------------------------------------------------
3 rows selected.
------------------------------------------
1 row deleted.
1 row deleted.
GRANT COMMAND
------------------------------
Grant succeeded.
REVOKE COMMAND
--------------------------------
Revoke succeeded.
RENAMING TABLE
---------------------------------
Table renamed.
TRUNCATION OF TABLE
---------------------------------------------
Table truncated.
no rows selected
DROPPING OF TABLE
-------------------------------
Table dropped.
RESULT:
Thus the Special SQL commands has been verified and executed successfully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AIM:
PROCEDURE:
STEP 1: Start
STEP 5: Stop
SQL COMMANDS
Command is used to identify a point in a transaction in which it can be restored using Roll
back command.
Command is used to find the maximum among the entities in a particular attribute.
Command is used to find the maximum among the entities in a particular attribute.
Command is used to add all the entities with in the attribute.
8. COMMAND NAME: UNION
Command is used to compile all distinct rows and display all entities in both rows.
Command is used to display only the rows that don’t match in both queries.
12.COMMAND NAME: AVG
TYPES OF COMMANDS
COMMIT
SAVEPOINT
ROLLBACK
SET OPERATORS
UNION
UNIONALL
INTERSECT
MINUS
ARITHMETIC OPERATORS
MAX
MIN
COUNT
AVG
SUM
COMMANDS EXECUTION
CREATION OF TABLE
------------------------------
Table created.
Table created.
DESCRIPTION OF TABLE
----------------------------------
EMPLOYEE_NAME VARCHAR2(10)
DEPT_NO NUMBER
DEPT_NAME VARCHAR2(10)
EMPLOYEE_NAME VARCHAR2(10)
DEPT_NAME VARCHAR2(10)
--------------------------------------------
19
---------------------------------------------------
SQL> commit;
Commit complete.
SQL> rollback;
Rollback complete.
Savepoint created.
1 row updated.
1 row deleted.
Rollback complete.
ARITHMETIC OPERATORS
-------------------------------------
SUM (EMPLOYEE_NO)
----------------
2101
AVG (EMPLOYEE_NO)
----------------
700.33333
MAX (EMPLOYEE_NO)
----------------
990
MIN (EMPLOYEE_NO)
----------------
234
SQL> select count (employee_no) from employee;
COUNT (EMPLOYEE_NO)
------------------
3
SET OPERATORS
------------------------
SQL> SQL> select employee_no from employee union select employee_no from employee1;
EMPLOYEE_NO
-----------
SQL> select employee_no from employee union all select employee_no from employee1;
EMPLOYEE_NO
-----------
SQL> select employee_no from employee intersect select employee_no from employee1;
EMPLOYEE_NO
-----------
234
SQL> select employee_no from employee minus select employee_no from employee1;
EMPLOYEE_NO
-----------
877
990
RESULT:
Thus the Special SQL commands has been verified and executed successfully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AIM:
To execute and verify the SQL commands using nested queries and Join queries.
PROCEDURE:
STEP 1: Start
STEP 4: Execute different Commands and extract information from the table.
STEP 5: Stop
SQL COMMANDS
Command returns the matching rows from the tables that are being joined.
Command returns matching rows from the tables being joined and also non-matching row
from the left table in the result and places null values in the attributes that come from the right
side table.
Command returns matching rows from the tables being joined and also non-matching row
from the right table in the result and places null values in the attributes that come from the left
side table.
COMMANDS EXECUTION
CREATION OF TABLE
------------------------------
SQL> create table employee (Employee_Name varchar2 (10), Employee_no number primary
key, Dept_no number, Dept_name varchar2 (10));
Table created.
SQL> create table employee1 (Employee_Name varchar2 (10), Employee_no number primary
key, Dept_no number, dept_name varchar2 (10));
Table created.
DESCRIPTION OF TABLE
----------------------------------
EMPLOYEE_NAME VARCHAR2(10)
DEPT_NO NUMBER
DEPT_NAME VARCHAR2(10)
--------------------------------------------
JOIN COMMANDS
-------------------------
INNER JOIN
----------------
EMPLOYEE_N DEPT_NO
------------------- --------------
Ganesh 45
-------------------------
DEPT_NAME DEPT_NO
----------------- --------------
---------------------------
DEPT_NAME DEPT_NO
----------------- --------------
SUB-QUERY
-----------------
SQL> update employee set dept_no= (select sum (employee_no) from employee) where
employee_no=234;
1 row updated.
SNAME CHAR(15)
RATING NUMBER(4)
AGE NUMBER(2)
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
Table created.
SQL> desc boat;
BNAME CHAR(15)
1 row created.
SQL> /
1 row created.
SQL> /
Table created.
DAY DATE
1 row created.
SQL> /
1 row created.
BNAME CHAR(15)
COLOR CHAR(6)
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
Table created.
1 row created.
SQL> /
1 row created.
SQL> select sname from sailor where sid in(select sid from reserve where bid=103);
no rows selected
SQL> select sname from sailor where sid in(select sid from reserve where bid=102);
SNAME
---------------
lubber
SQL> select sid from reserve where bid in(select bid from boat where color='red');
SID
----------
12
SQL> select color from boat where bid in(select bid from reserve where sid in(select sid from
sailore where sname='lubber'));
COLOR
------
red
RESULT:
Thus the SQL commands for Joins and Nested queries has been verified and executed
successfully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AIM:
To execute and verify the SQL commands for Views.
PROCEDURE:
STEP 1: Start
STEP 5: Execute different Commands and extract information from the View.
STEP 6: Stop
SQL COMMANDS
Command is used to change a value in a tuple without changing all values in the tuple.
COMMANDS EXECUTION
CREATION OF TABLE
------------------------------
Table created.
TABLE DESCRIPTION
-------------------------------
EMPLOYEE_NAME VARCHAR2(10)
EMPLOYEE_NO NUMBER(8)
DEPT_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)
CREATION OF VIEW
------------------------------
View created.
DESCRIPTION OF VIEW
------------------------------
EMPLOYEE_NAME VARCHAR2(10)
DEPT_NAME VARCHAR2(10)
DEPT_NO NUMBER(5)
Raj 98 IT 22
MODIFICATION
----------------------
1 row created.
0 rows updated.
1 row updated.
View droped
RESULT:
Thus the SQL commands for View has been verified and executed successfully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EX: NO: 5A
CURSOR
AIM:
PROCEDURE:
STEP 1: Start
STEP 2: Initialize the Cursor Procedure based on the table attributes to which the actual
operation has to be carried out.
STEP 6: Stop
EXECUTION:
Table created.
SQL> insert into Sal values (1,'vijay','manager','Accounts', 6000, 45, 200, 250, 1500.75);
1 row created.
SQL> insert into sal values (2,'vasanth','Asst.manager','Accounts', 4000, 45, 200, 200, 1200);
1 row created.
SQL> insert into Sal values (3,'priya','Steno','sales', 2000, 45, 100, 50,200);
1 row created.
3 priya Steno sales 2000 45 100 50 200
CODING
net_salary number(8,2);
begin
end loop;
close cur_salary;
end;
/
OUTPUT:
RESULT:
Thus the Cursor Procedure for calculating the Payroll process has been executed
successfully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROCEDURES
AIM:
To write a PL/SQL block to display the student name marks whose average mark is above
60%.
PROCEDURE:
STEP1: Start
STEP3: Insert the values into the table and calculate total and average of each student
STEP4: Execute the procedure function the student who get above 60%.
CODINGS
Table created
1 row created.
1 row created.
1 row created.
--------------------------------------------------------------------
tot number(3);
cursor c_mark is select*from student where mark1>=40 and mark2>=40 and mark3>=40 and
mark4>=40 and mark5>=40;
begin
dbms_output.put_line('regno name mark1 mark2 mark3 mark4 mark4 mark5 total average');
dbms_output.put_line('-------------------------------------------------------------');
end loop;
end;
/
OUTPUT:
------------------------------------------------------------------------------------
RESULT:
Thus the PL/SQL block to display the student name,marks,average is verified and executed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FUNCTIONS
AIM:
To write a Functional procedure to search an address from the given database.
PROCEDURE:
STEP 1: Start
STEP 4: Frame the searching procedure for both positive and negative searching.
STEP 5: Execute the Function for both positive and negative result .
STEP 6: Stop
EXECUTION
Table created.
1 row created.
CODING
begin
return address;
end;
/ Function created.
SQL>declare
address varchar2(100);
begin
address:=findaddress(20312);
dbms_output.put_line(address);
end;
/
OUTPUT:
SQL> declare
ddress varchar2(100);
begin
ddress:=findaddress(23556);
dbms_output.put_line(address);
end;
/
OUTPUT2:
.
RESULT:
Thus the Function for searching process has been executed successfully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CONTROLS
AIM:
To write a PL/SQL block using different control (if else, for loop, while loop,…) statements.
PROCEDURE:
STEP 1: Start
STEP 3: Develop the set of statements with the essential operational parameters.
STEP 6: Stop.
CODING
number;
c number;
begin
a:=&a;
b:=&b;
c:=a+b;
dbms_output.put_line('sum of'||a||'and'||b||'is'||c);
end;
INPUT:
Enter value for a: 23 old 6: a:=&a; new 6: a:=23; Enter value for b: 12 old 7: b:=&b; new 7:
b:=12;
OUTPUT:
b number;
c number;
d number;
begin a:=&a;
b:=&b;
c:=&b;
if(a>b)and(a>c)
elsif(b>a)and(b>c)then
dbms_output.put_line('B is maximum');
end if;
end;
/
INPUT:
old 7: a:=&a;
new 7: a:=21;
old 8: b:=&b;
new 8: b:=12;
old 9: c:=&b;
new 9: c:=45;
OUTPUT:
C is maximum
endvalue number;
begin
endvalue:=&endvalue;
n:=1;
sum1:=sum1+n;
end if;
end loop;
dbms_output.put_line('sum ='||sum1);
end;
/
INPUT:
old 6:
endvalue:=&endvalue;
new 6: endvalue:=4;
OUTPUT:
sum =4
endvalue number;
begin endvalue:=&endvalue;
n:=1;
while(n<endvalue) loop
sum1:=sum1+n;
n:=n+2;
end loop;
end;
/
INPUT:
old 6: endvalue:=&endvalue;
new 6: endvalue:=4;
OUTPUT:
RESULT:
Thus the PL/SQL block for different controls are verified and executed.
AIM:
PROCEDURE:
STEP 1: Start
STEP 6: Stop
EXECUTION:
Form1
List1.AddItem Text1.Text
List1.AddItem Text2.Text
If Option1.Value = True Then
gender = "male"
End If
gender = "female"
End
End If
End If
End Sub
List1.RemoveItem (0)
End If
End Sub
End
End Sub
RESULT:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FORM DESIGN
AIM:
PROCEDURE:
STEP 1: Start
STEP 6: Stop
EXECUTION:
Form1
End Sub
End Sub
End Sub
End
End Sub
RESULT:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TRIGGER
AIM:
To develop and execute a Trigger for before and after update, delete, insert operations on a
table.
PROCEDURE:
STEP 1: Start
STEP 2: Initialize the trigger with specific table id.
STEP 3: Specify the operations (update, delete, insert) for which the trigger has to be
executed.
STEP 4: Execute the Trigger procedure for both before and after sequences
STEP 5: Carryout the operation on the table to check for Trigger execution.
STEP 6: Stop
EXECUTION:
Table created.
1 row created.
1 row created.
1 row created.
------------------------------------------------
IF UPDATING THEN
END IF;
END;
Trigger created.
TABLE IS INSERTED
1 row created.
TABLE IS DELETED
1 row deleted.
------------------------------------------------------
BEGIN
IF UPDATING THEN
ELSIF
INSERTING
THEN
DBMS_OUTPUT.PUT_LINE('TABLE IS INSERTED');
ELSIF DELETING
END IF;
END;
/
Trigger created.
TABLE IS INSERTED
1 row created.
TABLE IS UPDATED
1 row updated.
TABLE IS DELETED
1 row deleted.
RESULT:
Thus the Trigger procedure has been executed successfully for both before and
after sequences.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MENU DESIGN
AIM:
PROCEDURE:
STEP 1: Start
STEP 2: Create the form with essential controls and insert the menu using menu editor.
STEP 6: Stop
CODING:
Form 1:
End Sub
End Sub
End Sub
End Sub
End Sub
End Sub
End Sub
End Sub
End Sub
End Sub
RESULT:
Thus the program for menu creation with menu editor has been developed and executed
successfully.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REPORT GENERATION
AIM:
PROCEDURE:
STEP 1: Start
STEP 2: Create the form with essential controls for employee details.
STEP 5: Write the code for doing the appropriate operations in the employee database.
STEP 8: Stop
Unload Me
Form1.Visible = False
Form2.Visible = True
Load Form2 Form2.Show
End Sub
Unload Me
Form1.Visible = False
Form3.Visible = True
End Sub
Unload Me
Form1.Visible = False
Form4.Visible = True
End Sub
End
End Sub
DataReport1.Show
End Sub
FORM2
CODING:
General Declaration
net = gp - ded con.Execute "insert into emp values('" & Text1.Text & "','" & Text2.Text & "','" &
Combo1.Text & "','" & Text3.Text & "','" & Val(Combo1.ItemData(Combo1.ListIndex)) & "','"
& Val(Text4.Text) & "','" & Val(Text5.Text) & "','" & Val(Text6.Text) & "','" &
Val(Text7.Text) & "','" & gp & "','" & net & "',0)"
Unload Form2
End Sub
End Sub
con.Close
End Sub
FORM3:
UPDATION CODE:
General Declaration
Dim n As Double
Unload Form3
End Sub
End Sub
con.Close
End Sub
FORM4:
DISPLAY CODE:
General Declaration
num = Text1.Text rs.Open "select * from emp where id='" + num + "'", con Set
DataReport1.DataSource = rs DataReport1.Show
End Sub
End Sub
con.Close
End Sub
AIM:
DESIGN PLAN:
Project Plan
Software testing
Software Debugging
Conclusion
PROJECT PLAN:
Allowances
The purpose of the Payroll as to provide Payroll for the Employee with allowance and
deduction individually and to update the Net pay.
Functionality of System:
It includes Employee Name, Employee id, Address, Designation and Date of Birth.
2. Allowance:
DA refers to Dearness Allowance, TA refers to Traveling Allowance, HRA refers to House
Rent Allowance, and MA refers to Medical Allowance. 3.
3. Deduction:
PF refers to Provident Fund. LIC refers to Life Insurance Corporation, Vehicle Loan
SOFTWARE TESTING:
The main objectives of testing to maximize the test case, minimize the number of errors,
focus on correctness and efficiency of program. It helps to find out details of the employee and
their personal details, experience with total salary. Allowances and Deductions are calculated
from GROSS amount.
CODING:
FORM 1:
Unload Me
Form2.Show
End Sub
Unload Me
Form3.Show
End Sub
End Sub
End
End Sub
Unload Me
Form5.Show
End Sub
FORM 2:
Adodc1.Recordset.Fields("des") = Text3.Text
Adodc1.Recordset.Fields("age") = Val(Text4.Text)
Adodc1.Recordset.Fields("sex") = Text5.Text
Adodc1.Recordset.Fields("dob") = Val(Text6.Text)
Adodc1.Recordset.Fields("doj") = Val(Text7.Text)
Adodc1.Recordset.Fields("sal") = Val(Text8.Text)
Adodc1.Recordset.Fields("ph") = Val(Text9.Text)
Adodc1.Recordset.Update
End Sub
Adodc1.Recordset.Update
End Sub
Adodc1.Recordset.MoveFirst On Error
Adodc1.Recordset.
MoveNext
Wend diva:
End Sub
If b = 1 Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
Else
End If
End Sub
Unload Me
End Sub
FORM 3:
Dim c As Variant Private Sub Command1_Click()
Adodc1.Recordset.Fields("sal") = Val(Text3.Text)
Adodc1.Recordset.Fields("loan") = Val(Text4.Text)
Adodc1.Recordset.Fields("loan_left") = Val(Text5.Text)
Adodc1.Recordset.Fields("ma") = Val(Text6.Text)
Adodc1.Recordset.Fields("hra") = Val(Text7.Text)
Adodc1.Recordset.Fields("ins_left") = Val(Text8.Text)
Adodc1.Recordset.Fields("da") = Val(Text9.Text)
Adodc1.Recordset.Fields("total_allow") = Val(Text10.Text)
'adodc1.Recordset.Update
End Sub
Adodc1.Recordset.Fields("e_name") = Text1.Text
Adodc1.Recordset.Update
End Sub
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.MoveNext
Wend diva:
End Sub
Private Sub Command4_Click()
b = MsgBox("Are you sure you want to delete it....", vbOKCancel + vbCritical, "Diva")
If b = 1 Then Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
Else
End If
End Sub
Unload Me
End Sub
Text10.Text = c
Adodc1.Recordset.Fields("e_name") = Text1.Text
Adodc1.Recordset.Update
End Sub
Text10.Text = c
Adodc1.Recordset.Fields("e_name") = Text1.Text
Adodc1.Recordset.Update
End Sub
FORM 4:
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("e_name") = Text1.Text
Adodc1.Recordset.Fields("e_no") = Val(Text2.Text)
Adodc1.Recordset.Fields("sal") = Val(Text3.Text)
Adodc1.Recordset.Fields("spf") = Val(Text4.Text)
Adodc1.Recordset.Fields("fa") = Val(Text5.Text)
Adodc1.Recordset.Fields("hf") = Val(Text6.Text)
Adodc1.Recordset.Fields("hr") = Val(Text7.Text)
Adodc1.Recordset.Fields("income_tax") = Val(Text8.Text)
Adodc1.Recordset.Fields("others") = Val(Text9.Text)
Adodc1.Recordset.Fields("total_ded") = Val(Text10.Text)
'adodc1.Recordset.Update
End Sub
Adodc1.Recordset.Fields("e_name") = Text1.Text
Adodc1.Recordset.Update
End Sub
Wend diva:
End Sub
b = MsgBox("Are you sure you want to delete it....", vbOKCancel + vbCritical, "Diva")
If b = 1 Then Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
MsgBox "Deleted"
Else
End If
End Sub
End Sub
x = Val(Text3.Text)
Text4.Text = (x / 0.2)
Text5.Text = (x / 0.2)
Text6.Text = (x / 0.2)
Text7.Text = (x / 0.2)
Text8.Text = (x / 0.2)
Text9.Text = (x / 0.2)
Text10.Text = c
Adodc1.Recordset.Fields("e_name") = Text1.Text
Adodc1.Recordset.Update
End Sub
Text10.Text = c
End Sub
x = Val (Text3.Text)
Text4.Text = (x / 0.2)
Text5.Text = (x / 0.2)
Text6.Text = (x / 0.2)
Text7.Text = (x / 0.2)
Text8.Text = (x / 0.2)
Text9.Text = (x / 0.2)
Adodc1.Recordset.Update
End Sub
FORM 5:
Unload Me
End Sub
End Sub
End Sub
Adodc1.Recordset.Update
End Sub
Text6.Text = c
End Sub
Result:
Thus the payroll processing system is designed and implemented in VB and output is
verified.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~