Difference between revisions of "Sales.Store (table)"

From dbscript Online Help
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
  
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
|-
+
|- valign="top"
 
| '''Table
 
| '''Table
 
| Sales.Store
 
| Sales.Store
Line 8: Line 8:
 
| '''Description
 
| '''Description
 
| Customers (resellers) of Adventure Works products.
 
| Customers (resellers) of Adventure Works products.
|-
 
 
|}
 
|}
  
 
+
=== 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 17:
 
| '''Nullable
 
| '''Nullable
 
| '''Default
 
| '''Default
| '''Description / PK / Index
+
| '''Description
+
 
 
|- valign="top"
 
|- valign="top"
 
| CustomerID
 
| CustomerID
Line 25: Line 24:
 
| not null
 
| not null
 
|  
 
|  
| Primary key. Foreign key to Customer.CustomerID.<br />PK_Store_CustomerID
+
| Primary key. Foreign key to Customer.CustomerID.
 
|- valign="top"
 
|- valign="top"
 
| Name
 
| Name
Line 31: Line 30:
 
| not null
 
| not null
 
|  
 
|  
| Name of the store.<br />
+
| Name of the store.
 
|- valign="top"
 
|- valign="top"
 
| SalesPersonID
 
| SalesPersonID
Line 37: Line 36:
 
| null
 
| null
 
|  
 
|  
| ID of the sales person assigned to the customer. Foreign key to SalesPerson.SalesPersonID.<br />IX_Store_SalesPersonID
+
| ID of the sales person assigned to the customer. Foreign key to SalesPerson.SalesPersonID.
 
|- valign="top"
 
|- valign="top"
 
| Demographics
 
| Demographics
Line 43: Line 42:
 
| null
 
| null
 
|  
 
|  
| Demographic informationg about the store such as the number of employees, annual sales and store type.<br />PXML_Store_Demographics
+
| 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 48:
 
| not null
 
| not null
 
| (newid())
 
| (newid())
| ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.<br />AK_Store_rowguid
+
| ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
 
|- valign="top"
 
|- valign="top"
 
| ModifiedDate
 
| ModifiedDate
Line 55: Line 54:
 
| not null
 
| not null
 
| (getdate())
 
| (getdate())
| Date and time the record was last updated.<br />
+
| 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
 +
|- valign="top"
 +
| PK_Store_CustomerID
 +
| CustomerID
 +
|}
  
 +
=== Indexes ===
 +
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 +
|- style="background:silver"
 +
| '''Index
 +
| '''Type
 +
| '''Columns
  
 +
|- valign="top"
 +
| AK_Store_rowguid
 +
| Unique
 +
| rowguid
 +
|- valign="top"
 +
| IX_Store_SalesPersonID
 +
|
 +
| SalesPersonID
 +
|- valign="top"
 +
| 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 65: Line 94:
 
| '''Column
 
| '''Column
 
| '''Referenced Column
 
| '''Referenced Column
+
 
|-
+
|- valign="top"
 
| [[Sales.Customer_(table)|Sales.Customer]]
 
| [[Sales.Customer_(table)|Sales.Customer]]
 
| CustomerID
 
| CustomerID
 
| CustomerID
 
| CustomerID
|-
+
|- valign="top"
 
| [[Sales.SalesPerson_(table)|Sales.SalesPerson]]
 
| [[Sales.SalesPerson_(table)|Sales.SalesPerson]]
 
| SalesPersonID
 
| SalesPersonID
Line 76: Line 105:
 
|}
 
|}
  
 
+
=== 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 82: Line 111:
 
| '''Column
 
| '''Column
 
| '''Referencing Column
 
| '''Referencing Column
+
 
|-
+
|- valign="top"
 
| [[Sales.StoreContact_(table)|Sales.StoreContact]]
 
| [[Sales.StoreContact_(table)|Sales.StoreContact]]
 
| CustomerID
 
| CustomerID
Line 89: Line 118:
 
|}
 
|}
  
 
+
=== 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"
| '''Triggers
+
| '''Trigger
 
| '''Type
 
| '''Type
+
 
|-
+
|- valign="top"
 
| iStore
 
| iStore
 
| ON INSERT
 
| ON INSERT
 
|}
 
|}
  
 +
==== 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 110: Line 179:
 
| '''Child Object
 
| '''Child Object
  
|-
+
|- valign="top"
 
| Data Type
 
| Data Type
 
| Type
 
| Type
Line 117: Line 186:
 
|  
 
|  
 
|  
 
|  
|-
+
|- valign="top"
 +
| Schema
 +
| Schema
 +
| [[Sales_(schema)|Sales]]
 +
 
 +
|
 +
|
 +
|- valign="top"
 
| Data Type
 
| Data Type
 
| XML Schema Collection
 
| XML Schema Collection
| [[Sales.StoreSurveySchemaCollection_(xml_schema_collection)|Sales.StoreSurveySchemaCollection]]
+
| [[Sales.StoreSurveySchemaCollection_(xml schema collection)|Sales.StoreSurveySchemaCollection]]
  
 
|  
 
|  
 
|  
 
|  
|-
+
|- valign="top"
 
| Select
 
| Select
 
| Table
 
| Table
Line 131: Line 207:
 
| Trigger
 
| Trigger
 
| iStore
 
| iStore
|-
+
|- valign="top"
 
| Execute
 
| Execute
 
| Procedure
 
| Procedure
Line 138: Line 214:
 
| Trigger
 
| Trigger
 
| iStore
 
| iStore
|-
+
|- valign="top"
 
| Execute
 
| Execute
 
| Procedure
 
| Procedure
Line 147: Line 223:
 
|}
 
|}
  
 
+
=== 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 157: Line 233:
 
| '''Child Object
 
| '''Child Object
  
|-
+
|- valign="top"
 
| Select
 
| Select
 
| View
 
| View
Line 164: Line 240:
 
|  
 
|  
 
|  
 
|  
|-
+
|- valign="top"
 
| Select
 
| Select
 
| Table
 
| Table
Line 172: Line 248:
 
| iuIndividual
 
| iuIndividual
 
|}
 
|}
 
  
  

Latest revision as of 23:17, 23 June 2010

wikibot[edit]

Table Sales.Store
Description Customers (resellers) of Adventure Works products.

Columns[edit]

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[edit]

Primary Key Columns
PK_Store_CustomerID CustomerID

Indexes[edit]

Index Type Columns
AK_Store_rowguid Unique rowguid
IX_Store_SalesPersonID SalesPersonID
PXML_Store_Demographics Demographics

Foreign Keys[edit]

Relation Column Referenced Column
Sales.Customer CustomerID CustomerID
Sales.SalesPerson SalesPersonID SalesPersonID

Detail Tables[edit]

Detail Table Column Referencing Column
Sales.StoreContact CustomerID CustomerID

Triggers[edit]

Trigger Type
iStore ON INSERT

Trigger iStore[edit]

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[edit]

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[edit]

Reference Type Object Type Referencing Object Child Type Child Object
Select View Sales.vStoreWithDemographics
Select Table Sales.Individual Trigger iuIndividual


automatically generated[edit]

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