Sunteți pe pagina 1din 3

Q. 1.

Ans:
The relation schema R is {Qi1, Qi2 , ...,Qin}
and the primary key of relation schema S is {Yi1, Yi2 , ...,Yim}. Then a
relationship
between the 2 sets can be represented as a tuple (Qi1, Qi2 , ...,QinYi1, Yi2
, ...,Yim). In a one-to-one relationship, each value on {Qi1, Qi2 , ...,Qin}will
appear in exactly one tuple and likewise for {Yi1, Yi2 , ...,Yim}. In amanyto-
one relationship (e.g., many A - one B), each value on {Qi1, Qi2 , ...,Qin} will
appear once, and each value on {Yi1, Yi2 , ...,Yin} may appear many times.
In a
many-to-many relationship, values on both {Qi1, Qi2 , ...,Qin} and { Yi1, Yi2
, ...,Yim} will appearmany times.

Ans : There are times when duplicate records somehow creep into a table
despite your best efforts. This happens more in cases where data is loaded
into table from other sources because during data loads, the integrity
constraints are disabled.

The following SQL statement helps in deleting the duplicate rows in a table:

delete table_a
where rowid not in
(select min(rowid) from table_a
group by column1, column2);

Ans DELETE FROM table_name A WHERE ROWID > (


2 SELECT min(rowid) FROM table_name B
3 WHERE A.key_values = B.key_values);

delete from my_table t1


where exists (select 'x' from my_table t2
where t2.key_value1 = t1.key_value1
and t2.key_value2 = t1.key_value2
and t2.rowid > t1.rowid);
Q. 3 a).
Ans:
Create or Replace Trigger upper
Before Insert Or Update Of ename ON emp
For Each Row
BEGIN
:new.ename : = UPPER (:new.ename);
END;

b)CREATE OR REPLACE TRIGGER EMP_UPDATE


AFTER UPDATE OF ENAME ON EMP FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE('OLD NAME: ' ||:OLD.ENAME);
DBMS_OUTPUT.PUT_LINE('NEW NAME:' ||:NEW.ENAME);
END;

c) Ans: Create Or Replace Trigger empaudit


After INSERT OR UPDATE OR DELETE ON emp
FOR EACH ROW

BEGIN
IF INSERTING THEN
INSERT INTO AUDITOR VALUES(:NEW.EMPNO,'INSERT');
ELSIF UPDATING THEN
INSERT INTO AUDITOR VALUES(:NEW.EMPNO,'UPDATE');
ELSIF DELETING THEN
INSERT INTO AUDITOR VALUES(:OLD.EMPNO,'DELETE');
ENDIF;

Part-B
(a)Ans:Create View Bank As Select account number, customer name from
accounts where branchname=’Deer Park Branch

(b. )

Ans:View Bank As Select names, addresses From Accounts Group by


All_Customers HAVING Loan = NULL;
c. Ans:Create View Bank As Select name, average balance from accounts
where branchname=’Rock Ridge branch ’

5: Ans: A view is updatable if and only if:

- DISTINCT is not specified.


- Every element in SELECT list of defining query is a
column name and no column appears more than
once.

UPDATE VW_PRODUCT
SET VALUE = ‘GREEN’
WHERE PRODUCT_ID = 2
AND ATTRIBUTE = ‘COLOR’;

S-ar putea să vă placă și