Anda di halaman 1dari 5

INT 451: Database Administration

Assignment # 2

PART-A

1. What are Schemas? Describe various steps to create and drop schemas (both graphically
and manually).

Solution: In computer programming, a schema is the organization or structure for a database. The
activity of data modeling leads to a schema. Schema is used in discussing both relational
databases and object-oriented databases.

Two common types of database schema are the star schema and the snowflake schema.

Create a schema

If a user has SYSADM or DBADM authority, then the user can create a schema with any valid
name. When a database is created, IMPLICIT_SCHEMA authority is granted to PUBLIC (that is,
to all users). The following example creates a schema for an individual user with the
authorization ID 'joe'

CREATE SCHEMA joeschma AUTHORIZATION joe

Inputs

schemaname

The name of a schema to be created. If this is omitted, the user name is used as the
schema name.

username
The name of the user who will own the schema. If omitted, defaults to the user executing
the command. Only superusers may create schemas owned by users other than
themselves.

schema_element

An SQL statement defining an object to be created within the schema. Currently, only
CREATE TABLE, CREATE VIEW, and GRANT are accepted as clauses within
CREATE SCHEMA. Other kinds of objects may be created in separate commands after
the schema is created.

Outputs

CREATE SCHEMA

Message returned if the command is successful.

ERROR: namespace "schemaname" already exists

If the schema specified already exists.

Description

CREATE SCHEMA will enter a new schema into the current database. The schema name must
be distinct from the name of any existing schema in the current database. Optionally, CREATE
SCHEMA can include subcommands to create objects within the new schema. The subcommands
are treated essentially the same as separate commands issued after creating the schema, except
that if the AUTHORIZATION clause is used, all the created objects will be owned by that user.

Drop Schema

Inputs

Name The name of a schema.


CASCADE Automatically drop objects (tables, functions, etc) that are contained in the schema.
RESTRICT Refuse to drop the schema if it contains any objects. This is the default.

Outputs

DROP SCHEMA The message returned if the schema is successfully dropped.


ERROR: Schema "name" does not exist

This message occurs if the specified schema does not exist.

Description

DROP SCHEMA removes schemas from the data base. A schema can only be dropped by its
owner or a superuser. Note that the owner can drop the schema (and thereby all contained
objects) even if he does not own some of the objects within the schema.

2. What are indexes? Differentiate between Clustered and Non-Clustered Indexes. Also
describe how Non Clustered indexes are applied on Heap and Clustered Indexes?

Solution: A database index is a data structure that improves the speed of data retrieval
operations on a database table at the cost of slower writes and increased storage space. Indexes
can be created using one or more columns of a database table, providing the basis for both rapid
random lookups and efficient access of ordered records. The disk space required to store the
index is typically less than that required by the table.

There are clustered and nonclustered indexes. A clustered index is a special type of index that
reorders the way records in the table are physically stored. Therefore table can have only one
clustered index. The leaf nodes of a clustered index contain the data pages.

A nonclustered index is a special type of index in which the logical order of the index does not
match the physical stored order of the rows on disk. The leaf node of a nonclustered index does
not consist of the data pages. Instead, the leaf nodes contain index rows.

Nonclustered indexes can be defined on a table or view with a clustered index or a heap. Each
index row in the nonclustered index contains the nonclustered key value and a row locator. This
locator points to the data row in the clustered index or heap having the key value. The row
locators in nonclustered index rows are either a pointer to a row or are a clustered index key for a
row, as described in the following:

• If the table is a heap, which means it does not have a clustered index, the row locator is a
pointer to the row. The pointer is built from the file identifier (ID), page number, and
number of the row on the page. The whole pointer is known as a Row ID (RID).
• If the table has a clustered index, or the index is on an indexed view, the row locator is the
clustered index key for the row. If the clustered index is not a unique index, SQL Server
makes any duplicate keys unique by adding an internally generated value called
a uniqueifier. This four-byte value is not visible to users. It is only added when required
to make the clustered key unique for use in nonclustered indexes. SQL Server retrieves
the data row by searching the clustered index using the clustered index key stored in the
leaf row of the nonclustered index.

3. What are Table Collations and its types? Describe various Collation settings with TSQL
examples.

Solution: A collation specifies the bit patterns that represent each character. It also specifies
the rules that are used to sort and to compare the characters. A collation has the following
characteristics:

• Language
• Case sensitivity
• Accent sensitivity
• Kana sensitivity
Various Collation settings with TSQL example are as following:

ALTER DATABASE database


{ ADD FILE < filespec > [ ,...n ] [ TO FILEGROUP filegroup_name ]
| ADD LOG FILE < filespec > [ ,...n ]
| REMOVE FILE logical_file_name
| ADD FILEGROUP filegroup_name
| REMOVE FILEGROUP filegroup_name
| MODIFY FILE < filespec >
| MODIFY NAME = new_dbname
| MODIFY FILEGROUP filegroup_name {filegroup_property | NAME = new_filegroup_name }
| SET < optionspec > [ ,...n ] [ WITH < termination > ]
| COLLATE < collation_name >
}

PART B

1. Explain various Table Constraints with appropriate examples.

2. How Security can be implemented in SQL Server 2005? Explain in detail.

3. Differentiate between Stored Procedures and Functions with examples.

Anda mungkin juga menyukai