AdventureWorks
| Table Name: | Sales.Store |
| Description: | Customers (resellers) of Adventure Works products. |
| Primary Keys: | CustomerID |
| Field | Type | Defaults | Nulls? | Comments |
|---|---|---|---|---|
| CustomerID | int | None | No | Primary key. Foreign key to Customer.CustomerID. |
| Name | nvarchar (50) | None | No | Name of the store. |
| SalesPersonID | int | None | Yes | ID of the sales person assigned to the customer. Foreign key to SalesPerson.SalesPersonID. |
| Demographics | xml | None | Yes | Demographic informationg about the store such as the number of employees, annual sales and store type. |
| rowguid | uniqueidentifier | (newid()) | No | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| ModifiedDate | datetime | (getdate()) | No | Date and time the record was last updated. |
| Index | Clustered? | Unique? | Fields |
|---|---|---|---|
| PK_Store_CustomerID | Yes | Yes | CustomerID |
| AK_Store_rowguid | No | Yes | rowguid |
| IX_Store_SalesPersonID | No | No | SalesPersonID |
| Internal Foreign Key Constraint | Affected Field | Source Table |
|---|---|---|
| FK_Store_Customer_CustomerID | CustomerID | Sales.Customer |
| FK_Store_SalesPerson_SalesPersonID | SalesPersonID | Sales.SalesPerson |
| Primary Key as Foreign Key Constraint | Affected Table | Affected Field |
|---|---|---|
| FK_StoreContact_Store_CustomerID | Sales.StoreContact | CustomerID |
| Trigger | Text |
|---|---|
| iStore | CREATE TRIGGER [Sales].[iStore] ON [Sales].[Store] AFTER INSERT AS BEGIN DECLARE @Count int; SET @Count = @@ROWCOUNT; IF @Count = 0 RETURN; SET NOCOUNT ON; BEGIN TRY IF EXISTS (SELECT * FROM inserted INNER JOIN [Sales].[Individual] ON inserted.[CustomerID] = [Sales].[Individual].[CustomerID]) BEGIN IF @@TRANCOUNT > 0 BEGIN ROLLBACK TRANSACTION; END END; END TRY BEGIN CATCH EXECUTE [dbo].[uspPrintError]; IF @@TRANCOUNT > 0 BEGIN ROLLBACK TRANSACTION; END EXECUTE [dbo].[uspLogError]; END CATCH; END; |