TAILIEUCHUNG - Microsoft SQL Server 2008 R2 Unleashed- P207

Microsoft SQL Server 2008 R2 Unleashed- P207:SQL Server 2005 provided a number of significant new features and enhancements over what was available in SQL Server 2000. This is not too surprising considering there was a five-year gap between these major SQL Server 2008 is not as much of a quantum leap forward from SQL Server 2005 | 1854 CHAPTER 46 SQLCLR Developing SQL Server Objects in .NET IsNullIfEmpty Tells SQL Server that the UDA will return null if its aggregated value is empty that is if its value is 0 or the empty string and so on . Name Tells the deployment routine what to call the UDA when it is created in the database. MaxByteSize Tells SQL Server not to allow more than the specified number of bytes to be held in an instance of the UDA. You must specify this when using . For this example you implement a very simple UDA that sums values in an integer column but only if they are prime. Listing shows the code to do this. LISTING A UDA That Sums Prime Numbers using System using using using using Serializable IsInvariantToDuplicates false IsInvariantToNulls true IsInvariantToOrder true IsNullIfEmpty true public struct SumPrime SqlInt64 Sum private bool IsPrime SqlInt64 Number for int i 2 i Number i if Number i 0 return false return true public void Init Sum 0 Developing Custom Managed Database Objects 1855 public void Accumulate SqlInt64 Value if IsPrime Value Value 1 Sum Value public void Merge SumPrime Prime Sum public SqlInt64 Terminate return Sum In this code SQL Server first calls Init initializing the private Sum data field to 0. For each column value passed to the aggregate the Accumulate method is called wherein Sum is increased by the value of the column if it is prime. When multiple threads converge Merge is called adding the values stored in each instance as the Prime parameter to Sum. When the rowset has been completely parsed SQL Server calls Terminate wherein the accumulated value Sum is returned. Following are the results of testing SumPrime on an existing AdventureWorks2008 table SELECT TOP 10 AS PrimeSum FROM p .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.