0% found this document useful (0 votes)
85 views98 pages

Dbms Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
85 views98 pages

Dbms Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 98
INDEX Exp.| Date of ‘xperiment Tit Page rks [Signature No [Experiment Experiment Title Now| Marks |Signature| 1 Create a database table using DDL and DML command in SQL 2 Create a set of tables, add some constraints and incorporate referential integrity 3 Query the database tables using different where clause condition and also aggregate functions 4a Query the database tables and explore Nested queries 4 Query the database table and explore simple Join operations 5 Query the database table and explore natural, equi and outer Join 6 Write user defined Functions and Stored Procedures in SQL 1 Execute Complex transactions and realize DCL and TCL commands 8 Write SQL Triggers for insert,delete and update operations in a database table 9 Create view and index for database tables with a large number of records 10 Create an XML database and validate it using XML schema u Create Document,Column and graph based data using NOSQL database tools 12 Develop a simple GUI based database applications 13 Case study using any of the Real life database applications EX: NO: 1 CREATE A DATABASE TABLE USING DDL and DML COMMANDS IN RDBMS AIM: To execute and verify the Data Definition Language commands and constraints DDL (DATA DEFINITION LANGUAGE) CREATE @ = ALTER DROP TRUNCATE ¢ COMMENT ¢ RENAME PROCEDURE STEP 1: Start STEP 2: Create the table with its essential attributes. STEP 3: Execute different Commands and extract information from the table. STEP 4: Stop SQL COMMANDS 1-COMMAND NAME: CREATE COMMAND DESCRIPTION: CREATE command is used to create objects in the database. 2-COMMAND NAME: DROP COMMAND DESCRIPTION: DROP command is used to delete the object from the database, 3-COMMAND NAME: TRUNCATE, COMMAND DESCRIPTION: TRUNCATE command is used to remove all the records from the table 4-COMMAND NAME: ALT ER COMMAND DESCRIPTION: ALTER command is used to alter the database structure of 5~COMMAND NAME: RENAME, COMMAND DESCRIPTION: RENAME command is used to rename the objects. QUERY: 01 QL. Write a query to create salary. table employee with empno, ename, designation, and Syntax for creating a table: SQL: CREATE (COLUMN NAME.1 (SIZE), COLUMN NAME.1 (SIZE) QUERY: 01 SQL>CREATE TABLE EMP (EMPNO NUMBER (4), ENAME VARCHAR? (10), DESIGNATIN VARCHAR? (10), SALARY NUMBER (8,2)); ‘Table created. QUER' 2 Q2. Write a query to display the column name and datatype of the table employee. Syntax for describe the table: SQL: DESC ; SQL> DESC EMP; Name Null? Type EMPNO NUMBER(4) ENAME VARCHAR2(10) DESIGNATIN VARCHAR2(10) SALARY NUMBER(8,2) QUER' 3 Q3. Write a query for create a from an existing table with all the fields Syntax For Create A from An Existing Table With All Fields SQL> CREATE TABLE SELECT * FROM ;QUERY: 03 SQL> CREATE TABLE EMP1 AS SELECT * FROM EMP; ‘Table created, SQL> DESC EMPI Name Type EMPNO. NUMBER(4) ENAME VARCHAR2(10) DESIGNATIN VARCHAR2(10) SALARY NUMBER(8,2) QUERY: 04 Q4. Write a query for create a from an existing table with selected fields Syntax For Create A from An Existing Table With Selected Fields SQL> CREATE TABLE SELECT EMPNO, ENAME FROM ; QUERY: 04 SQL> CREATE TABLE EMP2 AS SELECT EMPNO, ENAME FROM EMP; ‘Table created. SQL> DESC EMP2 Name Null? Type EMPNO, NUMBER (4) ENAME VARCHAR? (10) QUERY: 05 QS. Write a query for create a new table from an existing table without any record: Syntax for create a new table from an existing table without any record: SQL> CREATE TABLE AS SELECT * FROM WHERE ; QUERY: IS SQL> CREATE TABLE EMP3 AS SELECT * FROM EMP WHERE 1>2; Table created. SQL> DESC EMP3; Name Null? Type EMPNO, NUMBER(4) ENAME VARCHAR2(10) DESIGNA’ VARCHAR2(10) SALARY NUMBER(,2); ALTER & MODIFICATION ON TABLE QUERY: 06 Q6. Write a Query to Alter the column EMPNO NUMBER (4) TO EMPNO NUMBER (6). Syntax for Alter & Modify on a Single Colum SQL > ALTER
MODIFY (SIZE); QUERY: 06 SQL>ALTER TABLE EMP MODIFY EMPNO NUMBER (6); ‘Table altered SQL> DESC EMP; Name Null? Type NUMBER(6) EMPNO ENAME VARCHAR2(10) DESIGNATIN VARCHAR2(10) SALARY NUMBER(8,2) QUERY: 07 Q7. Write a Query to Alter the table employee with multiple columns (EMPNO, ENAME.) tax for alter table with multiple colum SQL > ALTER
MODIFY (SIZE), MODIFY (SIZE) QUERY: 07 SQL>ALTER TABLE EMP MODIFY (EMPNO NUMBER (7), ENAME VARCHAR2(12)); Table altered, SQL> DESC EMP; Name Null?) Type EMPNO. NUMBER(7) ENAME, VARCHAR2(12) DESIGNA’ VARCHAR2(10) SALARY NUMBER(8,2); QUERY: 08 Q8. Write a query to add a new column in to employee Syntax for add a new column: SQL> ALTER TABLE
ADD ( ); QUERY: 08 SQL> ALTER TABLE EMP ADD QUALIFICATION VARCHAR2(6); ‘Table altered, SQL> DESC EMP; Type EMPNO, NUMBER(7) ENAME, VARCHAR2(12) DESIGNA’ VARCHAR2(10) SALARY NUMBER@,2) QUALIFICATION VARCHAR2(6) QUERY: 09 Q9. Write a query to add multiple columns in to employee Syntax for add a new column: NAME> ADD ( ,( , QUERY: 09 SQL>ALTER TABLE EMP ADD (DOB DATE, DOJ DA1 Table altered. SQL> DESC EMI Name Null? Type NUMBER(7) ENAME VARCHAR2(12) DESIGNATIN VARCHAR2(10) SALARY NUMBER@,2) QUALIFICATION VARCHAR2(6) DOB DATE DoJ DATE REMOVE / DROP QUERY: 10 Q10. Write a query to drop a column from an existing table employee Syntax for add a new column: SQL> ALTER TABLE
DROP COLUMN ; QUER 0 SQL> ALTER TABLE EMP DROP COLUMN DOJ; Table altered. SQL> DESC EMP; Name Null? Type NUMBER(7) EMPNO. ENAME VARCHAR2(12) DESIGNATI VARCHAR2(10) SALARY NUMBER@,2) QUALIFICATION VARCHAR2(6) DOB DATE QUERY: 11 Q10, Write a query to drop multiple columns from employee Syntax for add a new column: SQL> ALTER TABLE
DROP ,,. QUERY: 11 SQL> ALTER TABLE EMP DROP (DOB, QUALIFICATION); ‘Table altered. SQL> DESC EMP; Name Null?) Type EMPNO. NUMBER(7) ENAME VARCHAR2(12) DESIGNAT! VARCHAR2(10) SALARY NUMBER(8,2) REMOVE QUERY: 12 Q10. Write a query to rename table emp to employee wyntax for add a new column: SQL> ALTER TABLE RENAME TO QUERY: 12 SQL> ALTER TABLE SQL> DESC EMPLOYE! Name Null?) Type MP RENAME EMP TO EMPLOYEE; EMPNO. NUMBER(7) ENAME VARCHAR2(12) DESIGNATIN VARCHAR2(10) SALARY NUMBER(8,2) To implementation on DML Commands in RDBMS AIM: To execute and verify the DML ¢ commands DML (DATA MANIPULATION LANGUAGE) SELECT 2. INSERT DELETE, 4. UPDATE SQL COMMANDS 1, COMMAND NAME: INSERT COMMAND DESCRIPTION: INSERT command is used to Insert objects in the datab: 2. COMMAND NAME: SELECTCOMMAND DESCRIPTION: SELECT command is used to SELECT the object fromthe database. 3, COMMAND NAME: UPDATE COMMAND DESCRIPTION: UPDA’ command is used to UPDATE. the records from the table 4, COMMAND NAME: DELETE COMMAND DESCRIPTION: DELETE command is used to DELETE the Records form the table 5. COMMAND NAME: COMMIT COMMAND DESCRIPTION: COMMIT command is used to save the Records, 6. COMMAND NAME: ROLLBACK COMMAND DESCRIPTION: ROLL BACK command is used to undo the Records, 7. COMMAND NAME: SAVE POINT COMMAND Di CRIPTION: SAVE POINT command is used to undo the Records in a particular transaction. INSERT QUERY: 01 QI. Write a query to insert the records Syntax for Insert Records in to a tabl in to employee. SQL > INSERT INTO
VALUES< VALI, ‘VAL2’,. QUERY: 01 INSERT A RECORD FROM AN EXISTING TABLE: SQL>INSERT INTO EMP VALUES(101,'NAGARAJAN'/LECTURER’,15000); 1 row created, SELECT QUER 2 Q3. Write a query to display the records from employee. Syntax for select Records from the table: SQL> SELECT * FROM
; QUERY: 02 DISPLAY THE EMP TABLE: SQL> SELECT * FROM EMP; EMPNO ENAME DESIGNATION — SALARY 101 NAGARAJAN LECTURER 15000 INSERT A RECORD USING SUBSITUTION METHOD QUERY: 03 Q3. Write a query to insert the records in to employee using substitution method. Syntax for Insert Records into the table: SQL > INSERT INTO
VALUES< ‘&column name’, ‘&column name 2°,....)5 QUERY: 03 SQL> INSERT INTO (&EMPNO, '&ENAME''&DESIGNATIN''& SALARY); ‘MP VALUE! Enter value for empno: 102 Enter value for ename: SARAVANAN Enter value for designatin: LECTURER Enter value for salary: 15000 old 1: INSERT INTO EMP VALUES(&EMPNO,&ENAME''&DESIGNATIN''&SALARY') new 1: INSERT INTO EMP VALUES(102,SARAVANAN'/LECTURER’,'15000') 1 row created. sq>/ Enter value for empno: 103 Enter value for ename: PANNERSELVAM Enter value for designatin: ASST. PROF Enter value for salary: 20000 old 1: INSERT INTO EMP VALUES(&EMPNO, &ENAME''&DESIGNATIN''&SALARY’) new 1: INSERT INTO EMP VALUES(103,'PANNERSELVAM'ASST PROF’,20000°) 1 row created, SQL> / Enter value for empno: 104 Enter value for ename: CHINNI Enter value for designatin: HOD, PROF Enter value for salary: 45000 old 1: INSER’ INTO EMP VALUES(&EMPNO,&ENAME'/&DESIGNATIN'&SALARY’) new 1: INSERT INTO EMP VALUES(104,CHINNI, HOD, PROF'45000') 1 row created. SQL> SELECT * FROM EMP; EMPNO ENAME DESIGNATIN SALARY 101 |NAGARAJAN LECTURER _ [15000 102__|SARAVANAN[LECTURER __|15000 103 | SELVAM__[AssT.PROF _b0000 104 [CHINNT [HOD,PROF _ 15000 UPDATE QUERY: 04 QL. Write a query to update the records from employee. Syntax for update Records from the table: SQL> UPDATE <
SET = WHERE ; QUERY: 04 SQL> UPDATE EMP SET SALARY=16000 WHERE EMPNO=101; | row updated. SQL> SELECT * FROM EMP: EMPNO ENAME DESIGNATION SALARY TO! [NAGARAJAN LECTURER 116000 102 [SARAVANAN [LECTURER l1s000 103 [SELVAM ASST. PROF hoooo 104 |CHINNI HOD,PROF 4000 UPDATE MULTIPLE COLUMNS. QUERY: 05 QS. Write a query to update multiple records from employee. 1 Syntax for update multiple Records from the table: SQL> UPDATE <
SET = WHERE UPDATE EMP SET SALARY = 16000, DESIGNATIN="ASST. PROF’ WHERE, EMPNO=102; | row updated. SQL> SELECT * FROM EMP; EMPNO ENAME DESIGNATION SALARY 101 [NAGARAJAN LECTURER [16000 102 [SARAVANANIASST. PROF [16000 103 |SELVAM__[ASST. PROF [20000 os |CHINNI [Hop,PROF _ [45000 DELETE QUERY: 06 QS. Write a query to delete records from employee. Syntax for delete Records from the table: SQL> DELETE WHERE = DELETE EMP WII MPNO=103; 1 row deleted. SQL> SELECT * FROM EMP; EMPNO ENAME DESIGNATION SALARY TO _ [NAGARAJAN [LECTURER [16000 102__ [SARAVANAN|ASST. PROF [16000 104 [SARAVANAN|Hop, PROF __ [15000 Thus the query for executing DDL and DML command in RDBMS was executed successfillly. EX.No.2 CRE. E A SET OF TABLES,ADD CONSTRAINTS AND INCORPORATE REFERENTIAL INTEGRITY AIM: To create a Constraints are part of the table definition that limits and restriction on the valueentered into its columns. TYPES OF CONSTRAINTS: Primary key Foreign key/references Check Unique Not null Null Default CONSTRAINTS CAN BE CREATED IN THREE WAY! 1- Column level constraints 2- Table level constraints 3+ Using DDL statements-alter table command OPERATION ON CONSTRAINT: 1- ENABLE 2- DISABLE 3. DROP. NOT NULL CONSTRAINTS: SQL> create table stud(rollno number(5) not null,studname varchar2(10),dob date, joiningyear number(5),dept varchar2(5)); Table created. SQL> insert into stud values(101 'akash’,'21-jul-1999'2017,'ese’); 1 row created. SQL> insert into stud values(",'ram,'22-aug-1999,2017,'e insert into stud values(",'ram’22-aug-1999',2017,'eee’) ERROR at line 1: ORA-01400: cannot insert NULL into ("CSE132"."STUD"."ROLLNO" % DEFAULT CONSTRAINT: SQL> create table stud3(rollno number(5),studname varchar2(10),joiningyear number(5)default10,dept varchar2(5)); Table created, SQL> insert into stud3(rollno,studname,dept)values(108,'divyal eve’); 1 row created SQL> insert into stud3(rollno,studname,dept)values(117,'ramya','eee'); 1 row created. SQL> select * from stud3; ROLLNO STUDNAME JOININGYEAR DEPT 108 divya 10 ece 7 ramya 10 eee CHECK CONSTRAINT: SQL> create table stud4(rollno number(5) not null,studname varchar2(10),joiningyear number(5)default 10,dept varchar2(5),age number(5)check (age17)); Table created SQL> insert into stud4 (rollno,studname,dept,age)values(170,'sivani'eee’,17); SQL> insert into stud4(rollno,studname,dept,agevalues( 140,'shruthi’eee’,19); insert into stud4(rolino,studname,dept,age)values(140,'shruthi'eee’,16) ERROR at line I: ORA-02290: check constraint (CSE132.SYS_C0012437) violated L QU TRAINT: SQL> create table stock 1 (itemno number(5)unique,itemname varchar2(10)not null,qu quantity number(5)); Table created SQL> insert into stock! values(|11,'pendrive'15); 1 row created. SQL> select * from stock]; ITEMNO ITEMNAME QUANTITY 111 pendrive 15 SQL> insert into stock1 values(111,'ed',20); insert into stock1 values(111,'ed',20) ERROR at line 1: ORA-00001: unique constraint (CSE132.SYS_C0012501) violated PRIMARY KI SQL> create table stock3(itemno number(5)primary key ,itemname varchar2(10)); Table created. SQL> insert into stock3 values(",'pendrive’); 1s insert into stock3 values(",'pendrive') ERROR at ine 1: ORA-01400: cannot insert NULL into ("CSE132"."STOCK3"."ITEMNO") SQL> insert into stock3 values('3'/ed’); 1 row created. SQL> insert into stock3 values(’3'/dvd"); insert into stock3 values('3','dvd') ERROR at line 1 ORA-00001: unique constraint (CSE132.SYS_C0012551) violated FOREIGN KEY: SQL> create table stock4(itemno number(5)references stock3(itemno),price number(5)); ‘able created. SQL> insert into stock4 values(3,100); 1 row created. SQL> select * from stock4; ITEMNO PRICE 3 100 SQL> insert into stock4 values(2,100); Insert into stock4 values(2,100) ERROR at line 1: ORA-02291: integrity constraint (CSE132.SYS_C0012562) violated - parent key notfound RESULT: Thus the constraints for the given query are verified and executed Successfully. EX.NO.3 Query the database Table using different ‘where’ clause conditions and also implement aggregate functions AIM: To practice Queries using Aggregate functions, Group By, Having Clause and Order Clause. Group Functions: ‘A group functions retums a result based on a group of rows. Some of these are just purelymathematical functions. The group functions supported by Oracle are summarized below: (Queries using aggregatefunctions{COUNT,AVG,MIN,MAX,SUM),Group by,Order by, Having, E_name ‘Age Salary, 101 Anu 2 9000 102 Shane 29 8000 103 Rohan’ 34 6000 104 Scott a 10000 105 Tiger 35 8000 106 lex 27 7000 107 [Abhi 29 8000 (@ Create Employee table containing all Records. SQL> create table emp(eid number,ename varchar2(10),age number,salary number); Table created SQL> dese emp; Name Null? Type EID NUMBER ENAME VARCHAR2(10) AGE NUMBER SALARY NUMBER (i) Count number of employee names from employee table, sq select count(ename) from emp; COUNT(ENAME) i)Find the Maximum age from employee table. SQL> select max(age) from emp; MAX(AGE) 44 (iy) Find the Minimum age from employee table. SQL> select min(age) from emp; MIN(AGE) 2 (s)Display the Sum of age employee table. SQL> select sum(age) from emp; SUM(AGE) 220 (viDisplay the Average of age from Employee table. SQL> select avg(age) from emp; AVG(AGE) 31.4285714 (vii)Create a View for age in employee table. SQL> create or replace view A as select age from emp where age<30; View created. (viii) Display views SQL> select * from A; AGE 22 29 21 29 (i) Find grouped salaries of employees.(group by clause) SQL> select salary from emp group by salary; SALARY 9000 10000 8000 6000 7000 (x) .Find salaries of employee in Ascending Order.(order by clause) SQL> select ename,salary from emp order by salary; ENAME SALARY rohan | 6000 7000 8000 abhi_|8000 tiger [8000 anu_ {9000 scott [10000 Trows selected, (xi) Find salaries of employee in Descending Order. SQL> select ename,salary from emp order by salary dese; scott 10000) anu 9000 shane 8000 abhi 8000 tiger 8000 alex 7000 rohan 6000 7 rows selected. (aii)Having Clause. SQL> select ename,salary from emp where age<29 group by cename,salary havingsalary<10000; NAME — SALARY alex 7000 anu 9000 Result: Thus query the database tables using where clause clause conditions and also implement aggregate fu ction was executed successfully. EX.Noda QUERY THE DATABASE TABLE AND EXPLORE NESTED QUERIES AIM To execute and verify the SQL commands for Nested Queries. OBJECTIVE: Nested Query can have more than one level of nesting in one single query. A SQL nested query is a SELECT query that is nested inside a SELECT, UPDATE, INSERT, or DELETE SQL query. PROCEDURE STEP 1: Start STEP 2: Create two different tables with its essential attributes. STEP 3: Insert attribute values into the table. STEP 4: Create the Nested query from the above created table. STEP 5: Execute Command and extract information from the tables. STEP 6: Stop SQL COMMANDS 4, COMMAND NAME: SELECT COMMAND DESCRIPTION: SELECT command is used to select records from the table. 5. COMMAND NAME: WHERE COMMAND DESCRIPTION: WHERE command is used to identify particular elements. 6. COMMAND NAME: HAVING: COMMAND DESCRIPTION: HAVING command is used to identify particular elements 7. COMMAND NAME: MIN (SAL) COMMAND DESCRIPTION: MIN (SAL) command is used to find minimum salary. Table-1 SYNTAX FOR CREATING A TAB SQL: CREATE (COLUMN NAME.1 (SIZE), COLUMN NAME.1 (SIZE). rneenen) SQL> CREATE TABLE EMP2| IPNO NUMBER(S), ENAME VARCHARQ(20), JOB VARCHAR2(20), SAL NUMBER(6), MGRNO NUMBER(4), DEPTNO NUMBER()); SYNTAX FOR RT RECORI INTO A TABLE: SQL > INSERT INTO
VALUES< VALI, ‘VAL2’,.. INSERTION SQL> INSERT INTO EMP2 VALUI 1 ROW CREATED. SQL> INSERT INTO EMP2 VALUES(1002,MANOJ\’TESTER', 12000,1560,200); 1 ROW CREATED. '$(1001,MAHESII,PROGRAMMER’15000,1560,200); SQL> INSERT INTO EMP2 VALUES(1003,KARTHIK',PROGRAMMER’,13000,1400,201); 1 ROW CREATED. SQL> INSERT INTO EMP2 VALUES(1004,NARESH?,/CLERK’,1400,1400,201); 1 ROW CREATED. SQL> INSERT INTO EMP2 VALUES(1005,MANI’TESTER',13000,1400,200); 1 ROW CREATED. SQL> INSERT INTO EMP2 VALUES(1006,'VIKI, DESIGNER’, 12500,1560,201); 1 ROW CREATED. SQL> INSERT INTO EMP2 VALUES(1007)MOHAN' DESIGNER’, 14000,1560,201); 1 ROW CREATED. SQL> INSERT INTO EMP2 VALUES(1008,'NAVEEN’/CREATION,,20000,1400,201);, 1 ROW CREATED, SQL> INSERT INTO EMP2 VALUES(1009, PRASAD',DIR',20000,1560,202); 1 ROW CREATED. SQL> INSERT INTO EMP2 VALUES(1010,AGNESH?,'DIR’,15000,1400,200); 22 1 ROW CREATED. SYNTAX FOR f SQL> SELECT * FROM
; SQL> SELECT *FROM EMP2; EMPNO ENAME JOB SAL MGRNO DPTNO 1001 MAHESH PROGRAMMER 15000 1560 200 1002 MANOJ TESTER 12000 1560 200 1003 KARTHIK PROGRAMMER 13000 1400-201 1004 NARESH CLERK 1400 1400-201 1005 MANI 13000 1400-200 1006 VIKI DESIGNER 12500 1560 01 1007 MOHAN DESIGNER 140001560201 1008 NAVEEN CREATION 20000 1400-201 1009 PRASAD DIR 200001560201 1010 AGNESH DIR 15000 1400201 TABLE-2 SYNTAX FOR CREATING A BLE: SQL: CREATE (COLUMN NAME.1 (SIZE), COLUMN NAME.1 (SIZE) SQL> CREATE TABLE DEPT2(DEPTNO NUMBER(3), DEPTNAME VARCHARQ(10), LOCATION VARCHARQ(15)); Table created. SQL => INSERT INTO
VALUES< VALI, ‘VAL2?,....)5 INSERTION SQL> INSERT INTO DEPT2 VALUI 1 ROW CREATED. SQL> INSERT INTO DEPT2 VALUES(201,,DEBUG'/UK’); 1 ROW CREATED. S(107,,DEVELOP'ADYAR’); SQL> INSERT INTO DEPT2 VALUES(200,TEST,'US); SQL> INSERT INTO DEPT2 VALUES(201,'TEST,'USSR’); 1 ROW CREATED. SQL> INSERT INTO DEPT2 VALUES(108,DEBUG''ADYAR)); 1 ROW CREATED. SQL> INSERT I 1 ROW CREATED. SYNTAX FOR SELECT RECORDS FROM THE TABLE: SQL> SELECT * FROM
; SQL> SELECT *FROM DEPT2; DEPTNO DEPTNAME LOCATION 107 DEVELOP = ADYAR 201 DEBUG UK 200‘ TEST us 201 TEST USSR 108 DEBUG ADYAR 109 BUILD POTHERI 6 rows selected, GENERAL SYNTAX FOR NESTED QUERY: SELECT "COLUMN_NAME!" FROM "TABLE_NAME1" WHERE "COLUMN_NAME2" [COMPARISON OPERATOR] (SELECT "COLUMN_NAME3" FROM "TABLE_NAME2" WHERE [CONDITION)) SYNTAX NESTED QUERY STATEM SQL> SELECT FROM FRORM
WHERE *VALUE” 2a (SELECT (AGGRECATE FUNCTION) FROM WHERE = ‘ALUE? (SELECT FROM WHERE SELECT ENAME FROM EMP2 WHERE SAL>(SELECT MIN(SAL) FROM EMP2 WHERE DPTNO=(SELECT DEPTNO FROM DEPT2 WHERE LOCATION='UK')); Nested Query Output: ENAME MAHESH MANOJ KARTHIK MANI VIKI MOHAN NAVEEN PRASAD AGNESH RESULT: Thus to query the database of Nested queries was verified and executed successfully. Query the database table using Join operations AIM: To execute and verify the SQL commands using Join queries, OBJECTIVE: SQL joins are used to query data from two or more tables, based on a relationshipbetween certain columns in these tables, PROCEDURE STEP 1: Start STEP 2: Create the table with its essential attributes. STEP 3: Insert attribute values into the table STEP 4: Execute different Commands and extract information from the table. STEP 5: Stop SQL COMMANDS COMMAND NAME: INNER JOIN COMMAND DESC! IPTION: The INNER JOIN keyword return rows when there is at least one match in both tables. COMMAND NAME LEFT JOIN COMMAND DESCRIPTION: The LEFT JOIN keyword retums all rows from the left table (table_namel), even if there are no matches in the right table (table_name2). COMMAND NAME : RIGHT JOIN COMMAND DESCRIPTION: The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_namel), COMMAND NAME : FULL JOIN COMMAND DESCRIPTION: The FULL JOIN keyword return rows when there is a match in one of the tables, LEFT JOIN or LEFT OUTER JOIN ORDERS E table orders(O_Id number(5),Orderno number(5),P_Id number(3)); ‘Table created. SQL> DESC orders; Name Null? Type oD NUMBER(S) ORDERNO NUMBER(S) PID NUMBERG) INSERTING VALUES INTO ORDERS SQL> INSERT into orders values(&O_Id,&Orderno,&P_Id); Enter value for o_id: 1 Enter value for ordemo: 77895 Enter value for p_id: 3 old 1: INSERT into orders values(&O_Id,&Orderno,&P_Id) new I: INSERT into orders values(1,77895,3) 1 row created, SQL> INSERT into orders values(&O_Id,&Orderno,&P_Id); Enter value for o_id: 2 Enter value for ordemo: 44678 Enter value for p_id: old 1: INSERT into orders values(&O_Id,&Orderno,&P_Id) new 1: INSERT into orders values(2,44678,3) | row created. SQL> INSERT into orders values(&O_Id,&Orderno,&P_Id); Enter value for o_id: 3 Enter value for Enter value for ordemo: 22456Enter value for p_id: 1 old 1: INSERT into orders values(&O_Id,&Ordemo,&P_Id) new 1: INSERT into orders values(3,22456,1) L row created, SQL> INSERT into orders values(&O_Id,&Orderno,&P_Id); Enter value for o_id: 4 Enter value for ordemo: 24562 Enter value for p_id: 1 old 1: INSERT into orders values(&O_Id,&Orderno,&P_Id) new 1: INSERT into orders values(4,24562,1) | row created, SQL> INSERT into orders values(&O_Id,&Orderno,&P_Id); Enter value for o_id: 5 Enter value for ordemo: 34764 old 1: INSERT into orders values(&O_Id,&Orderno,&P_Id)new 1: INSERT into orders values(5,34764,15) | row created. TABLE SECTION: SQL> Ss ECT * FROM orders; OID ORDERNO P_ID T [77895 3 2 | 44678 3 3 | 22456 1 4 | 24562 1 5_| 34764 15 TABLE -2: PERSONS SQL> CREATE table persons(p_Id number(5),LASTNAME varchar2(10), Firstname varchar2(15), Address varchar2(20),city varchar2(10)); Table created. SQL> INSERT into persons Enter value for p_id: 1 Enter value for lastname: Hansen Enter value for firstname: Ola Enter value for address: Timoteivn 10 Enter value for city: sadnes old 1: INSERT into persons values(&p_Id,'SLastname! firstname’ /&Address'/&city’) new 1: INSERT into persons values(1,'Hansen' Ola’, rimoteivn 10'/sadnes') 1 row created. SQL> INSERT into persons values(&p_Id,'&Lastname’ '& firstname’ 'S& Address’ &city’); Enter value for p_id: 2 Enter value for lastname: SvendsonEnter value for firstname: Tove Enter value for address: Borgn 23 Enter value for city: Sandnes old 1: INSERT into persons values(&p_Id,'&Lastname’,'& firstname’ '&Address' Sccity’) new 1: INSERT into persons values(2,'Svendson','Tove','Borgn 23',Sandnes’) 1 row created SQL> INSERT into persons values(&p_Id,'&Lastname' '&firstname’,'& Address’ &city’); Enter value for p_id: 3 Enter value for lastname: Pettersen Enter value for firstname: Kari Enter value for address: Storgt 20 Enter value for city: Stavanger old 1: INSERT into persons values(&p_Id,'&Lastname’,'&firstname’&Address'&city’) new 1: INSERT into persons values(3,'Pettersen’,’Kari'/Storgt 20'/Stavanger’) 1 row created. SQL> SELECT * FROM persons; PID LASTNAME FIRSTNAME ADDRESS CITY 1 fAansen ta JFimoteivn 10 fandnes 2 |Svendson [Tove IBorgn 23 [Sandnes 3 Pettersen ari IStorgt 20 {Stavanger LEFT JOIN SYNTAX SQL> SELECT column_name(s) FROM table_namel LEFT JOIN table_name2 ON table_name!.column_name=table_name2.column_name LEFT JOIN EXAMPLE SQL> SELECT persons.lastname, persons firstname, orders.orderno FROM persons LEFT JOIN orders ON persons.p_Id = orders.p_Id ORDER BY persons.lastname; ourPUT LASTNAME FIRSTNAME —ORDERNO- Hansen Ola 72456] Hansen Ola 24562| Pettersen Kari 71895 30 Pettersen Kari 44678 Svendson Tove 53423 FULL OUTER JOIN SQL> SELECT * FROM persons; P_IDLASTNAME FIRSTNAME ADDRESS crry T ] Hansen Ola Timoteivn 10 | sandnes 2 | Svendson | Tove Borgn 23 Sandnes 3_| Pettersen Kari Storgt 20 Stavanger SQL> SELECT * FROM orders; 01D ORDERNO PID 1 77895 3 2 44678 3 3 22456 L 4 24562 L Ss 34764 15 FULL OUTER JOIN S' SQL>SELECT column_name(s) FROM table_namel FULL JOIN table_name2 ON table_namel.column_name-table_name2.column_name FULL OUTER JOIN EXAMPLE SQL> SELECT persons lastname,persons. firstname,orders.ordemoFULL OUTER JOIN orders ON persons.p_Id ~ orders.p_I4ORDER BY persons. lastname; RIGHT OUTER JOL RIGHT OUTTER JOIN SYNTAX SQL>SELECT Persons.LastName, Persons.FirstName, Orders.OrderNoFROM Persons RIGHT JOIN Orders ON Persons.P_Id=Orders.P_Id ORDER BY Persons.LastName RIGHT OUTTER JOIN EXAMPLE SQL>SELECTpersons lastname,persons.firstname,orders.ordemo FROM personsRIGHT OUTER JOIN orders ON persons.p_Id orders.p_I4ORDER BY persons.lastname; LASTNAME FIRSTNAME —ORDERNO Hansen Ola 24562 Hansen Ola 22456 Pettersen Kari 44678 Pettersen Kari T1895 INNER JO} INNTER JOIN SYNTAX SQL> SELECT column_name(s) FROM table_namel INNER JOIN table_name2 ON table_namel.column_name=table_name2,column_name INNTER JOIN EXAMPLE SQL> SELECT persons.lastname, persons firstname, orders.orderno 2. FROM persons 1 IR JOIN orders, 2. ON persons.p_Id = orders.p_Id 5 ORDER BY persons.lastname; LASTNAME FIRSTNAME ORDERNO Hansen Ola 22456 Hans Ola 24562 Pettersen Kari 71895 Pettersen Kari 44678 Hansen Ola 22456 Hansen Ola 24562 Pettersen Kari 77895 Pettersen Kari 44678 Svendson Tove 34764 RESULT: Thus to query the database using join operations was verified and executed successfully. 33 Ex.No.5 Query the database tables and explore natural, equi and cross joins AIM: To query the database tables and explore natural join,equi join and cross join OBJECTIVE: SQL joins are used to query data from two or more tables, based on a relationshipbetween certain columns in these tables. PROCEDURE STEP 1: Start STEP 2: Create the table with its essential attributes. STEP 3: Insert attribute values into the table STEP 4: Execute different Commands and extract information from the table. STEP 5: Stop JOU SQL> select * from stud,marks where stud.rollno=marks.rollno; ROLLNO STUDNAME DEPT ROLLNO MARKS CGPA 101 1 SQL> select * from stud,marks where stud.rollno<=marks.rollno; ROLLNO STUDNAME DEPT ROLLNO MARKS = CGPA 101 harini ese 101 1 8 101 harini ese 103 89 9 102 priya ese 103 89 9 SQL> select * from stud s,marks m where s.rollno=m.rollno; ROLLNO STUDNAME DEPT ROLLNO MARKS — CGPA 101 harini ese 101 1 8 34 INNER JO} SQL> select * from stud inner join marks on stud.rollno=marks.rollno; ROLLNO STUDNAME DEPT ROLLNO MARKS CGPA 101 harini ese 101 7 8 NATURAL JOIN: SQL> select * from stud natural join marks; ROLLNO STUDNAME DEPT MARKS CGPA 101 harini c 1 CROSS JOINS: SQL> select * from stud cross join marks; ROLLNO STUDNAME DEPT ROLLNO MARKS — CGPA 101 harini ese 101 1 8 101 harini ese 103 89 9 102 priya cse 101 1 8 102 priya ese 108 89) 9 SOL OPERATORS SQL> select * from stock1; SNOSNAME ITEM 4 ek pen 7 kkk pen 12 gk pen 12 kk pen SQL> select #from stock] where sname='gk'; SNOSNAME ITEM 4 gk pen 12. gk pen SQL> select *from stock! where sname 3s SNO SNAME ITEM 7 kkk pen 12 kk pen SQL> select *from stock where sno> 7; SNOSNAME — ITEM 12. gk pen 12 kk pen SQL> select *from stock! where sno>= 7 and sname~'gk'; SNOSNAME ITEM 12 gk pen SQL> select *from stock! where sno>= 7 or sname='gk'; SNOSNAME ITEM 4 sk pen 7 kkk pen 2 sk pen 2 kk pen SQL> select *from stock] where (sno>= 7 and sname~gk’) or (item=pen'); SNOSNAME ITEM 4 gk pen 7 kkk pen 12 gk pen 12 kk pen SQL> select *from stock! where (sno>= 7 and sname='gk') order by item; SNOSNAME ITEM 12 gk pen SQL> select all sno from stock! where sname=kKl SNO. 36 SQL> select distinct sno from stock! where sname=' SNO. SQL> select * from stock! where sname in('gk'’kKk’); SNO SNAME ITEM 4 sk pen 7 kkk pen 12 gk pen SQL> select * from stock! where sname not in('gk’ kkk"); SNOSNAME ITEM 12 kk pen SQL> select * from stock! where sname <> 'gk'; SNOSNAME ITEM 7 kkk pen 12. kk pen SQL> select * from stock1 where sname <> ‘null’; SNOSNAME ITEM 4 ¢k pen 7 kkk pen 12 gk pen 12 kk pen SQL> select * from stock! where sname is null; no rows selected SQL> select * from stock! where sname is not null; SNOSNAME ITE} 4 gk pen 7 kkk pen ek pen 12 kk pen 31 SQL> select * from stock! where sname like 'k%"; SNO SNAME ITEM 7 kkk pen 12 kk pen SQL> select * from stock where sname not like 'k%'; SNOSNAME ITE! 4 ak pen 12 gk pen SQL> select *from stock4; SNOSNAME ITEM AGE 6 ff watch 9 7 gee hhh 10 7 eee hhh 20 7 gee hhh 2 SQL> select item from stock4 where sname like 'f_%_%'; ITEM Watch SQL> select * from stock4 where age between 10 and 22; SNOSNAME ITEM AGE 7 ggg hhh 10 7 ges bhh 20 7 hhh 2 Alias Column SQL> select sno as stno from stock4; STNO 6 7 7 3 38 ANY SQL> select * from stock4; SNOSNAME ITEM AGE 6 fff — watch 9 7 gee hhh 10 7 gee hhh 20 7 seg hhh 2 SQL> select * fiom stock!; SNO SNAME_ ITEM 4 gk pen 7 kkk pen 120 gk pen 12 kk pen SQL> select sno,sname from stock4 where sno=any(select sno from stock] where sno= SNO SNAME, 7 gee 7 gee Some SQL> select sno,sname from stock4 where sno=some(select sno from stock! where sn 0=7); UNI SQL> select sname from student union select name from railway; SNAME max melvina sarah selvi sophia stella 6 rows selected. INTERSECT: SQL> select sname from student intersect select name from railway; SNAME RESULT: Thus query the database tables and explore natural,equi and outer join was executed successfilly. 40 EX.No.6 Write user defined functions and stored procedures in SQL AIM To write a Functional procedure to search an address from the given database. PROCEDURE STEP 1: Start STEP 2: Create the table with essential attributes. STEP 3: Initialize the Function to carryout the searching procedure. 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 SETTING SERVEROUTPUT ON: SQL> SET SERVEROUTPUT ON; 1) PROGRAM SQL> create table phonebook (phone_no number (6) primary key,userame varchar2(30),doorno varchar2(10),street varchar2(30),place varchar2(30),pincode char(6)); Table created. SQL> insert into phonebook values(20312,'vijay'120/SD'bharathi street! NGO colony’,'629002'); | row created, SQL> insert into phonebook values(29467,'vasanth’,'39D4'’RK bhavan','sarakkal vilai''629002"); 4 1 row created. SQL> select * from phonebook; PHONE_NO USERNAME DOORNO STREET PLACE —PINCODE 20312 vijay 120/SD —_bharathi street. NGO colony 629002 29467 vasanth — 39D4 RK bhavan —_sarakkal vilai_ 629002 SQL> create or replace function findAddress(phone in number) return varchar2 asaddress varehar2(100); begin select usernamel},'|doorno |),|street |||[place|!,'|pincode into address from phonebookwhere phone_no=phone; return address; exception When no_data_found then return ‘address not found’; end; / Function created. SQL>declare 2 address varchar2(100); 3 begin 4 address:=findaddress(20312); 5 dbms_output.put_line(address); 6 end; TI OUTPUT I: Vijay,120/5D,bharathi street, NGO colony,629002PL/SQL procedure successfully completed. SQL> declare 2 address varchar2(100); begin address:—findaddress(23556); dbms_output put_line(address); end; / anne OUTPUT2: Address not found PL/SQL procedure successfully completed. a2 PROCEDURES AIM To write a PL/SQL block to splay the student name, marks whose average mark is above 60%, ALGORITH! STEPI:Start STEDP2:Create a table with table name stud_exam, STEP3:Insert the values into the table and Calculate total and average of each studentSTEP4: Execute the procedure funetion the student who get above 60%. STEPS: Display the total and average of studentSTEP6: End EXECUTION SETTING SERVEROUTPUT ON: SQL> SET SERVEROUTPUT ON 1. PROGRAM: PROCEDURE USING POSITIONAL PARAMETER: SQL> SET SERVEROUTPUT ON SQL> CREATE OR REPLACE PROCEDURE PROC] AS. 2BEGIN 3 DBMS_OUTPUT.PUT_LINE(Hello from procedure..."); 4END; 5 Output: Procedure created. SQL> EXECUTE PROCI Hello from procedure. PL/SQL procedure successfully completed. 43 2, PROGRAM: PROCEDU. jOTATIONAL PARAMETERS SQL> CREATE OR REPLACE PROCEDURE PROC2 2(N1 IN NUMBER,N?2 IN NUMBER, TOT OUT NUMBER) IS3BEGIN 4TOT :=N1 +N2; SEND; 6 Output: Procedure created. SQL> VARIABLE T NUMBERSQL> EXEC PROC2(33,66,:T) PL/SQL procedure suecessfully completed SQL> PRINT T T 99 PROCEDURE FOR GCD NUMBERS PROGRAM: SQL> create or replace procedure prois a number(3); bnumber(3); c number(3); dnumber(3); begin a:=&a; b:=&b; if(a>b) then e:=mod(a,b); iff(c=0) then dbms_output.put_line(GCD is'); dbms_output.put_line(b); else dbms_output-put_line(’GCD is’; dbms_output.put_line(e); 44 end ifjelse -=mod{(b,a); if(d=0) then dbms_output.put_line(‘G dbms_output.put_line(a); else dbms_output.put_line('GCD is’); set serveroutput on;SQL> execute pro; GCD is 8 PL/SQL procedure successfully completed. PROCEDURE FOR CURSOR IMPLEMENATION PROGRA! SQL> create table student(regno number(4),name varchar2)20),mark1 number(3), mark2number(3), mark3 number(3), mark4 number(3), mark5 number(3)); Table created SQL> insert into student values (101,'priya’, 78, 88,77,60,89); 1 row created. SQL> insert into student values (102,'surya’, 99,77,69,81,99); 1 row created. SQL> insert into student values (103,'suryapriya’, 100,90,97,89,91); 1 row created. SQL> select * from student; Regno name — markl = mark2._—mark3_mark4- mark5 [101 priya 78_| 88 7 | 60 | 89 102 fury. 9977 [81 99 1103 suryapriya | 100 [90 o7_[ 89 | 91 SQL> declare ave number(5,2):tot number(3); cursor ¢_mark is select*from student where mark: andmark3>=40 and mark4>=40 and mark5>=40; begin dbms_output.put_line('regno name mark mark2 mark3 mark4 mark4 markS totalaverage’); dbms_output.put_line( ; for student in c_markloop tot:=student.mark + student. mark2++student.mark3 +student.mark4+tstudent.mark: ave:tot/5; dbms_output.put_line(student.regno||rpad(student.name, 15) \[ppad{student.mark 1,6)|rpad{student.mark2,6))jppad(student.mark3,6) \lspad(student.mark4,6)jspad(student.mark5,6))rpad(tot,8)|rpad(ave,5)) end loop; end; / SAMPLE OUTPUT 40 and mark2>=40 tegno name — mark mark2 mark3 mark4 markS total average lol priya 78 88 77 60 89 393 79 102 surya 99 77 69 81 99 © 42585 103 suryapriya 100 90 97 89 91 46793 PL/SQL procedure successfully completed. Result: ‘Thus the user defined functions and stored procedures in SQL was verified and executed successfully. 46 Ex.No.7 Execute Complex transac AIM: To execute Complex transactions and realize DCL and TCL commands PROCEDURE STEP 1: Start STEP 2: Create the table with its essential attributes. STEP 3: Execute different Commands and extract information from the table, EP 4: Stop DCL (DATA CONTROL L. 'UAGE) DCL a Data Control Language Its commands are responsible for access restrictions inside of the database. Let’s take a look at DCL statements definitions. GRA! GRANT command gives permissions to SQL user account. For example, I want to grant all privileges to ‘explainjava’ database for user ‘dmytro@localhost’ Let's create a user first CREATE USER ‘dmytro'@'localhost' IDENTIFIED BY '123'; Then I can grant all privileges using GRANT statement: GRANT ALL PRIVILEGES ON explainjava.* TO ‘dmytro'@'localhost and we have to save changes using FLUSH command: FLUSH PRIVILEGES; a7 REVOKE: REVOKE statement is used to remove privileges from user accounts. Example: REVOKE ALL PRIVILEGES ON explainjava.* FROM ‘dmytro'@'localhost’; and save changes’ FLUSH PRIVILEGES; CREATING A USER SQL>CONNECT SYSTEM/MANAGER; SQL>CREATE USER "USERNAME" IDENTIFIED BY "PASSWORD" SQL>GRANT DBA TO "USERNAME" SQL>CONNECT "USERNAME""PASSWORD”; EXAMPLE CREATING A USER SQL>CONNECT SYSTEM/MANAGER; SQL>CREATE, USER CSE2 IDENTIFIED BY CSECSE;SQL>GRANT DBA TO CSE2; SQL>CONNECT CSE2/CSECS| SQL>REVOKE DBA FROM CSE2; DRL-DATA RETRIEVAL IMPLEMENTING ON. SQL> select * from emp; ‘COMMANDS EMPNO ENAME, JOB HIREDATE SAL DEPTNO 17369 SMITH CLERK 902 17-DEC-80 800 2000 77499 |ALLEN SALESMAN 17698 20-FEB-81 [1600 3000 521 /ARD SALESMAN [7698 22-FEB-81___[1250 5000 566 JONES MANAGER _ [7839 02-APR-81 975 2000 48 4 rows selected. SQL> select empno,ename,sal fromemp; EMPNO ENAME SAL 7369 |SMITH 800 [7499 [ALLEN _|1600 7521 [WARD _ [1250 [7566 [JONES 2975 SQL>select ename,job,sal,deptno from emp where sal not between 1500 and 5000; [ENAME OB SAL DEPTNO. SMITH [CLERK 800 20 WARD SALESMAN 1250 30, MARTIN SALESMAN 1250 30 [ADAMS SCERK 1100 20 [AMES [CLERK 950 30 MILLER (CLERK 1300 10 6 rows selected, SQL> select empno,ename,sal from emp where sal in (80,5000); IEMPNOJENAME [SAL 7369 | SMITH 00 7839 | KING [5000 SQL> select empno,ename,sal from emp where comm is null; EMPNO ENAME SAL 7369__|SMITH 00 7566 [JONES 22975 7698 [BLAKE _ P2850 7782__ [CLARK __P450 7788__|SCOTT _ [5000 7839__|KING [5000 7876 [ADAMS _ |I100 7900 [JAMES [950 7902 |FORD [5000 7934 [MILLER {1300 10 rows selected. SQL> select empno,ename,sal from emp where comm is not null; EMPNO ENAME SAL 7499 |ALLEN {1600 7521__|WARD __|I250 7654 [MARTIN [1250 7844 [TURNER [1500 SQL> select empno,ename,job,sal from emp where ename like'S%'; EMPNO ENAME JOB SAL. 7369|SMITH_ | CLERK 800 TIssSCOTT | ANALYST [3000 SQL> select empno,ename,job,sal from emp where job not like'S%'; EMPNO ENAME JOB SAL. 7369_(smirH _|cterK 800 | 7566 [JONES MANAGER | 2975 7698 [BLAKE [MANAGER | 2850 CLARK [MANAGER 2450 7788 |SCOTT [ANALYST [| 3000 SQL> select ename,job,sal from emp where sal>2500: JONES MANAGER 975 BLAKE [MANAGER _ 2850 SCOTT [ANALYST _ 000 KING [PRESIDENT 5000 FORD [ANALYST 000 SQL> select ename,job,sal from emp where sal<2500; ENAME JOB SAL. SMITH [CLERK [800 [ALLEN [SALESMAN _|I600 WARD SALESMAN _[1250 MARTIN SALESMAN _ [1250 [CLARK [MANAGER _ 2450 TURNER SALESMAN _ [1500 ADAMS [CLERK [L100 JAMES [CLERK 950 MILLER [CLERK 1300 9 rows selected, SQL> select empno,ename,job,sal from emp order by sal; ENO ENAME JOB SAL. 7369 SMITH _|CLERK [300 "7900 JAMES _|CLERK 950 7876 ADAMS |CLERK 100 7521 WARD_SALESMAN_|1250 7654 MARTIN SALESMAN _|I250 7934 MILLER |CLERK 1300 7844 TURNER|SALESMAN _|1500 7499 ALLEN [SALESMAN _|1600 7782 CLARK [MANAGER _ 2450 7698 BLAKE [MANAGER 2850 7566. JONES [MANAGER _ 2975 7788 SCOTT [ANALYST __B000 7902FORD [ANALYST $000 7839 KING [PRESIDENT 5000 14 rows selected SQL> select empno,ename,job,sal from emp order by sal des PNO. ENAME JOB SAL. 839 |KING PRESIDENT |s000 788 [SCOTT NALYST _ 3000 902 FORD ANALYST _ 3000 [7566 JONES [ANAGER 2975 698 [BLAKE MANAGER 2850 782 (CLARK |ANAGER _ R450 499 |ALLEN SALESMAN [1600 844 [TURNER ALESMAN [1500 934 MILLER. CLERK S21 [WARD ALESMAN 654 MARTIN SALESMAN 876 [ADAMS SLERK 7900__|TAMES [CLERK 369__ SMITH [CLERK L(TRNSACTI CONTROL LANGUAG TCL is a Transaction Control Language. Its commands are used to manage transactions in SQL. databases, This is TCL commands list: START TRANSACTION (BEGIN, BEGIN WORK) START TRANSACTION is used to start a new SQL transaction, BEGIN and BEGIN WORK ate aliases for START TRANSACTION, Example: START TRANSACTION; after that, you're doing manipulations with a data (insert, update, delete) and at the end, you need to commit a transaction. COMMIT Asa mentioned above COMMIT command finishes transaction and stores all changes made inside of a transaction Example: START TRANSACTION; INSERT INTO student (name, lastname) VALUES (‘Dmytro’, ‘Shvechikov’); COMMIT; ROLLBACK ROLLBACK statement reverts all changes made in the scope of transaction. Example: START TRANSACTION; INSERT INTO student (name, lastname) VALUES (‘Dmytro’, ‘Shvechikov'); ROLLBACK. SAVEPOINT: QUERY: 07 Write a query to implement the save point. ntax for save point: SQL> SAVEPOINT ; QUERY: 07 SQL> SAVEPOINT S1; Savepoint created. sal EMPNO ENAME — DESIGNATIN 101 [NAGARAJAN]LECTURER [16000 102 |SARAVANAN|ASST. PROF |16000 104 |CHINNI HOD, PROF [45000 BLECT * FROM EMP; ALARY, SQL> INSERT INTO EMP VALUES(105,PARTHASAR'STUDENT',100); | row created, SQL> SELECT * FROM EMP; EMPNO ENAME DESIGNATION SALARY TOI [NAGARAIAN [LECTURER [16000 102 [SARAVANAN [ASST. PROF __ [16000 104 [CHINNI HOD, PROF __ [45000 ROLL BACK QUERY: 08 QS. Write a query to implement the Rollback. Syntax for save point: SQL> ROLL BACK ; QUERY: 18 SQL> ROLL BACK S1; Rollback complete. SQL> SELECT * FROM EMP; EMPNO — ENAME, DESIGNATIN SALARY 101 _[NAGARATAN LECTURER [16000 102 [SARAVANAN SST. PROF _ [16000 103 |PANNERSELVAM |ASST.PROF [20000 104 |CHINNI Hop,PROF __ {45000 COMMIT QUERY: 09 Syntax for commit: SQL> COMMIT; QUERY: 9 SQL> COMMIT; Commit complete. RESULT: Thus the query to execute tran: executed successfully. EX.No.8 Write SQL Triggers for Insert,delete and update operations in a database table 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 beexecuted STEP 4: Execute the Trigger procedure for both Before and Afier sequences STEP 5: Carryout the operation on the table to check for Trigger execution. STEP 6: Stop EXECUTION 1. Create a Trigger to pop-up the DML operations SQL> create table empa(id number(3),name varchar2(10),income number(4),expencenumber(3),savings number(3)); Table created. SQL> insert into empa values(2,’kumar’,2500,150,650); 1 row created. SQL> insert into empa values(3,'venky’,5000,900,950); 1 row created, SQL> insert into empa values(4'anish’,9999,999,999); | row created. SQL> select * from empa; 1D NAME, INCOME EXPENCE SAVINGS B kumar 2500 150 650 B venky 5000 900 950 & anish 9999) 999 999, TYPE 1- TRIGGER AFTER UPDATE sQu> CREATE OR REPLACE TRIGGER VIJAY AFTER UPDATE OR INSERT OR DELETE ON EMPFOR EACH ROW BEGIN IF UPDATING THEN DBMS_OUTPUT.PUT_LINE(TABLE IS, UPDATED’); ELSIF INSERTING THEN DBMS_OUTPUT.PUT_LINE("TABLE IS INSERTED));ELSIF DELETING THEN DBMS_OUTPUT.PUT_LINE((TABLE IS DELETED); END IF; END; ! ‘Trigger ereated. SQL> update emp set income =900 where empname='kumar'; TABLE IS UPDATED | row updated. SQL> insert into emp values ( 4,'Chandru’,700,250,80); TABLE IS INSERTED 1 row created. SQL> DELETE FROM EMP WHERE EMPID = 4;TABLE IS DELETED 1 row deleted, SQL> select * from emp: EMPID EMPNAME INCOME EXPENSE SAVINGS 2 vivek 30 [150 oo 3 Kumar _[5000__[550 0 9 vasanth [987 6554 aa TYPE 2 - TRIGGER BEFORE UPDATE SQL> CREATE OR REPLACE TRIGGER VASANTH BEFORE UPDATE OR INSERT OR DELETE ON EMPLOYEEFOR EACH ROW BEGIN IF UPDATING THEN DBMS_OUTPUT.PUT_LINE(‘TABLE IS UPDATED));ELSIF INSERTING THEN DBMS_OUTPUT.PUT_LINE(TABLE IS INSERTED');ELSIF DELETING THEN DBMS_OUTPUT.PUT_LINE(TABLE IS DELETED); END IF; END; / Trigger created. SQL> INSERT INTO EMP VALUES (4,'SANKAR',700,98,564); TABLE IS INSERTED | row created, SQL> UPDATE EMP SET EMPID = 5 WHERE EMPNAME ='SANKAR'; TABLE IS UPDATED 1 row updated. "ABLE IS DELETED SQL> DELETE EMP WHERE EMPNAME>'SANKA\ 1 row deleted. 2.Create a Trigger to check the age valid or not Using Message Alert SQL> CREATE TABLE TRIG(NAME CHAR(10),AGE NUMBER(3)); SQL> DES! RIG; Table created. Name Null? Type NAME, CHAR(0) AGE NUMBERG) PROGRAM: SQL> SET SERVEROUTPUT ON; SQL> CREATE TRIGGER TRIGNEW AFTER INSERT OR UPDATE OF AGE ON TRIG FOR EACH ROW BEGIN IFGNEW.AGE<0) THEN DBMS_OUTPUT.PUT_LINE(INVALID AGE"); ELSE DBMS_OUTPUT.PUT_LINE('VALID AGI END IF; END; Trigger created, SQL> insert into trig values(abe’, Valid age 1 row create SQL> insert into trig values('xyz',-12); Invalid age 1 row created. NAME AGE, abe 15 xyz -12 2. Create a Trigger to check the age valid and Raise appropriate error code and error message. SQL> create table data(name char(10),age number(3)); Table created. SQL> dese data; Name Null? Type NAME CHAR(I0) AGE NUMBER@G) SQL> CREATE TRIGGER DATACHECK AFTER INSERT OR UPDATE OF AGE ON DATA FOR EACH ROW BEGIN IF(NEW.AGE<0) THEN RAISE_APPLICATION_ERROR(-20000,NO NEGATIVE AGE ALLOWED’); END IF; END; / ‘Trigger created. SQL> INSERT INTO DATA VALUES(‘ABC',10); | ROW CREATED. 15) SQL> INSERT INTO DATA VALUES (‘DI ERROR at line 1 ‘ORA-20000: No negative age allowed ORA-06512: at "4039.DATACHECK", line 3 ORA-04088: error during execution of trigger '4039.DATACHECK' NAME AGE abe 10 3. Create a Trigger for EMP table it will update another table SALARY while inserting values. SQL> CREATE TABLE SRM_EMP2(INAME VARCHAR2(10),lID NUMBER(S), SALARY NUMBER(10)); Table created. SQL> CREATE TABLE SRM_SAL2(INAME VARCHAR2(10), TOTALEMP NUMBER(S), TOTALSAL NUMBER(10)); Table created. E OR REPLACE TRIGGER EMPTRIGR22 AFTER INSERT ON SQL> CRE: SRM_EMP2FOR EACH ROW DECLARE A VARCHARQ(10); W.SALARY,TOTALEMP=TOTALEMP+1 WHERE TOTALSA INAME=A; END; i Trigger created. SQL> INSERT INTO SRM_SAL2 VALUES('VEC,0.0); | row created, SQL> INSERT INTO SRM_SAL2 VALUES(‘SRM'0,0); 1 row created SQL> INSERT INTO SRM_EMP2 VALUES('VEC’, 100,100); 1 row created. SQL> SELECT * FROM SRM_SAL2; INAME TOTALEMP TOTALSAL. 1 1000 SRM 0 0 VEC SQL> INSERT INTO SRM_EMP2 VALUES('SRM',200,3000); L row created. SQL> SELECT * FROM SRM_SAL2; INAME TOTALEMP TOTALSAL EC RM ooo [3000 60 SQL> INSERT INTO SRM_EMP2 VALU! ('VEC',100,5000); 1 row created, SQL> SELECT * FROM SRM_SAL2; INAME TOTALEMP TOTALSAL VEC 2 6000 SRM 3000 SQL> INSERT INTO SRM_EMP2 VALUES('VEC',100,2000); 1 row created. SQL; ECT * FROM SRM_SAL2; INAME TOTALEMP TOTALSAL. 8000 3000 SQL> INSERT INTO SRM_EMP2 VALUES('SRM',200,8000); 1 row created, SQL> SELECT * FROM SRM_SAL2; INAME TOTALEMP TOTALSAL VEC 3 8000 SRM 2 11000 RESULT: Thus the Trigger procedure has been executed successfully for both before and after sequences, EX.No.9 To Create view and index for database tables with a large number of records VIEWS AIM To execute and verify the SQL commands for Views and index OBJECTIVE: 1. Views Helps to encapsulate complex query and make it reusable. 2. Provides user security on each view - it depends on your data policy security. 3. Using view to convert units - if you have a financial data in US curreney, you can create view to convert them into Euro for viewing in Euro currency. PROCEDURE STEP |: Start STEP 2: Create the table with its essential atributes. STEP 3: Insert attribute values into the table. STEP 4: Create the view from the above created table. STEP 5: Execute different Commands and extract information from the View. STEP 6: Stop SQL COMMANDS 4, COMMAND NAME: CREATE VIEW COMMAND DESCRIPTION: CREATE VIEW command is used to define a view. 5, COMMAND NAME: INSERT IN VIEW COMMAND DESCRIPTION: INSERT command is used to insert a new row into the view. 6. COMMAND NAME: DELETE IN VIEW COMMAND DESCRIPTION: DELETE command is used to delete a row from the view. 7. COMMAND NAME: UPDATE OF VIEW COMMAND DESCRIPTION: UPDAT vommand is used to change a value in a tuple without changing all values in the tuple. 62 8, COMMAND NAME: DROP OF VIEW COMMAND DESCRIPTION: DROP command is used to drop the view table COMMANDS EXECUTION CREATION OF TABLE SQL> CREATE TABLE EMPLOYEE ( EMPLOYEE_NAMEVARCHAR2(10), EMPLOYEE_NONUMBER(8), DEPT_NAME VARCHAR2(10), DEPT_NO NUMBER (5),DATE_OF_JOIN DATE); Table created, TABLE DESCRIPTION SQL> DESC EMPLOYE! NAME NULL? TYPE EMPLOYE! VARCHAR2(10) EMPLOY! NUMBER(S) DEPT_NAME VARCHAR2(10) DEPT_NO NUMBER(S) DATE_OF_JOIN DATE SUNTAX FOR CREATION OF VIEW SQL> CREATE AS SELECT =COLUMN_NAME_1>, FROM
; CREATION OF VIEW SQL> CREATE VIEW EMPVIEW AS SELECT EMPLOYEE_NAME,EMPLOYEE_NO,DEPT_NAME,DEPT_NO,DATE_OF_JOIN FROM ‘VIEW CREATED, DESCRIPTION OF VIEW SQL> DESC EMPVIEW; 63 NAME NULL? TYPE EMPLOYEE_NAME VARCHAR2(10) EMPLOYEE_NO NUMBER(8) DEPT_NAME ARCHAR2(10) DEPT_NO NUMBER(S) DISPLAY VIEW: SQL> SELECT * FROM EMPVIEW; EMPLOYEE_N EMPLOY! NODEPT_NAME DEPT_NO RAVI 24 ce ho VLIAY Bas SE__-pl RAD bs rT pa: GIRT 100 SE, 7 INSERTION INTO VIEW ‘TATEMED SQL> INSERT INTO (COLUMN NAME, ) VALUES(VALUEI,....); SQL> INSERT INTO EMPVIEW VALUES (‘SRI', 120,CSE’, 67,'16-NOV-1981"); 1 ROW CREATED. SQL> SELECT * FROM EMPVIEW; EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO RAVI 24 [ECE 89 [VLIAY 45 CSE pu J bs iT be SIRT 00 SE 7 RE 120 (CSE 7 SQL> SELECT * FROM EMPLOYEE; EMPLOYEE_.N EMPLOYEE_NO DEPT.NAME DEPTNO — DATE_OF J ravi 124 lece ko WITAY B: SE bi IRAy ps iT ba IRI [100 CSE 7 [[4-NOV-81 BRI 120 (SE 7 [le-NOV-8T 64 SQL> DELE’ 2 WHERE SQL> DELETE FROM EMPVIEW WHERE EMPLOYEE_NAM 1 ROW DELETED, SQL> SELECT * FROM EMPVIEW; EMPLOYEE_N EMPLOYEE_NO DEPT_NAME DEPT_NO RAVI [124 lece Iso. TAY B45 ICSE T RAT ps ir 2 GIRT__ [100 (CSE 7 UPDATE STATEMEN’ SYNTAX: AQL>UPDATE SET< COLUMN NAME> = + WHERE =VALUE; SQL> UPDATE EMPKAVIVIEW SET EMPLOYEE_NAME~KAVI WHERE EMPLOYEE_NAME~RAVI'; 1 ROW UPDATED. SQL> SELECT * FROM EMPKAVIVIEW; EMPLOYEE_NEMPLOYEE_NODEPT_NAME DEPT_NO. KAVI ia lece 9 VUAY, Bas [CSE T RAJ i Ir bz [GIRT [roo [CSE 7 DROP A VIEW: SYNTAX: SQL> DROP VIEW EXAMPLE, SQL>DROP VIEW EMPVIEW; VIEW DROPED CREATE A VIEW WITH SELECTED FIELDS: SYNTAX; SQL>CREATE [OR REPLACE] VIEW AS SELECT .....FROM
CREATE OR REPLACE VIEW EMPL_VIEW1 AS SALARY FROM EMPL; SLECT EMPNO, ENAME, ‘SQL> SELECT * FROM EMPL_VIEW1; AMPLI SQL> CREATE OR REPLACE VIEW EMPL_VIEW2 AS SELECT * FROM EMPL WHERE DEPTNO=10; SQL> SELECT * FROM EMPL_VIE' Note: Replace is the keyboard to avoid the error “ora_0095:name is already used by an existing abject” CHANGING TH MN(S) NAM TH DURING AS SI co TYPE. SQL> CREATE OR REPLACE VIEW EMP_TOTSAL(EID,NAME,SAL) AS SELECT. EMPNO,ENAME,SALARY FROM EMPL; View created. EMPNO, ENAME SALARY 7369 smrrH ooo P7499 MARK [1050 P7565 WILL [1500 P7678 jOHN i800 P7578 [TOM 500 P7348 TURNER [15007 6 rows selected. View created, EMPNO ENAME SALARY MGRNO DEPTNO 7578 [rom i500 [7298 lho P7548 TURNER [i500 [7298 [ro View created, SQL> SELECT * FROM EMP_TOTSAL; ‘TYPE-2: SQL> CREATE OR REPLACE VIEW EMP_TOTSAL AS SELECT EMPNO "EID",ENAME, "NAME" SALARY "SAL" FROM EMPL; SQL> SELECT * FROM EMP_TOTSAL: 66 EXAMPLE FOR JOIN VIEW: SQL> CREATE OR REPLACE VIEW DEPT_EMP AS SELECT A.EMPNO "EID' "EMPNAME",A.DEPTNO "DNO",B.DNAM SQL> SELECT * FROM DEPT_EMP; EID NAME SAL 7369 smitH [1000 7499) MARK 1050 7365, WILL [1500 7678 JOHN [1800 7578 TOM 1500 7548 TURNER [1500 6 rows selected. View created, EID Ename Salary 369 kmitH 1000 499 MARK 1050 365 WILL [15007 618 jOHN [18007 STR [rom Sa8 URNER 6 rows selected. View created, LOC "D_LOC" FROM EMPL A,DEPMT B WHERE, EID EMPNAME DNO D.NAME — D_LOC s78___ [TOM ho EW YORK, 348 [TURNER [ro EW YORK, 369 SMITH. 0 CHICAGO 678 (OHN 0 ALES. CHICAGO, 7499 MARK Bo ESEARCH ZURICH 365 (WILL 0 RESEARCH [ZURICH 6 ENAME VIEW READ ONLY AND CHECK OPTIK READ ONLY CLAUSE: You can create a view with read only option which enable other to only query .no dm! ‘operation can be performed to this type of a view. EXAMPLE-4: SQL>CREATE OR REPLACE VIEW EMP_NO_DML AS SELI READ ONLY: CT * FROM EMPL WITH WITH CHECK OPTION CLAUSE EXAMPLE-4: SQL CREATE OR REPLACE VIEW EMP_CK_OPTION AS SELECT . ALARY,DEPTNO FROM EMPL WHERE DEPTNO_ 0 WITH CHECK OPTION: "T * FROM EMP_CK_OPTION; SQL> CREATE OR REPLACE VIEW DEPT_EMP_VIEW AS SELECT A.EMPNO, A.ENAME, A.DEPTNO, B.DNAME, B.LOC FROM EMPL A.DEPMT B WHERE A.DEPTN DEPTNO; SQL> SELECT * FROM DEPT_EMP_VIEW; View created EMPNO ENAME — SALARY DEPTNO 7578 TOM 1500 10 7548 TURNER 1500 10 View created. EMPNO ENAME — DEPTNO DNAME Loc 7578 TOM 10 ACCOUNT NEW YORK 7848 = TURNER 10 ACCOUNT —_ NEW YORK, 7369 SMITIT 20. SALES CHICAGO 7678 JOHN 20. SALES. CHICAGO 7499 MARK 30 RCH ZURICH 7565 WILL. 30. RESEARCH ZURICH 6 rows selected, 68 FORCE VIEW COMPILING A VIEW NTAX: ‘ALTER VIEW COMPILE; AMPL VIEW MYVIEW COMPILE; INDEXING: An index is an ordered set of pointers to the data in a table. It is based onthe data values in one or more columns of the table. SQL Base stores indexes separatelyrom tables, An index provides two benefits 1, ILimproves performance because it makes data access faster. 2.It ensures uniqueness. A table with a unique index cannot have two rows with the same values in the column or columns that form the index key. Syntax: CREATE INDEX on (attrib Iattrib 2....attrib n); INDEXES SIMPLE INDEX: SQL> create index rollindex on stud(rollno); Index created, SQL> select * from stud; ROLLNO NAME 101 mel COMPOSITE INDE! SQL> create index regnoindex on student(regno,sname); Index created. SQL> select * from student; REGNO SNAME DEPT MARKS PERCENT — RANK 12345 max 100 100 1 11335 sophia 87 88 5 55432 sarah 94 B 2 lol amber 98 94 3 102 rose 90 46 9 15743 stella 90 87 4 6 rows selected. UNIQUE INDEX: SQL> create unique index nameindex on railway(name); Index created, SQL> select * from railway; NAME DEPARTURE ARRIVAL TICKET, melvina 23-FEB-14 12343 59555 sophia IT-JAN*1S 13-JAN-IS 11111 1234 sarah L1-JUL-96 19-JUL-97 33456 12345 max 16-FEB-04 17-MAR-14 77765 34532 selvi 12-JAN-90 13-FEB-82 98765 67854 BITMAPPING INDEX: SQL> create bitmap index deptindex on student(dept); Index created. SQL> select * from student; REGNO SNAME PT MARKS PERCENT RANK 12345 max ese 100 100 11335 sophit it 8788 55432 sarah ece 4B 101 amber ese 98 94 102 rose mech 9 © 46 15743 stella ese 90 (87 6 rows selected. 70 SQL> create index seatindex on railway(seatno) reverse; Index created, SQL> select * from railway; NAME DEPARTURE ARRIVAL TICKET_NO SEATNO melvina 19-FEB-14 23-PEB-14 12343 55555 sophia 17-JAN-IS13-JAN-15 Wid 1234 sarah 11-JUL-96 —-19-JUL-97 33456 12345 max 16-FEB-04.-17-MAR-14.__77765 34532 selvi 12-JAN-90—13-FEB-82 98765 67854 ASCENDING ANU ENDING INDEX: SQL> create index railindex on railway(name ase,ticket_no dese); Index created. FUNCTION BASED INDEX: SQL> create index studindex on student(marks+percent); Index created. DROPPING AN INDEX: SQL> drop index studindex; Index dropped. RESULT: Thus the SQL commands for View and indexes has been verified and executed successfully. EX.NO.10 Create an XML database and validate it using XML Schema AIM: To create an XML database and validate it using XML Schema, PROCEDURE: How to run XML database 1. Save the XML schema and XML file to your computer. 2. Open a text editor, such as Notepad or TextE 3. Copy and paste the XML schema into the text editor. 4. Copy and paste the XML file into the text editor, directly beneath the XML schema, 5, Save the file with a xml extension, For example, you could name it "books.xml", 6. Open a command prompt or terminal window. 7. Navigate to the directory where you saved the XML file. 8, Type the following command to validate the XML file against the schema: xmillint schema books.xsd books.xml Step 1: | First, you need to create an XML file that will serve as your database. For this example, let's create a simple database or books PROGRAM. <2xml version="1.0" encoding="UTF-8"2> The Great Gatsby<ititle> <author>F. Scott Fitzgerald</author> <year>1925</year> </book> <book id="2"> <title>To Kill a Mockingbird Harper Lee 1960 1984 George Orwell 1949 This XML file contains three book entries, each with an ID, title, author, and year. STEP 2: 2.Next, you need to create an XML schema that will define the structure and rules of your database. Here is an example XML schema for our books database: 1.0"7> "http://www.w3.org/2001/XMLSchema"> )ooks"> ‘xs:integer” use="required"/> id" typ. This schema defines that our XML file must have a root element named "books," which can contain an unlimited number of "book" elements. Each "book" element must have a "title,” "author," and "year" element, and an "id" attribute that is required and must be an integer. STEP 3: 3. To validate the XML file against the XML schema, you can use an XML validator tool or an integrated development environment (IDE) with XML support. Here's an example of how to validate the XML file using the xmllint tool: xmllint --noout --schema books.xsd books.xml The "--noout" flag tells xmllint not to output the XML file, and the "--schema" flag specifies the XML schema file to use for validation. If there are any errors in the XML file that violate the schema, xmllint will output an error message describing the issue.Assuming that the XML file and schema are valid, the output should be empty. Result: Thus to create an XML database and validate it using XML schema was successfully verified, EX.No.11 Create document,Column and Graph based data using NOSQL Database tools AIM: To create document, column, and graph-based data using Apache Cassandra in NOSQL database tools. PROCEDURE: 1. This code creates a new database called "mydatabase" in MongoDB and three collections within it "mycollection" for document-based data, "mycolumn_collection” for column-based data, and "mygraph_collection" for graph-based data. 2. For document-based data, the code inserts a new document into the "mycollection” collection 3. For column-based data, it inserts a new column into the "mycolumn_collection" collection. 4, For graph-based data, it connects to a Gremlin server and inserts a new vertex and edge into the "mygraph_collection" collection. Stepl: First, let's create a keyspace for our database CREATE KEYSPACE mykeyspace WITH replication = {‘class'SimpleStrategy', ‘replication_factor':1}; Step 2: Next, let’s create a table for our document-based data. CREATE TABLE mytable ¢ id UUID PRIMARY KEY, name text, age int, city text % Step 3: To insert a document into the table. INSERT INTO mytable (id, name, age, city) VALUES (uuid0, ‘John’, 30, 'New York’); Step 4: To retrieve a column from the table SELECT * FROM mytable WHERE id ~ ; Next, let's create a table for our column-based data: Step I: CREATE TABLE mycolumn_table ( id UUID PRIMARY KEY, name text, age int, city text) WITH CLUSTERING ORDER BY (name ASC); To insert a column into the table: Step 2: INSERT INTO mycolumn_table (id, name, age, city) VALUES (uuid(), ‘John’, 30, "New York’); To retrieve a column from the table: Step 3: SELECT name, age FROM mycolumn_table WHERE id = ; Finally, | 's create a table for our graph-based data: Step 1: CREATE TABLE mygraph_table ( id UUID PRIMARY KEY, name text ys CREATE TABLE mygraph_edges ( souree_id UUID, destination_id UUID, edge_type text, PRIMARY KEY (source_id, destination_id, edge_type) y To insert a vertex into the table: Step 1: INSERT INTO mygraph_table (id, name) VALUES (uuid(), John’); To insert an edge into the table: Step 2: INSERT INTO mygraph_table (id, name) VALUES (uuid(), ‘John’); To retrieve a vertex and its edges from the table: Step 3: SELECT * FROM mygraph_table WHERE id = ; SELECT * FROM mygraph_edges WHERE source_id = ; RESULT: ‘Thus to create document,Column and graph based data using NOSQL database tools was verified and executed successfully. EX.NO:12 CREATING DATABASE CONNECTIVITY WITH FRONT END TOOLS AIM: To create a Database Connectivity with Front end Tools STEP 1: Create a Table Emp. SQL> dese emp; Name Null? Type EMPNO, NUMBER(6) ENAME NOT NULL VARCHAR2(20) JOB VARCHAR2(20) MGR NUMBER(4) DEPTNO NUMBER(G) SALARY NUMBER(7,2) STEP 2: Design a Form Employee TTT [EMPLOYE INFORMATION SYSTEM enna oe emoctie FORT vermoeer omment [Fr 78 STEP 3 Accessing Database using ADODC. In this section we will learn to use the Remote Data Access Object that is the ADO DC data object. We will illustrate using the control to connect to a Oracle Database and some Demo tables on the Scott user in Oracle Dbase. Setting up the ADO Control Open Visual Basic, start a new project. On the menu tab of Project. Click Components (CTRL*T) Now add the control >Microsoft ADO Data Control (OLEDB)< ‘Components Contils | Desines | insertable Obtects | LayeutBTC 1.0 Type Library ] LEDMeter Activex Control module Mg Extended Form Control 1.2 "| MB ProgressBar Control 1.0 Me Seraler Control 1.0 # {ADO Dats Conia! 6.0 (GLEDS) Microsoft Agent control 2.0 IMerasoft Calendar Control 8.0 Meerasoft Chart Control 6.0 (OLEDE) JMacroroft Comm Control 6.0 Mereeo Conmon Sslog contra 6.0 = 4] i J I Selected Items Only Microsoft ADO Data Central 6.0 (OLEDS) Location: C:\WINDOWS\pystem22\MSADODC.OCK Add an ADO Data Control to the form using the ADODC tool [ Now right click on the ADO control and select ADODC Properties. i Send To Back yen code Algn to Gid ‘Now it will invoke the Property Pages for the ADO DC control that you added, Select the option use Connection String and then click at the Build button. a ) ‘Genel | Athoicaton | RecorSouce | Color | rt_| j-Saurce of Connection © Use Data Link Fle 7 Use DDBC Dats Source Naive lke Connector Sing Connection to a database. ‘Now a another dialog — Data Link Properties pops up. Select Microsoft OLE DB provider for Oracle from that list that appears and click on the Next Button. 20 rortee |camectin | Advan | A Selectthe dete yous wants correct: [OLDE Pend ModiaGatalooU E OLE D8 Provo, Mercot SAM 9.7 OLE DS Fovdar Mreaot Jet 25] OLEDR Prove Moet OLE D3 Pride Fer Osta Ninn Servicee Macoof OLE D8 Pevdat for Indexing Sorico Mereaot OLE D8 Provdafor SOL Server Maeaot OLE 98 Smpe Provider BLEDB Frew for icra Diwctoy Senicoe fee) tee >> Now if you are on a single system you don’t have to Enter the Server name in the entry field. Just enter the demo Usemame :Scott and password: tiger. Provider Cennecton |Advencea AN | “Speaty the following to connect te Oracie data: oraclelig 2 Enter information log onto the database: emecteen Pesenord: = ( Biante pacewors 10 [isi gamma paSSei a1 after this press the button test connection . If the username and password is valid, then a message box will appear. ED tetcomeston ascent = tip : check the allow saving password, otherwise on every run time start, it will ask for a password. After this, press Ok in the main dialog box. Once again in the Property Pages, Click on the RecordSource Tab. Select Command Type from the drop down box. General | Authentistin FReardSouce | cole | Font. | RecordSouce Command Type [-sicnauninewn SSL -sdtndUnkoown accent la: [a asCndstoredros (Connmand Tes (SOL) Now from the drop down list of Table or Stored Procedure Name drop down box, select the Table EMP | Property Pages wel] avericaion (Pease [eee ae eae eae > adGmaTable “Table or Stored Frocadure Name EMPLOYEES SALGRADE. lWkSATTRIBUITE Few Notes on Command Type methods -ademdText The Source string contains a SQL command, such as a select statement. -adCmdTable The Source string contains the name of a table to be retrieved. (ADO itself creates the query without the user seeing it), Using this option is not suited for large tables as it contains all the records, and thus handling may become cumbersome. Use it only for small tables like the EMP table of Scott User -adCmdStoredProc The Source string contains the name of a stored procedure (not applicable to Oracle.) -adCmdUnknown. This constant indicates that the type of command in the Source argument is not known. Using this option is inefficient. STEP 4 Select the text control and change the properties as: Data Source ; Adodel Date Field : EmpNo Like assign all text field with adode for connect data source to text controls, saa STEPS Add the command controls such as ADDNEW, SAVE, DELETE, UPDATE Write the Event coding by click Private Sub Command] _Click() Adodel Recordset. AddNew End Sub Private Sub Command2_Click() Adodel Recordset Delete MsgBox "Record Deleted" End Sub Private Sub Command3_ClickO Adodel Recordset. Update End Sub Private Sub Command4_Click() Adodel Recordset Save End Sub STEP 6 Add the command controls such as MOVE FIRST, MOVE NEXT, MOVE PREVIOUS AND MOV LAST ea Write the Event coding by click Private Sub CommandS_Click0) Adodc1 Recordset. MoveFirst End Sub Private Sub Command6_Click() Adode! Recordset. MoveNext End Sub Private Sub Command7_Click() Adode! Recordset. MovePrevious End Sub Private Sub Command8_Click() Adodel Recordset MoveLast End Sub STEP 7 Run you project by FS REPORT GENERATION STEP 1: ADDING DATA REPORT Start Visual Basic as a Standard EXE project. From the Project menu in the VBE, select Add Data Report in the dropdown menu, Now, you will be presented with the data report environment, as shown in Figure The data report environment contains six controls, they are RptTextBox, RptLine, RptFunction, RptLabel, RptImage and RptShape. ‘You can customize your report here by adding a title to the page header using the report label RptLabel. Simply drag and draw the RptLabel control on the data report designer window and use the Caption property to change the text that should be displayed. You can also add graphics to the report using the RptImage control. STEP 2: CONNECTING THE REPORT TO DATABASE USING DATA ENVIRONMENT DESIGNER, Click the Project menu, then select Data Environment. from the drop-down menu. The default data environment will appear, as shown in figure RA een I clade) Slots xii a dala Ep Datebrviermertt +2 86 Select the Connection > Properties xicrle| la fs: Select Provider -> Microsoft OLE DB Provider for Oracle Click Next. a7 ent [eam ees | Select the Connection. Enter Server Name, UserName & Password. Also Choose Allow Saving Password & Press Ok Button. BR TSP BAS bee MPSWREARE oo Bewces | ell 2S Be | es ee Step 3: Retrieving Information from the Database.In order to use the database in your report, you need to create query to retrieve the information from the database. Here , we will use SQL command to create the query. First of all, ight click on MyConnection to add a command to the data environment. er en (SaEIEs Select Command - > Properties Ee Ot Hone Fane (ap Bn Cy OpDIN eds Aas HY 3-8-5 eG eM ys NRaERE jet CARTE Some Som ret Choose Source of Data Database Object as Table Object Name as EMP (Table Name) 90 Se BG TSR ORK MR RER ADS oe aly one sop aw s mPa Ger Ja] Ane enrrshos [Eman — Cm Earns 2 ote f= 3] Expand the Command! Button to Choose all the fields. To add data to your report, you need to drag the fields from MyCommand in MyDataEnvironment into MyDataReport, as shown in Figure on wv) Be Eo Bot rt bt Bn Cy Dia aE HO ese seen [ss MP BEREM OS oo Choose the DataReport! and set the DataSource as DataEnvironment! DataMember as Command1. 92 aaa et STEP 4: Run the Report. RESULT: Thus to create a database connectivity with front end tool was verified and executed successfully. 93 EX.NO.10 CASE STUDY USING REAL LIFE DATABASE APPLICATIONS AIM: To make a Case Study using real life database applications. Hospital Management System XYZ hospital is a multi specialty hospital that includes a number of departments, rooms, doctors, nurses, compounders, and other staff working in the hospital. Patients having different kinds of ailments come to the hospital and get checkup done from the concerned doctors. If required they are admitted in the hospital and discharged after treatment. The aim of this case study is to design and develop a database for the hospital to maintain the records of various departments, rooms, and doctors in thehospital. It also maintains records of the regular patients, patients admitted in the hospital, the check up of patients done by the doctors, the patients that have been operated, and patients discharged from the hospital. Description: In hospital, there are many departments like Orthopedic, Pathology, Emergency, Dental, Gynecology, Anesthetics, I.C.U., Blood Bank, Operation Theater, Laboratory, MRL, Neurology, Cardiology, Cancer Department, Corpse, etc. There is an OPD where patients come and get a card (that is, entry card of the patient) for check up from the concerned doctor. After making entry in the card, they go to the concerned doctor’s roomand the doctor checks up their ailments. According to the ailments, the doctor either prescribes medicine or admits the patient in the concerned department, Thepatient may choose either private or general room according to his/her need. But before getting admission in the hospital, the patient has to fulfill certain formalities of the hospital like room charges, etc. After the treatment is completed, the doctor discharges the patient Before discharging from the hospital, the patient again has to complete certain formalities of the hospital like balance charges, test charges, operation charges (if any), blood charges, doctors’ charges, ete. Next we talk about the doctors of the hospital. There are two types of the doctors in the hospital, namely,regular doctors and call on doctors, Regular doctors are those doctors who come to the hospital daily. Calls on doctors are those doctors who are called by the hospital if the concerned doctor is not available. ER-Diagram for Hospital Management system Railway Reservation The railway reservation system facilitates the passengers to enquire about the trains available on the basis of source and destination, booking and cancellation of tickets, enquire about the status of the booked ticket, etc. The aim of case study is to design and develop a database maintaining the records of different trains, train status, and passengers. The record of train includes its number, name, source, destination, and days on which it is available, whereas record of train status includes dates for which tickets can be booked, total number of seats available, and number of seatsalready booked. The database has been developed and tested on the Oracle. Description: Passengers can book their tickets for the train in which seats are available. For this, passenger has (o provide the desired train number and the date for whichticket is to be booked. Before booking a ticket for a passenger, the validity of train number and booking date is checked. Once the train number and booking date are validated, it is checked whether the seat is available. If yes, the ticket is booked with confirm status and corresponding ticket ID is generated which is stored along with other details of the passenger. After all the available tickets are booked, certain numbers of tickets are booked with waiting status. If waiting lot is also finished, then tickets are not booked and a message of non availability of seats is displayed. The ticket once booked can be cancelled at any time. For this, the passenger has to provide the ticket ID (the unique key). The ticket ID is searched and the corresponding recordis deleted. With this, the ticket with waiting status also gets confirmed. List of Assumptio: Since the reservation system is very large in reality, it is not feasible to develop the case study to that extent and prepare documentation at that level. Therefore, a small sample case study has been created to demonstrate the working of the reservation system, To implement this sample case study, some assumptions have been made which are as follows: 1, The number of trains has been restricted to 5. 2. The booking is open only for next seven days from the current date. 3. Only two categories of tickets can be booked, namely, AC and General The total number of tickets that can be booked in each category (AC and 4. General) is 10. 8. The total number of tickets that can be given the status of waiting is 2 ‘6. The in between stoppage stations and their bookings are not considered. ER-Diagram for Railway Reservation System =; TS I> er => = ——" ert RESULT: Thus prepared a Case Study using real life database applications was verified successfully.

You might also like