Editing Sales.Individual (table)

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
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.Individual
 
| Sales.Individual
|- valign="top"
+
|-
| '''Description
 
| Demographic data about customers that purchase Adventure Works products online.
 
 
|}
 
|}
  
=== 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 17: Line 15:
 
| '''Nullable
 
| '''Nullable
 
| '''Default
 
| '''Default
| '''Description
+
| '''PK
 
+
| '''Index
|- valign="top"
+
 +
|-
 
| CustomerID
 
| CustomerID
 
| int
 
| int
 
| not null
 
| not null
 
|  
 
|  
| Unique customer identification number. Foreign key to Customer.CustomerID.
+
| PK_Individual_CustomerID
|- valign="top"
+
|
 +
|-
 
| ContactID
 
| ContactID
 
| int
 
| int
 
| not null
 
| not null
 
|  
 
|  
| Identifies the customer in the Contact table. Foreign key to Contact.ContactID.
+
|  
|- valign="top"
+
|
 +
|-
 
| Demographics
 
| Demographics
 
| xml
 
| xml
 
| null
 
| null
 
|  
 
|  
| Personal information such as hobbies, and income collected from online shoppers. Used for sales analysis.
+
|  
|- valign="top"
+
| PXML_Individual_DemographicsXMLPATH_Individual_DemographicsXMLPROPERTY_Individual_DemographicsXMLVALUE_Individual_Demographics
 +
|-
 
| ModifiedDate
 
| ModifiedDate
 
| datetime
 
| datetime
 
| not null
 
| not null
 
| (getdate())
 
| (getdate())
| 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_Individual_CustomerID
 
| CustomerID
 
|}
 
  
=== Indexes ===
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
| '''Index
 
| '''Type
 
| '''Columns
 
 
|- valign="top"
 
| PXML_Individual_Demographics
 
|
 
| Demographics
 
|- valign="top"
 
| XMLPATH_Individual_Demographics
 
|
 
| Demographics
 
|- valign="top"
 
| XMLPROPERTY_Individual_Demographics
 
|
 
| Demographics
 
|- valign="top"
 
| XMLVALUE_Individual_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 86: Line 55:
 
| '''Column
 
| '''Column
 
| '''Referenced Column
 
| '''Referenced Column
 
+
|- valign="top"
+
|-
 
| [[Person.Contact_(table)|Person.Contact]]
 
| [[Person.Contact_(table)|Person.Contact]]
 
| ContactID
 
| ContactID
 
| ContactID
 
| ContactID
|- valign="top"
+
|-
 
| [[Sales.Customer_(table)|Sales.Customer]]
 
| [[Sales.Customer_(table)|Sales.Customer]]
 
| CustomerID
 
| CustomerID
Line 97: Line 66:
 
|}
 
|}
  
=== 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"
| '''Trigger
+
| '''Triggers
 
| '''Type
 
| '''Type
 
+
|- valign="top"
+
|-
 
| iuIndividual
 
| iuIndividual
 
| ON INSERT UPDATE
 
| ON INSERT UPDATE
 
|}
 
|}
 
==== Trigger iuIndividual ====
 
<pre>
 
CREATE TRIGGER [Sales].[iuIndividual] ON [Sales].[Individual]
 
AFTER INSERT, UPDATE NOT FOR REPLICATION AS
 
BEGIN
 
    DECLARE @Count int;
 
 
    SET @Count = @@ROWCOUNT;
 
    IF @Count = 0
 
        RETURN;
 
 
    SET NOCOUNT ON;
 
 
    -- Only allow the Customer to be a Store OR Individual
 
    IF EXISTS (SELECT * FROM inserted INNER JOIN [Sales].[Store]
 
        ON inserted.[CustomerID] = [Sales].[Store].[CustomerID])
 
    BEGIN
 
        -- Rollback any active or uncommittable transactions
 
        IF @@TRANCOUNT > 0
 
        BEGIN
 
            ROLLBACK TRANSACTION;
 
        END
 
    END;
 
 
    IF UPDATE([CustomerID]) OR UPDATE([Demographics])
 
    BEGIN
 
        UPDATE [Sales].[Individual]
 
        SET [Sales].[Individual].[Demographics] = N'<IndividualSurvey xmlns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey">
 
            <TotalPurchaseYTD>0.00</TotalPurchaseYTD>
 
            </IndividualSurvey>'
 
        FROM inserted
 
        WHERE [Sales].[Individual].[CustomerID] = inserted.[CustomerID]
 
            AND inserted.[Demographics] IS NULL;
 
       
 
        UPDATE [Sales].[Individual]
 
        SET [Demographics].modify(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
 
            insert <TotalPurchaseYTD>0.00</TotalPurchaseYTD>
 
            as first
 
            into (/IndividualSurvey)[1]')
 
        FROM inserted
 
        WHERE [Sales].[Individual].[CustomerID] = inserted.[CustomerID]
 
            AND inserted.[Demographics] IS NOT NULL
 
            AND inserted.[Demographics].exist(N'declare default element namespace
 
                "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey";
 
                /IndividualSurvey/TotalPurchaseYTD') <> 1;
 
    END;
 
END;
 
</pre>
 
 
=== References ===
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
| '''Dependency Type
 
| '''Object Type
 
| '''Referenced Object
 
 
| '''Child Type
 
| '''Child Object
 
 
|- valign="top"
 
| Schema
 
| Schema
 
| [[Sales_(schema)|Sales]]
 
 
|
 
