Hình thức thứ hai, các OUTER ÁP DỤNG lệnh, hoạt động giống như một trái bên ngoài tham gia. Với việc sử dụng này, hàng từ các truy vấn chính được bao gồm trong tập hợp kết quả bất kể bảng ảo được trả lại bởi các chức năng người dùng định nghĩa là trống rỗng. | Part IV Developing with SQL Server Anderson Andrews 01-016 01-015 2001-11-16 00 00 Outer Banks 2001-11-05 00 00 Amazon Trek Lighthouses Andrews 01-012 2001-09-14 00 00 Gauley River Rafting Andrews 01-014 2001-10-03 00 00 Outer Banks Lighthouses Bettys 01-013 2001-09-15 00 00 Gauley River Rafting Bettys 01-015 2001-11-05 00 00 Amazon Trek The second form the OUTER APPLY command operates much like a left outer join. With this usage rows from the main query are included in the result set regardless of whether the virtual table returned by the user-defined function is empty. Creating functions with schema binding All three types of user-defined functions may be created with the significant added benefit of schema binding. Views may be schema bound in this way UDFs are like views both can be schema bound. This is one reason why you might choose a UDF over a stored procedure as stored procedures cannot be schema bound. Schema binding prevents the altering or dropping of any object on which the function depends. If a schema-bound function references TableA then columns may be added to TableA but no existing columns can be altered or dropped and neither can the table itself. To create a function with schema binding add the option after RETURNS and before AS during function creation as shown here CREATE FUNCTION FunctionName Input Parameters RETURNS DataType WITH SCHEMA BINDING AS BEGIN Code RETURNS Expression END Schema binding not only alerts the developer that the change will may affect an object it prevents the change. To remove schema binding so that changes can be made ALTER the function so that schema binding is no longer included. Multi-Statement Table-Valued Functions The multi-statement table-valued user-defined function combines the scalar function s ability to contain complex code with the inline table-valued function s ability to return a result set. This type of function creates a table variable and then populates it .