tailieunhanh - Microsoft SQL Server 2005 Developer’s Guide- P6

Microsoft SQL Server 2005 Developer’s Guide- P6:This book is the successor to the SQL Server 2000 Developer’s Guide, which was extremely successful thanks to all of the supportive SQL Server developers who bought that edition of the book. Our first thanks go to all of the people who encouraged us to write another book about Microsoft’s incredible new relational database server: SQL Server 2005. | Chapter 3 Developing CLR Database Objects 99 User-Defined Types Another important new feature in SQL Server 2005 that is enabled by the integration of the .NET CLR is the ability to create true user-defined types UDTs . Using UDTs you can extend the raw types provided by SQL Server and add data types that are specialized to your application or environment. In the following example you ll see how to create a UDT that represents a gender code either M for male or F for female. While you could store this data in a standard one-byte character field using a UDT ensures that the field will accept only these two values with no additional need for triggers constraints or other data validation techniques. To create a UDT using Visual Studio 2005 select the New Project option give your project a name and click OK to create the project. For this project I used the name of Gender for the new UDT. After naming the project and clicking OK I filled out the New Database Reference dialog using the required connection values to deploy the project to the appropriate SQL Server system and database. Next I used the Project Add User-Defined Type option to display the Add New Item dialog that you can see in Figure 3-11. Figure 3-11 Creating a .NET SQL Server UDT 100 Microsoft SQL Server 2005 Developer s Guide Method Description IsNull This required method is used to indicate if the object is nullable. SQL Server 2005 requires all UDTs to implement nullability so this method must always return true. Parse This required method accepts a string parameter and stores it as a UDT. ToString This required method converts the contents of the UDT to a string. Default constructor This required method creates a new instance of the UDT. Table 3-1 Required UDT Methods Select User-Defined Type from the list of SQL Server templates. Enter the name that you want to assign to the class and then click Open to have Visual Studio generate a starter project file for the UDT. The starter project file .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.