Data Definition Language Enhancements

The Data Definition Language (DDL) refers to Transact-SQL statements used to define databases and database objects and to manage their properties. In SQL Server 6.0, DDL includes a significant number of statements. The feature areas with significant enhancements can be categorized as shown in the following table. The DDL enhancements are then described in detail.


Feature area
Related DDL statements and
Transact-SQL Reference topics
Table definition ALTER TABLE
CREATE TABLE
Constraints
IDENTITY Property
Data Integrity
View definition CREATE VIEW
Dropping objects All drop statements
DROP DEFAULT
DROP PROCEDURE
DROP TABLE
Encrypted definition: procedures, triggers, and views CREATE PROCEDURE
CREATE TRIGGER
CREATE VIEW
syscomments
Parameters CREATE PROCEDURE
Local and global temporary objects: procedures and tables CREATE PROCEDURE
CREATE TABLE

Table Definition

The syntax for the CREATE TABLE and ALTER TABLE statements has been updated to include ANSI-standard constraints and the IDENTITY property. Constraints can enforce primary and foreign key references through declarative referential integrity (DRI) as well as other various aspects of data integrity: entity, domain, and user-defined. The IDENTITY property refers to a column attribute which defines a series of values to be used for inserts.

Earlier releases of SQL Server supported only user-defined datatypes, defaults, rules, triggers, and stored procedures. SQL Server now supports all of these objects, and the table-definition syntax now includes a variety of extensions that achieve similar results without requiring separate object-creation and "binding" steps to enforce them. Constraint information is maintained in new system tables (sysconstraints and sysreferences). All of these options can be used together to provide efficient and effective data integrity.

Integrity
type
Earlier
options
Comparable,
new options
Entity Unique indexes PRIMARY KEY and UNIQUE constraints, IDENTITY Property
Domain Datatypes, defaults, rules CHECK, DEFAULT and FOREIGN KEY constraints
Referential Triggers FOREIGN KEY constraints
User-defined Rules, triggers, stored procedures All column- and table-level constraints in CREATE TABLE

Entity Integrity
Defines a row as a unique entity for a particular table. Entity integrity usually enforces the primary key of a table (through UNIQUE or PRIMARY KEY constraints or indexes).
Domain Integrity
Refers to the valid entries for a given column. Domain integrity is enforced by restricting the datatype (through system or user-defined datatypes), format (through CHECK constraints and rules), or range of possible values (through FOREIGN KEY and CHECK constraints, and rules and NULL/NOT NULL declarations).
Referential Integrity
Enforces the validity of data entered to ensure that it exists within a range of values within another table. With SQL Server 6.0, referential integrity is declarative with FOREIGN KEY constraints. (In earlier releases, the requirement to check the existence of a foreign key was programmatically defined through triggers.)
User-defined Integrity
Allows specific business rules that don't fall into one of the above categories to also be defined. All options listed above support user-defined integrity.

The syntax for constraints includes support for specifying clustered or nonclustered indexes to support PRIMARY KEY and UNIQUE constraints. For more information about defining and manipulating constraints, and for information about the IDENTITY property, see the ALTER TABLE and CREATE TABLE statements.

View Definition

Views provide an alternate method for looking at the data within a table or group of related tables. The CREATE VIEW statement in SQL Server 6.0 checks the validity of data updated through a view, and permits the use of the DISTINCT keyword in the definition of the view. For details, see the CREATE VIEW statement.

Encrypted Definition and Passwords

Procedures, triggers, and views can be created with an optional (one way) encryption parameter that encrypts the definition text stored in syscomments. For details, see the CREATE PROCEDURE, CREATE TRIGGER, and CREATE VIEW statements. In addition, if passwords are stored (that is, not using integrated security), they are now always encrypted.

Dropping Objects

The DROP object_name statements (DROP DEFAULT, DROP PROCEDURE, DROP TABLE, DROP TRIGGER, etc.) can now be executed by the database owner (DBO) or the system administrator (SA). The DBO and SA no longer need to use the SETUSER statement to drop objects. All other object owner functionality is maintained by the database object owner. The DBO and SA must continue to use SETUSER to perform tasks such as granting permissions.

Parameters

When executing a stored procedure, the server will reject any parameters that were not included with the parameter list during procedure creation. Any parameter that is passed by reference (explicitly passing the parameter name) will not be accepted if the parameter name does not match. For details on creating procedures and passing parameters, see the CREATE PROCEDURE and EXECUTE statements.

Local and Global Temporary Objects

Tables and stored procedures can be created for permanent access by any user who has appropriate permissions, or they can be created as temporary objects. You can create local and global temporary procedures or tables for use only in the current session or for use in all sessions. Local temporary objects are visible in the current session only; global temporary objects are visible to all sessions. Local temporary objects are automatically dropped at the end of the current session; global temporary objects are dropped at the end of the last session using the table (normally, this is when the session that created the object ends). For details, see the sections about the CREATE PROCEDURE and CREATE TABLE statements.