Difference between revisions of "Sales.Store (table)"
| Line 12: | Line 12: | ||
| + | === Columns === | ||
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
|- style="background:silver" | |- style="background:silver" | ||
| Line 18: | Line 19: | ||
| '''Nullable | | '''Nullable | ||
| '''Default | | '''Default | ||
| − | | '''Description | + | | '''Description |
|- valign="top" | |- valign="top" | ||
| Line 25: | Line 26: | ||
| not null | | not null | ||
| | | | ||
| − | | Primary key. Foreign key to Customer.CustomerID. | + | | Primary key. Foreign key to Customer.CustomerID. |
|- valign="top" | |- valign="top" | ||
| Name | | Name | ||
| Line 31: | Line 32: | ||
| not null | | not null | ||
| | | | ||
| − | | Name of the store. | + | | Name of the store. |
|- valign="top" | |- valign="top" | ||
| SalesPersonID | | SalesPersonID | ||
| Line 37: | Line 38: | ||
| null | | null | ||
| | | | ||
| − | | ID of the sales person assigned to the customer. Foreign key to SalesPerson.SalesPersonID. | + | | ID of the sales person assigned to the customer. Foreign key to SalesPerson.SalesPersonID. |
|- valign="top" | |- valign="top" | ||
| Demographics | | Demographics | ||
| Line 43: | Line 44: | ||
| null | | null | ||
| | | | ||
| − | | Demographic informationg about the store such as the number of employees, annual sales and store type. | + | | Demographic informationg about the store such as the number of employees, annual sales and store type. |
|- valign="top" | |- valign="top" | ||
| rowguid | | rowguid | ||
| Line 49: | Line 50: | ||
| not null | | not null | ||
| (newid()) | | (newid()) | ||
| − | | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. | + | | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
|- valign="top" | |- valign="top" | ||
| ModifiedDate | | ModifiedDate | ||
| Line 55: | Line 56: | ||
| not null | | not null | ||
| (getdate()) | | (getdate()) | ||
| − | | Date and time the record was last updated. | + | | Date and time the record was last updated. |
|} | |} | ||
| + | === Primary Key === | ||
| + | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
| + | |- style="background:silver" | ||
| + | | '''Primary Key | ||
| + | | '''Columns | ||
| + | |- | ||
| + | | PK_Store_CustomerID | ||
| + | | CustomerID | ||
| + | |} | ||
| + | === Indexes === | ||
| + | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
| + | |- style="background:silver" | ||
| + | | '''Index | ||
| + | | '''Type | ||
| + | | '''Columns | ||
| + | |||
| + | |- | ||
| + | | AK_Store_rowguid | ||
| + | | Unique | ||
| + | | rowguid | ||
| + | |- | ||
| + | | IX_Store_SalesPersonID | ||
| + | | | ||
| + | | SalesPersonID | ||
| + | |- | ||
| + | | PXML_Store_Demographics | ||
| + | | | ||
| + | | Demographics | ||
| + | |} | ||
| + | === Foreign Keys === | ||
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
|- style="background:silver" | |- style="background:silver" | ||
| Line 76: | Line 107: | ||
|} | |} | ||
| − | + | === Detail Tables === | |
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
|- style="background:silver" | |- style="background:silver" | ||
| Line 89: | Line 120: | ||
|} | |} | ||
| − | + | === Triggers === | |
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
|- style="background:silver" | |- style="background:silver" | ||
| Line 100: | Line 131: | ||
|} | |} | ||
| + | Trigger iStore | ||
| + | <pre> | ||
| + | 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 | ||
| + | -- Only allow the Customer to be a Store OR Individual | ||
| + | IF EXISTS (SELECT * FROM inserted INNER JOIN [Sales].[Individual] | ||
| + | ON inserted.[CustomerID] = [Sales].[Individual].[CustomerID]) | ||
| + | BEGIN | ||
| + | -- Rollback any active or uncommittable transactions | ||
| + | IF @@TRANCOUNT > 0 | ||
| + | BEGIN | ||
| + | ROLLBACK TRANSACTION; | ||
| + | END | ||
| + | END; | ||
| + | END TRY | ||
| + | BEGIN CATCH | ||
| + | EXECUTE [dbo].[uspPrintError]; | ||
| + | -- Rollback any active or uncommittable transactions before | ||
| + | -- inserting information in the ErrorLog | ||
| + | IF @@TRANCOUNT > 0 | ||
| + | BEGIN | ||
| + | ROLLBACK TRANSACTION; | ||
| + | END | ||
| + | |||
| + | EXECUTE [dbo].[uspLogError]; | ||
| + | END CATCH; | ||
| + | END; | ||
| + | </pre> | ||
| + | |||
| + | === References === | ||
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
|- style="background:silver" | |- style="background:silver" | ||
| Line 114: | Line 185: | ||
| Type | | Type | ||
| [[dbo.Name_(type)|dbo.Name]] | | [[dbo.Name_(type)|dbo.Name]] | ||
| + | |||
| + | | | ||
| + | | | ||
| + | |- | ||
| + | | Schema | ||
| + | | Schema | ||
| + | | [[Sales_(schema)|Sales]] | ||
| | | | ||
| Line 147: | Line 225: | ||
|} | |} | ||
| − | + | === Dependencies === | |
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | {| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse" | ||
|- style="background:silver" | |- style="background:silver" | ||
| Line 172: | Line 250: | ||
| iuIndividual | | iuIndividual | ||
|} | |} | ||
| − | |||
Revision as of 23:07, 2 February 2010
Contents
wikibot
| Table | Sales.Store |
| Description | Customers (resellers) of Adventure Works products. |
Columns
| Column | Data Type | Nullable | Default | Description |
| CustomerID | int | not null | Primary key. Foreign key to Customer.CustomerID. | |
| Name | dbo.Name | not null | Name of the store. | |
| SalesPersonID | int | null | ID of the sales person assigned to the customer. Foreign key to SalesPerson.SalesPersonID. | |
| Demographics | xml | null | Demographic informationg about the store such as the number of employees, annual sales and store type. | |
| rowguid | uniqueidentifier | not null | (newid()) | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. |
| ModifiedDate | datetime | not null | (getdate()) | Date and time the record was last updated. |
Primary Key
| Primary Key | Columns |
| PK_Store_CustomerID | CustomerID |
Indexes
| Index | Type | Columns |
| AK_Store_rowguid | Unique | rowguid |
| IX_Store_SalesPersonID | SalesPersonID | |
| PXML_Store_Demographics | Demographics |
Foreign Keys
| Relation | Column | Referenced Column |
| Sales.Customer | CustomerID | CustomerID |
| Sales.SalesPerson | SalesPersonID | SalesPersonID |
Detail Tables
| Detail Table | Column | Referencing Column |
| Sales.StoreContact | CustomerID | CustomerID |
Triggers
| Triggers | Type |
| iStore | ON INSERT |
Trigger 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
-- Only allow the Customer to be a Store OR Individual
IF EXISTS (SELECT * FROM inserted INNER JOIN [Sales].[Individual]
ON inserted.[CustomerID] = [Sales].[Individual].[CustomerID])
BEGIN
-- Rollback any active or uncommittable transactions
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
END;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END;
References
| Dependency Type | Object Type | Referenced Object | Child Type | Child Object |
| Data Type | Type | dbo.Name | ||
| Schema | Schema | Sales | ||
| Data Type | XML Schema Collection | Sales.StoreSurveySchemaCollection | ||
| Select | Table | Sales.Individual | Trigger | iStore |
| Execute | Procedure | dbo.uspLogError | Trigger | iStore |
| Execute | Procedure | dbo.uspPrintError | Trigger | iStore |
Dependencies
| Reference Type | Object Type | Referencing Object | Child Type | Child Object |
| Select | View | Sales.vStoreWithDemographics | ||
| Select | Table | Sales.Individual | Trigger | iuIndividual |
automatically generated
| Table | Sales.Store |
| Description | Customers (resellers) of Adventure Works products. |
| Column | Data Type | Nullable | Default | Description / PK / Index |
| CustomerID | int | not null | Primary key. Foreign key to Customer.CustomerID. PK_Store_CustomerID | |
| Name | Name | not null | Name of the store. | |
| SalesPersonID | int | null | ID of the sales person assigned to the customer. Foreign key to SalesPerson.SalesPersonID. IX_Store_SalesPersonID | |
| Demographics | XML | null | Demographic informationg about the store such as the number of employees, annual sales and store type. PXML_Store_Demographics | |
| rowguid | uniqueidentifier | not null | (NEWID()) | ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample. AK_Store_rowguid |
| ModifiedDate | datetime | not null | (GETDATE()) | Date and time the record was last updated. |
| Relation | Column | Referenced Column |
| Sales.Customer | CustomerID | CustomerID |
| Sales.SalesPerson | SalesPersonID | SalesPersonID |
| Detail Table | Column | Referencing Column |
| Sales.StoreContact | CustomerID | CustomerID |
| Triggers | Type |
| iStore | ON INSERT |
| Dependency Type | Object Type | Referenced Object | Child Type | Child Object |
| Data Type | Type | dbo.Name | ||
| Schema | Schema | Sales | ||
| Data Type | XML Schema Collection | Sales.StoreSurveySchemaCollection | ||
| Select | Table | Sales.Individual | Trigger | iStore |
| Execute | Procedure | dbo.uspLogError | Trigger | iStore |
| Execute | Procedure | dbo.uspPrintError | Trigger | iStore |
| Reference Type | Object Type | Referencing Object | Child Type | Child Object |
| Select | View | Sales.vStoreWithDemographics | ||
| Select | Table | Sales.Individual | Trigger | iuIndividual |