Sales Store (table)

wikibot

TableSales.Store
DescriptionCustomers (resellers) of Adventure Works products.

Columns

ColumnData TypeNullableDefaultDescription
CustomerIDintnot null Primary key. Foreign key to Customer.CustomerID.
Namedbo.Namenot null Name of the store.
SalesPersonIDintnull ID of the sales person assigned to the customer. Foreign key to SalesPerson.SalesPersonID.
Demographicsxmlnull Demographic informationg about the store such as the number of employees, annual sales and store type.
rowguiduniqueidentifiernot null(newid())ROWGUIDCOL number uniquely identifying the record. Used to support a merge replication sample.
ModifiedDatedatetimenot null(getdate())Date and time the record was last updated.

Primary Key

Primary KeyColumns
PK_Store_CustomerIDCustomerID

Indexes

IndexTypeColumns
AK_Store_rowguidUniquerowguid
IX_Store_SalesPersonID SalesPersonID
PXML_Store_Demographics Demographics

Foreign Keys

RelationColumnReferenced Column
Sales.CustomerCustomerIDCustomerID
Sales.SalesPersonSalesPersonIDSalesPersonID

Detail Tables

Detail TableColumnReferencing Column
Sales.StoreContactCustomerIDCustomerID

Triggers

TriggerType
iStoreON 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 TypeObject TypeReferenced ObjectChild TypeChild Object
Data TypeTypedbo.Name  
SchemaSchemaSales  
Data TypeXML Schema CollectionSales.StoreSurveySchemaCollection  
SelectTableSales.IndividualTriggeriStore
ExecuteProceduredbo.uspLogErrorTriggeriStore
ExecuteProceduredbo.uspPrintErrorTriggeriStore

Dependencies

Reference TypeObject TypeReferencing ObjectChild TypeChild Object
SelectViewSales.vStoreWithDemographics  
SelectTableSales.IndividualTriggeriuIndividual