Identify common relational database objects Flashcards

1
Q

What is a view?

A

A view is a virtual table based on the results of a SELECT query. It can be thought of as a window on specified rows in one or more underlying tables.

Example:
CREATE VIEW Deliveries
AS
SELECT o.OrderNo, o.OrderDate,
c.FirstName, c.LastName, c.Address, c.City
FROM ORDER AS o JOIN Customer AS c
ON o.Customer = c.ID

To view and filter data
SELECT OrderNo, OrderDate, LastName, Address FROM Deliveries
WHERE City = “Seattle”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Whats is a stored procedure?

A

A stored procedure defines SQL statements that can be run on command. They are used to encapsulate programmatic logic in a database for actions that applications need to perform when working with data.

Example:
CREATE PROCEDURE RenameProduct
@ProductID INT.
@NewName VARCHAR(20)
AS
UPDATE Product SET NAME = @NewName
WHERE ID = @ProductID

To rename a product
EXEC RenameProduct 201, “Spanner”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an index?

A

An index helps search for data in a table. When creating an index in a database, specify a column from the table. When users run a query that specifies this column in the WHERE clause, the database system can use this index to fetch data quickly.

Example:
CREATE INDEX idx_ProductName
ON Product(Name);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly