| Name | Object Type | Object Use |
| trgGRCITableName | trigger | Create |
| trgGRCUTableName | trigger | Update |
| uspGRCITableName | stored procedure | Create |
| uspGRCUTableName | stored procedure | Update |
| uspGRCDTableName | stored procedure | Delete |
| uspGRCSTableName | stored procedure | Read (Retrieve) |
| uspGRKDTableName | stored procedure | Delete |
| uspGRKSTableName | stored procedure | Read (Retrieve) |
| udfGRKSTableName | user-defined function | Read (Retrieve) - requires SQL Server 2000 or newer |
I will start with a brief explanation of the naming convention used for these objects. Each name begins with a three-letter prefix to indicate the object type. Notice that without the prefix the names are not unique and unique names are required by SQL Server. The next two characters (positions 4 and 5) are a two-letter label (GR) to indicate a generated routine. The next two characters (positions 6 and 7) are a two-letter label to indicate the purpose for the routine, with C/K meaning Common/Key and I/U/D/S meaning INSERT/UPDATE/DELETE/SELECT. The remaining characters are a table name.
The trgGRCITableName trigger fires with an insert and sets the CreateDate column to the current date and time.
The trgGRCUTableName trigger fires with an update and sets the ModifyDate column to the current date and time.
The uspGRCITableName routine performs an INSERT of one row. It accepts values for each column (except for the primary key) and it returns the system-generated primary key (IDENTITY value) as an OUTPUT parameter. It can automatically assign values to the Create and Modify standard columns.
The uspGRCUTableName routine performs an UPDATE of one row. It accepts a primary key value and values for each of the other columns. If the DetectWork standard column is present, the new value is compared with the existing value. The existing value must be less than the new value or the row is not affected. The application can check the number of rows affected and react accordingly. This behavior supports the earlier discussion of concurrent access. It can automatically assign a value to the Modify standard column.
The uspGRCDTableName routine performs a DELETE of one row. It accepts (expects) a primary key value.
The uspGRCSTableName routine performs a SELECT of one row. It accepts (expects) a primary key value and it returns all columns.
The uspGRKDTableName routine performs a DELETE of one or more rows.
The uspGRKDTableName stored procedure accepts an optional column name to determine which key column will be used to identify a set of rows. The default behavior is to use the primary key, but any foreign key can be used instead. This routine accepts an optional key value. The default behavior is to use a key value of zero (0), which matches all rows. This routine also accepts an optional value for the RecordMask standard column. The default behavior is to use a value of zero (0), which matches all rows. If the RecordMask standard column is not present, the value is simply ignored.
The uspGRKSTableName routine performs a SELECT of one or more rows, returning all columns.
The uspGRKSTableName stored procedure accepts an optional column name to determine which key column will be used to identify a set of rows. The default behavior is to use the primary key, but any foreign key can be used instead. This routine accepts an optional key value. The default behavior is to use a key value of zero (0), which matches all rows. This routine also accepts an optional value for the RecordMask standard column. The default behavior is to use a value of zero (0), which matches all rows. If the RecordMask standard column is not present, the value is simply ignored.
The udfGRKSTableName routine performs a SELECT of one or more rows, returning all columns.
The udfGRKSTableName user-defined function expects a column name to determine which key column will be used to identify a set of rows. The primary key or any foreign key can be used. This function expects a key value to be supplied. The value zero (0) matches all rows. This function also expects a value for the RecordMask standard column as a way to filter or mask rows based on their status. The value zero (0) matches all rows. If the RecordMask standard column is not present, the value is simply ignored. The parameter is included for all tables for consistency. This function offers advantages over a view or stored procedure. It allows the use of parameters (a view does not) and it can be referenced in a FROM clause (unlike a stored procedure).
Columns and objects to support a surrogate key architecture
Home: Introduction
Part 1: Overview of proposed surrogate key architecture
Part 2: Dealing with concurrent access
Part 3: Standard routines for each table
Part 4: Stored procedures: Create and manage standard objects
| ABOUT THE AUTHOR: |
|
Brian Walker Brian Walker is a senior database architect in an IS department that uses SQL Server 2000 and the .NET Framework. He has more than 25 years of experience in the IT industry with the last several years focused on databases and SQL Server. Walker is a software developer, database developer, database administrator and database consultant. He develops utility software as a hobby, including a large collection of SQL Server utilities. Copyright 2006 TechTarget |
This was first published in February 2006
Join the conversationComment
Share
Comments
Results
Contribute to the conversation