TAILIEUCHUNG - Beginning SQL Server 2005 for Developers From Novice to Professional phần 7

Cập nhật nhiều cột 8. Bây giờ chúng ta hãy di chuyển các cột cập nhật trong đó các loại dữ liệu không phù hợp với. không một công việc khá tốt khi nó có thể đảm bảo cập nhật xảy ra, và những ví dụ sau đây sẽ chứng minh như thế nào đối phó với cập nhật một kiểu dữ liệu số nguyên với một giá trị trong một loại dữ liệu . | CHAPTER 8 WORKING WITH THE DATA 295 SELECT CustomerFirstName CustomerLastName ClearedBalance UnclearedBalance FROM WHERE CustomerId 1 You should now see the alteration in place as shown in Figure 8-45. Figure 8-45. Updating multiple columns 8. Now let s move on to updating columns in which the data types don t match. SQL Server does a pretty good job when it can to ensure the update occurs and these following examples will demonstrate how well SQL Server copes with updating an integer data type with a value in a varchar data type. The first example will demonstrate where a varchar value will successfully update a column defined as integer. Enter the following code DECLARE @WrongDataType VARCHAR 20 SET @WrongDataType UPDATE SET ClearedBalance @WrongDataType WHERE CustomerId 1 9. Execute the code you should see the following message when you do 1 row s affected 10. The value has been placed into the ClearedBalance column for CustomerId 1. SQL Server has performed an internal data conversion known as an implicit data type conversion and has come up with a money data type from the value within varchar as this is what the column expects and therefore can successfully update the column. Here is the output as proof SELECT CustomerFirstName CustomerLastName ClearedBalance UnclearedBalance FROM WHERE CustomerId 1 Figure 8-46 shows the results of updating the column. Figure 8-46. Updating a column with internal data conversion 296 CHAPTER 8 WORKING WITH THE DATA 11. However in this next example the data type that SQL Server will come up with is a numeric data type. When we try to alter an integer-based data type bigint with this value which we can find in the AddressId column the UPDATE does not take place. Enter the following code DECLARE @WrongDataType VARCHAR 20 SET @WrongDataType UPDATE SET AddressId @WrongDataType WHERE CustomerId 1 12. Now execute

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.