SQL Server CLR custom type Store Object

Source: Internet
Author: User

Q: Can I store my business objects in SQL Server 2005 using CLR user-defined types?

A: Implementing a SQL CLR user-defined type (UDT) is very simple, like giving. NET class or struct to add some extra fragments. These include attributes (SqlUserDefinedTypeAttribute), interfaces (inullable), and some additional methods (Null () and Parse ()). The consequence of this simplicity is that an experienced developer can convert a business object into a SQL CLR user-defined type in less than 5 minutes.

The design goal of SQL Server 2005 is not for object-oriented database management systems. It is also a standard SQL database management system, and the ability of user-defined types should also be treated as a type of system extension, not an object. Developers should carefully weigh their choices when deciding whether to use existing business objects as CLR UDT.

Each time a method or property of an instance of a type is accessed, the instance should be serialized before the method is accessed. Therefore, it is best to rely on those comparable types based on their serialized bytes. Developers should try to use only those user-defined types that can answer questions automatically. For example, the following C # class is less than a user-defined type:

class Product
{
  public string Name;
  public string Description;
  public decimal price;
}

If a query is for such a type of field, each row must be drag to answer the following question, "What product is worth 10 dollars?" This is because we cannot assume that all 10 dollars of products have the same binary representation. Drag of each row in a large table, such as a table with millions of products, can be a serious test of performance.

In addition to the performance challenges, there are also standardization issues. For example, suppose this type, how can a company store two descriptions for the same product, and make sure that there is only one valid price for the product?

It is best to stick to types that can answer questions and do not bring drag to the line.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.