ABHAY
ABHAY
On
Department of AI & DS
Roll no - 2201321630001
Semester - 5th
Index
S.n Pag
e
o NAME OF PRATICAL No.
1. Installing oracle/ MYSQL
2. Creating Entity-Relationship Diagram using case tools.
Writing SQL statements Using ORACLE /MYSQL:
a). Writing basic SQL SELECT statements.
b). Restricting and sorting data.
c). Displaying data from multiple tables.
3. d). Aggregating data using group function.
e). Manipulating data.
f). Creating and managing tables.
4. Normalization
5. Creating cursor
To install Oracle Database on windows 10 first download Oracle 11g 64 bit from
Oracle. Please follow the link given below to download Oracle Database 11g
http://www.oracle.com/technetwork/database/enterpriseedition/
downloads/index.html
After Oracle Database 11g download complete extract zip files then run setup.exe
from installation folder.
Choose installation path where you want to install Oracle Database 11g after
that enter database name and admin password for your database.
SQL COMMANDS
CREATE TABLE: It defines each column of table uniquely. Each column has
minimum of three attributes name data type and size.
Syntax
SELECT: The select command of sql lets you make queries on the database.
It can be used to retrieve a subset of rows or columns from one or more tables.
Syntax
SELECT <column_name1>,<column_name2> FROM <table _name>;
DESCRIBE : To find information about columns like column name, their
data types and other attributes of a table we can use DESCRIBE command.
Syntax
DELETE : One can delete data from table by using delete from statement.
Syntax
INSERT INTO table name(col1,col2,col3,..)VALUES(value1,value2,value3);
Example
UPDATE: The update command enables user to change the values of existing rows.
Syntax
UPDATE table name SET col1=value1,col2=value2;
Example
UPDATE emp_info SET salary =salary +100;
DROP TABLE: To remove the definition of oracle table, the drop table statement
is used.
Syntax
Syntax
RENAME old name to new name
Experiment – 4
(SQL FUNCTIONS)
SUM (): The SUM() function returns the sum of all the values of the selected
Column.
Syntax:
SELECT SUM(column_name) FROM table_name;
MAX(): The MAX() function returns the maximum value of the selected
column.
Syntax:
SELECT MAX(column name) FROM table_name;
MIN(): The MIN() function returns the minimum value of the selected colume
AVG(): It returns average value after calculating from values in a numeric column.
Syntax:
SELECT AVG(column_name) FROM table name;
Syntax:
SELECT COUNT(column_name) FROM table_name;
FIRST (): The FIRST() function returns the first value of the selected
column.
Syntax:
SELECT FIRST(column_name) FROM table_name;
LAST (): The LAST () function returns the last value of the selected
column. It can beused only in MS ACCESS.
Syntax:
SELECT LAST (column_name) FROM table_name;
String functions are used to perform an operation on input string and return an
output string. Following are the string functions defined in SQL:
ASCII (): This function is used to find the ASCII value of a character.
FORMAT (): This function is used to display a number in the given format.
LCASE(): This function is used to convert the given string into lower case.
LEFT(): This function is used to SELECT a sub string from the left of given
size or characters.
LOCATE(): This function is used to find the nth position of the given word in a
string.
LOWER(): This function is used to convert the upper case string into lower case.
LPAD(): This function is used to make the given string of the given size by adding
LTRIM(): This function is used to cut the given sub string from the original string.
MID(): This function is to find a word from the given position and of the given
size.
POSITION(): This function is used to find position of the first occurrence of the
given alphabet.
REPEAT(): This function is used to write the given string again and again till the
number of times mentioned
.
REPLACE(): This function is used to cut the given string by removing the given
sub string.
RIGHT(): This function is used to SELECT a sub string from the right end of the
given size.
SQL Constraints
SQL constraints are used to specify rules for the data in a table.
The following constraints are commonly used in SQL:--->
The SQL Joins clause is used to combine records from two or more tables in a
database. A JOIN is a means for combining fields from two tables by using values
common to each.
Consider the following two
Now, let us join these two tables in our SELECT statement as shown below.
This would produce the following result.
Now, let us join these two tables in our SELECT statement as shown below
SQL> SELECT ID, NAME, AGE, AMOUNT FROM CUSTOMERS, ORDERS WHERE CUSTOMERS.ID =
ORDERS.CUSTOMER_ID;
Here, it is noticeable that the join is performed in the WHERE clause. Several
operators can be used to join tables, such as =, <, >, <>, <=, >=,! =, BETWEEN,
LIKE, and NOT; they can all be used to join tables.
There are different types of joins available in SQL −>
LEFT JOIN − returns all rows from the left table, even if there are no matches
in the righttable.
RIGHT JOIN − returns all rows from the right table, even if there
are no
matches in the lefttable.
FULL JOIN − returns rows when there is a match in one of the tables.
SELF JOIN − is used to join a table to itself as if the table were two
tables, temporarilyrenaming at least one table in the SQL statement.
The LIKE operator is used in a WHERE clause to search for a specified pattern in
a column.There are two wildcards often used in conjunction with the LIKE
operator:
The percent sign and the underscore can also be used in combinations! LIKE
Syntax
SELECT column1, column2, FROM table_name WHERE column N LIKE
pattern;
Experiment No: 7
Theory:
There are two types of cursor
Explicit cursor
Implicit cursor
A. Explicit cursor
After declaring a cursor, we can use the following commands to control the cursor.
Open
Fetch
Close
declare
c_rollno stud.rollno%type;
cursorst is select rollno from stud where rollno=1; begin
openst; loop
fetchst into c_rollno;
update stud set lastname='barde' where rollno=c_rollno; exit when st %
NOT FOUND;
end loop;
dbms_output.put_line('table updated'); close st;
end;
output:table updated
In the above cursor we are going to update the table. Name of table is stud and its
attributes are rollno which is number, first name which is of data type varchar2,last
name which is of data type varchar2.
In the Declare section we declare variable that match to the attribute in the table
%TYPE matches the datatype of that variable.In the above procedure c_rollno is
the variable that we declare in the procedure to access the column rollno from table
stud because of %type it directly provide matching of data.
In the begin section we open the cursor and fetch the values. Error handles by the
exception section. Close the cursor. And end;
Experiment No:7(A)
PROCEDURE
Objective: Creating Procedure in Oracle
Theory:
PL/SQL supports the two types of programming:
Procedure.
Function.
Procedures are usually used to perform any specific task and functions are used to
compute a value.
PROCEDURE
The basic syntax for the creating procedure is:
output:Procedure created.
BEGIN
(Exception section)
EXCEPTION
(Error handling or exception section).
End Function name;
A function has two parts, namely function specification and function body. The
function specification begins with the keyword function and end with return
clause. The function bodies begins with the keyword is/as and end with keyword
end
Experiment No: 8
Objective: Design and implementation of Student Information System
i.Create the database design with required tables (using SQL) as:
Admin(admin_id, admin_name, admin_pass)
Student_Details(roll_no, name, age, address, dob, email_id, phno, course_enrolled,
section, group etc as required)
Department(dept_id, dept_name, head_name etc. as required)
(Apart from these additional tables/fields can be added as required)
ii. Create the system design with features for adding students by admin after login,
students could view and update their details, department could enroll and view
students as per the database design created in step i.
iii. Basic project should contain required design forms with features to support step