AdventureWorks 中的数据类型
本主题列出了 AdventureWorks 示例数据库中出现的 Microsoft.NET Framework CLR 用户定义类型、MicrosoftSQL Server 系统数据类型和 Transact-SQL 别名数据类型。
CLR 用户定义类型
下表列出了 AdventureWorks 中使用 CLR 用户定义类型的示例。可以从 Microsoft SQL Server Samples and Community Projects(Microsoft SQL Server 示例和社区项目)主页下载这些示例。有关 CLR 用户定义类型的详细信息,请参阅 CLR 用户定义类型。
示例 |
说明 |
---|---|
SQL Server 数据库引擎示例 |
使用 C# 定义 Currency 用户定义数据类型。此用户定义数据类型封装了金额和区域性,该区域性有助于确定使用正确的方法将金额显示为该区域中的货币值。此示例还提供了返回 Currency 用户定义类型实例的货币换算函数。 |
UDT 实用工具 |
包含向 Transact-SQL 公开程序集元数据的函数:以表的形式返回程序集中类型的示例流式表值函数,以及返回用户定义类型的字段、方法和属性的函数。 |
用户定义数据类型 (UDT) 示例 |
介绍如何在 Transact-SQL 和使用 System.Data.SqlClient 的客户端应用程序中创建和使用简单用户定义数据类型。 |
UTF8 字符串用户定义数据类型 (UDT) |
实现了一种 UTF-8 用户定义数据类型,此数据类型扩展了数据库的类型系统以便可以存储 UTF-8 编码的值。此类型还实现了 Unicode 字符串与 UTF-8 字符串之间的转换。 |
识别日历的日期/时间 UDT |
定义了两种用户定义数据类型(CADatetime 和 CADate),它们提供了与日历相似的日期和时间处理方式。 |
数组参数示例 |
通过使用 CLR 用户定义数据类型将一组信息从客户端传递到服务器上的 CLR 存储过程。 |
系统数据类型
下表列出了 SQL Server 系统数据类型以及使用这些系统数据类型的表和列。有关系统数据类型的详细信息,请参阅数据类型 (Transact-SQL)。
数据类型 |
在此 schema.table.column 中使用 |
---|---|
bigint |
未使用。 |
bit |
请参阅下面的“别名数据类型”节中的 Flag 和 NameStyle。 |
char 或nchar |
HumanResources.Employee.Gender HumanResources.Employee.MaritalStatus Person.StateProvince.StateProvinceCode Production.BillOfMaterials.UnitMeasureCode Production.Culture.CultureID Production.Document.Revision Production.Product.Class Production.Product.ProductLine Production.Product.SizeUnitMeasureCode Production.Product.Style Production.Product.WeightUnitMeasureCode Production.ProductModelProductDescriptionCulture.CultureID Production.TransactionHistory.TransactionType Production.TransactionHistoryArchive.TransactionType Production.UnitMeasure.UnitMeasureCode Purchasing.ProductVendor.UnitMeasureCode Sales.CountryRegionCurrency.CurrencyCode Sales.CurrencyRate.FromCurrencyCode Sales.CurrencyRate.ToCurrencyCode Sales.Customer.CustomerType Sales.Currency.CurrencyCode |
datetime |
所有表中的 ModifiedDate 列 dbo.AWBuildVersion.VersionDate dbo.DatabaseLog.PostTime HumanResources.Employee.BirthDate HumanResources.Employee.HireDate HumanResources.EmployeeDepartmentHistory.EndDate HumanResources.EmployeeDepartmentHistory.StartDate HumanResources.EmployeePayHistory.RateChangeDate HumanResources.Shift.EndTime HumanResources.Shift.StartTime Production.BillOfMaterials.EndDate Production.BillOfMaterials.StartDate Production.Product.DiscontinuedDate Production.Product.SellEndDate Production.Product.SellStartDate Production.ProductCostHistory.EndDate Production.ProductCostHistory.StartDate Production.ProductListPriceHistory.EndDate Production.ProductListPriceHistory.StartDate Production.TransactionHistory.TransactionDate Production.TransactionHistoryArchive.TransactionDate Production.WorkOrder.DueDate Production.WorkOrder.EndDate Production.WorkOrder.StartDate Production.WorkOrderRouting.ActualEndDate Production.WorkOrderRouting.ActualStartDate Production.WorkOrderRouting.ScheduledEndDate Production.WorkOrderRouting.ScheduledStartDate Purchasing.ProductVendor.LastReceiptDate Purchasing.PurchaseOrderDetail.DueDate Purchasing.PurchaseOrderHeader.OrderDate Purchasing.PurchaseOrderHeader.ShipDate Sales.SalesCurrencyRate.CurrencyRateDate Sales.SalesOrderHeader.DueDate Sales.SalesOrderHeader.OrderDate Sales.SalesOrderHeader.ShipDate Sales.SalesPersonQuotaHistory.QuotaDate Sales.SalesTerritoryHistory.EndDate Sales.SalesTerritoryHistory.StartDate Sales.ShoppingCartItem.DateCreated Sales.SpecialOfferEndDate Sales.SpecialOfferStartDate |
decimal |
Production.BillOfMaterials.PerAssemblyQty Production.Location.Availability Production.Product.Weight Purchasing.PurchaseOrderDetail.ReceivedQty Purchasing.PurchaseOrderDetail.RejectedQty Purchasing.PurchaseOrderDetail.StockedQty Production.WorkOrderRouting.ActualResourcesHrs |
float |
未使用。 |
image |
未使用。请参阅 varbinary(max)。 |
int |
所有表。 |
money |
HumanResources.EmployeePayHistory.Rate Production.Product.ListPrice Production.Product.StandardCost Production.ProductCostHistory.StandardCost Production.ProductListPriceHistory.ListPrice Production.TransactionHistory.ActualCost Production.TransactionHistoryArchive.ActualCost Production.WorkOrderRouting.PlannedCost Production.WorkOrderRouting.ActualCost Purchasing.ProductVendor.LastReceiptCost Purchasing.ProductVendor.StandardPrice Purchasing.PurchaseOrderDetail.LineTotal Purchasing.PurchaseOrderDetail.UnitPrice Purchasing.PurchaseOrderHeader.Freight Purchasing.PurchaseOrderHeader.SubTotal Purchasing.PurchaseOrderHeader.TaxAmt Purchasing.PurchaseOrderHeader.TotalDue Purchasing.ShipMethod.ShipBase Purchasing.ShipMethod.ShipRate Sales.CurrencyRate.AverageRate Sales.CurrencyRate.EndOfDayRate Sales.SalesOrderDetail.UnitPrice Sales.SalesOrderDetail.UnitPriceDiscount Sales.SalesOrderHeader.Freight Sales.SalesOrderHeader.SubTotal Sales.SalesOrderHeader.TaxAmt Sales.SalesOrderHeader.TotalDue Sales.SalesPerson.Bonus Sales.SalesPerson.SalesLastYear Sales.SalesPerson.SalesYTD Sales.SalesPersonQuotaHistory.SalesQuota Sales.SalesTerritory.CostLastYear Sales.SalesTerritory.CostYTD Sales.SalesTerritory.SalesLastYear Sales.SalesTerritory.SalesYTD |
numeric |
Sales.SalesOrderDetail.LineTotal |
smallint |
HumanResources.Department.DepartmentID HumanResources.Employee.SickLeaveHours HumanResources.Employee.VacationHours HumanResources.EmployeeDepartmentHistory.DepartmentID Production.BillOfMaterials.BOMLevel Production.Location.LocationID Production.Product.SafetyStockLevel Production.Product.ReorderPoint Production.ProductInventory.Quantity Production.ProductInventory.LocationID Production.WorkOrder.ScrappedQty Production.WorkOrder.ScrapReasonID Production.WorkOrderRouting.OperationSequence Production.WorkOrderRouting.LocationID Purchasing.PurchaseOrderDetail.OrderQty Sales.CreditCard.ExpYear Sales.SalesOrderDetail.OrderQty |
smallmoney |
Production.Location.CostRate Sales.SalesPerson.CommissionPct Sales.SalesTaxRate.TaxRate Sales.SpecialOffer.DiscountPct |
sysname |
dbo.DatabaseLog.DatabaseUser dbo.DatabaseLog.Event dbo.DatabaseLog.Schema dbo.DatabaseLog.Object |
text 或ntext |
未使用。请参阅 varchar(max) 或 nvarchar(max)。 |
tinyint |
dbo.AWBuildVersion.SystemInformationID HumanResources.EmployeePayHistory.PayFrequency HumanResources.EmployeeDepartmentHistory.ShiftID HumanResources.EmployePayHistory.Rate Production.Document.Status Production.ProductInventory.Bin Purchasing.PurchaseOrderHeader.RevisionNumber Purchasing.PurchaseOrderHeader.Status Purchasing.Vendor.CreditRating Sales.CreditCard.ExpMonth Sales.SalesOrderHeader.RevisionNumber Sales.SalesOrderHeader.Status Sales.SalesTaxRate.TaxType |
uniqueidentifier (GUID) |
请参阅下面架构中的表的 ROWGUID 列:
在 AdventureWorks 中,复制示例使用了 ROWGUID 列。 |
varbinary(max) |
Production.Document.Document Production.ProductPhoto.LargePhoto Production.ProductPhoto.ThumbnailPhoto |
varchar 或nvarchar |
所有表。 |
varchar(max) 或 nvarchar(max) |
Production.Document.DocumentSummary dbo.DatabaseLog.TSQL |
xml |
dbo.DatabaseLog.XmlEvent HumanResources.JobCandidate.Resume Person.Contact.AdditionalContactInfo Production.Illustration.Diagram Production.ProductModel.CatalogDescription Production.ProductModel.Instructions Sales.Individual.Demographics Sales.Store.Demographics |
别名数据类型
下表列出了别名数据类型、Transact-SQL 用户定义数据类型以及使用这些数据类型的表和列。有关别名数据类型的详细信息,请参阅使用别名数据类型。
数据类型名称 |
定义为 |
在此 schema.table.column 中使用 |
---|---|---|
AccountNumber |
nvarchar(15) |
Sales.SalesOrderHeader.AccountNumber Purchasing.Vendor.AccountNumber |
Flag |
bit |
HumanResources.Employee.CurrentFlag HumanResources.Employee.SalariedFlag Person.StateProvince.IsOnlyStateProvinceFlag Production.Product.FinishedGoodsFlag Production.Product.MakeFlag Production.ProductProductPhoto.Primary Purchasing.Vendor.ActiveFlag Purchasing.Vendor.PreferredVendorStatusFlag Sales.SalesOrderHeader.OnlineOrderFlag |
NameStyle |
bit |
Person.Contact.NameStyle |
Name |
nvarchar(50) |
HumanResources.Department.GroupName HumanResources.Department.Name HumanResources.Shift.Name Person.AddressType.Name Person.Contact.FirstName Person.Contact.LastName Person.Contact.MiddleName Person.ContactType.Name Person.CountryRegion.Name Person.StateProvince.Name Production.Culture.Name Production.Location.Name Production.Product.Name Production.ProductCategory.Name Production.ProductModel.Name Production.ProductReview.ReviewerName Production.ProductSubcategory.Name Production.ScrapReason.Name Production.UnitMeasure.Name Purchasing.ShipMethod.Name Purchasing.Vendor.Name Sales.Currency.Name Sales.SalesReason.Name Sales.SalesReason.ReasonType Sales.SalesTaxRate.Name Sales.SalesTerritory.Name Sales.Store.Name |
OrderNumber |
nvarchar(25) |
Sales.SalesOrderHeader.SalesOrderNumber |
Phone |
nvarchar(25) |
Person.Contact.Phone |