The above function returns an integer value. To test this function, we will write some code as shown below –
Let us see another example which will fetch the number of orders processed by an employee for a given year. Write the following function in our query pad –
We will test this function with different years for an employee as shown below –
Table Valued Functions
Now let’s try an Inline Table valued function. Inline Table valued functions can return a row set using SQL Server Table datatype. You cannot perform addition logic in inline table valued functions. We will fetch the product details purchased by a customer as shown below –
To test this example we will use a select statement as shown below –
Another example of the Inline Table Valued Function is as shown below –
To test this function, we will use different years as shown below –
We will now see a Multi-Statement Table Valued Function. This function can be used to perform additional logic within the function. The code is as shown below –
To use the Multi-Statement Table Valued function, use this code –
Thay đổi cấu trúc bảng ALTER TABLE trong SQL
Thay đổi cấu trúc bảng.
Câu lệnh ALTER TABLE được sử dụng để thêm hoặc xoá cột trong một bảng.
ALTER TABLE tên_bảngADD tên_cột kiểu_dữ_liệu
ALTER TABLE tên_bảngDROP COLUMN tên_cột
Lưu ý: M…Read More
Từ khoá DISTINCT trong SQL không lấy giá trị trùng nhau
Câu lệnh SELECT sẽ trả về thông tin về các cột trong bảng. Nhưng nếu chúng ta không muốn lấy về các giá trị trùng nhau thì sau?
Với SQL, ta chỉ cần thêm từ khoá DISTINCT vào câu lệnh SELECT the…Read More
Tạo một CSDL trong SQL
Tạo một CSDL
CREATE DATABASE tên_CSDL
Tạo một bảng trong một CSDL
CREATE TABLE tên_bảng(tên_cột_1 kiểu_dữ_liệu,tên_cột_2 kiểu_dữ_liệu,.......)
Ví dụ
Tạo một bảng tên Person có bốn cột:&…Read More
0 nhận xét:
Post a Comment