|
 
|- valign="top"
 
| Data Type
 
| XML Schema Collection
 
| [[Sales.IndividualSurveySchemaCollection_(xml schema collection)|Sales.IndividualSurveySchemaCollection]]
 
 
|
 
|
 
|- valign="top"
 
| Update
 
| Table
 
| [[Sales.Individual_(table)|Sales.Individual]]
 
 
| Trigger
 
| iuIndividual
 
|- valign="top"
 
| Select
 
| Table
 
| [[Sales.Store_(table)|Sales.Store]]
 
 
| Trigger
 
| iuIndividual
 
|}
 
 
=== Dependencies ===
 
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse"
 
|- style="background:silver"
 
| '''Reference Type
 
| '''Object Type
 
| '''Referencing Object
 
 
| '''Child Type
 
| '''Child Object
 
 
|- valign="top"
 
| Select
 
| View
 
| [[Sales.vIndividualCustomer_(view)|Sales.vIndividualCustomer]]
 
 
|
 
|
 
|- valign="top"
 
| Select
 
| View
 
| [[Sales.vIndividualDemographics_(view)|Sales.vIndividualDemographics]]
 
 
|
 
|
 
|- valign="top"
 
| Select
 
| SQL table-valued-function
 
| [[dbo.ufnGetContactInformation_(function)|dbo.ufnGetContactInformation]]
 
 
|
 
|
 
|- valign="top"
 
| Update
 
| Table
 
| [[Sales.Individual_(table)|Sales.Individual]]
 
 
| Trigger
 
| iuIndividual
 
|- valign="top"
 
| Update
 
| Table
 
| [[Sales.SalesOrderDetail_(table)|Sales.SalesOrderDetail]]
 
 
| Trigger
 
| iduSalesOrderDetail
 
|- valign="top"
 
| Select
 
| Table
 
| [[Sales.Store_(table)|Sales.Store]]
 
 
| Trigger
 
| iStore
 
|}
 
 
 
 
== automatically generated ==
 
== automatically generated ==
  
Line 259: Line 83:
 
| Sales.Individual
 
| Sales.Individual
 
|- valign="top"
 
|- valign="top"
 +
 
| '''Description
 
| '''Description
 
| Demographic data about customers that purchase Adventure Works products online.
 
| Demographic data about customers that purchase Adventure Works products online.
 
|-
 
|-
 +
 
|}
 
|}
  
Line 341: Line 167:
 
| Schema
 
| Schema
 
| Schema
 
| Schema
| [[Sales_(schema)|Sales]]
+
| [[Sales_(schema)|false.Sales]]
  
 
|  
 
|  
Line 348: Line 174:
 
| Data Type
 
| Data Type
 
| XML Schema Collection
 
| XML Schema Collection
| [[Sales.IndividualSurveySchemaCollection_(xml_schema_collection)|Sales.IndividualSurveySchemaCollection]]
+
| [[Sales.IndividualSurveySchemaCollection_(xml_schema_collection)|true.IndividualSurveySchemaCollection]]
  
 
|  
 
|  
Line 355: Line 181:
 
| Update
 
| Update
 
| Table
 
| Table
| [[Sales.Individual_(table)|Sales.Individual]]
+
| [[Sales.Individual_(table)|true.Individual]]
  
 
| Trigger
 
| Trigger
Line 362: Line 188:
 
| Select
 
| Select
 
| Table
 
| Table
| [[Sales.Store_(table)|Sales.Store]]
+
| [[Sales.Store_(table)|true.Store]]
  
 
| Trigger
 
| Trigger
Line 381: Line 207:
 
| Select
 
| Select
 
| View
 
| View
| [[Sales.vIndividualCustomer_(view)|Sales.vIndividualCustomer]]
+
| [[Sales.vIndividualCustomer_(view)|true.vIndividualCustomer]]
  
 
|  
 
|  
Line 388: Line 214:
 
| Select
 
| Select
 
| View
 
| View
| [[Sales.vIndividualDemographics_(view)|Sales.vIndividualDemographics]]
+
| [[Sales.vIndividualDemographics_(view)|true.vIndividualDemographics]]
  
 
|  
 
|  
Line 395: Line 221:
 
| Select
 
| Select
 
| SQL table-valued-function
 
| SQL table-valued-function
| [[dbo.ufnGetContactInformation_(function)|dbo.ufnGetContactInformation]]
+
| [[dbo.ufnGetContactInformation_(function)|true.ufnGetContactInformation]]
  
 
|  
 
|  
Line 402: Line 228:
 
| Update
 
| Update
 
| Table
 
| Table
| [[Sales.Individual_(table)|Sales.Individual]]
+
| [[Sales.Individual_(table)|true.Individual]]
  
 
| Trigger
 
| Trigger
Line 409: Line 235:
 
| Update
 
| Update
 
| Table
 
| Table
| [[Sales.SalesOrderDetail_(table)|Sales.SalesOrderDetail]]
+
| [[Sales.SalesOrderDetail_(table)|true.SalesOrderDetail]]
  
 
| Trigger
 
| Trigger
Line 416: Line 242:
 
| Select
 
| Select
 
| Table
 
| Table
| [[Sales.Store_(table)|Sales.Store]]
+
| [[Sales.Store_(table)|true.Store]]
  
 
| Trigger
 
| Trigger
 
| iStore
 
| iStore
 
|}
 
|}

Please note that all contributions to dbscript Online Help may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Project:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)