Professional Documents
Culture Documents
• Computer language
• IBM implemented this language, originally called sequel.
Purpose?
• To store, Manipulate, and retrive data in relational database.
TOPIC TO BE COVERED…
• Constraints
• Index
• Views
• Alias
CONSTRAINTS
• Limitations / Restrictions.
• Rules implemented on table.
When to be specified?
• Constraints can be specified when table is created.
CREATE TABLE statement.
• Column constraints.
• Table constraints.
• CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
Age int
);
• ALTER TABLE Persons
MODIFY Age int NOT NULL;
INDEX STATEMENT
• Reference.
• Quick lookup table.
• Retrieve data from the database.
• CREATE INDEX statement is used to create indexes in tables
• The users cannot see the indexes,
• Used to speed up searches/queries.
• Therefore: Check the syntax for creating indexes in your database.
• You can use the system stored procedure sp_rename to rename any index in
the database.
EXEC sp_rename
index_name,
new_index_name,
N'INDEX';
VIEW STATEMENT
• To see the data in the View, we can query the view in the same manner as we
query a table.
SELECT * FROM DetailsView;
• shows up-to-date data!
• The database engine recreates the view, every time a user queries it
• assumed identity.
• used to give a table, or a column in a table, a temporary name.
• An alias only exists for the duration of that query.
• An alias is created with the AS keyword.
• Alias Column Syntax
• SELECT CustomerName AS Customer, ContactName AS [Contact Person]
FROM Customers;
SELECT column_name AS alias_name
FROM table_name;