SQL Viva Questions
SQL Viva Questions
Previous
Next Chapter
P_Id
1
2
3
LastName
Hansen
Svendson
Pettersen
FirstName
Ola
Tove
Kari
Address
Timoteivn 10
Borgvn 23
Storgt 20
City
Sandnes
Sandnes
Stavanger
OrderNo
77895
44678
22456
24562
P_Id
3
3
2
1
Note that the "P_Id" column in the "Orders" table points to the "P_Id" column in the "Persons"
table.
The "P_Id" column in the "Persons" table is the PRIMARY KEY in the "Persons" table.
The "P_Id" column in the "Orders" table is a FOREIGN KEY in the "Orders" table.
The FOREIGN KEY constraint is used to prevent actions that would destroy links between
tables.
The FOREIGN KEY constraint also prevents that invalid data form being inserted into the
foreign key column, because it has to be one of the values contained in the table it points to.
SQL: VIEWS
A view is, in essence, a virtual table. It does not physically exist. Rather, it is created by a query
joining one or more tables.
Creating a VIEW
The syntax for creating a VIEW is:
CREATE VIEW view_name AS
SELECT columns
FROM table
WHERE predicates;
For example:
CREATE VIEW sup_orders AS
SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_name = 'IBM';
trigger
(n.) In a DBMS, a trigger is a SQL procedure that initiates an action (i.e., fires an action) when
an event (INSERT, DELETE or UPDATE) occurs. Since triggers are event-driven specialized
procedures, they are stored in and managed by the DBMS. A trigger cannot be called or
executed; the DBMS automatically fires the trigger as a result of a data modification to the
associated table. Triggers are used to maintain the referential integrity of data by changing the
data in a systematic fashion.
Each trigger is attached to a single, specified table in the database.
Triggers can be viewed as similar to stored procedures
Stored procedure