"SQL Server Notes" nullability of SQL Server numeric types

Source: Internet
Author: User

Unlike programming languages such as C #, Java, in SQL Server, the initial value of a numeric type such as int is null, and the assignment operator can be assigned null, and a variable with a value of NULL cannot display its value in the message bar, only null is displayed in the result bar.

At the same time, the option to create a database causes the concatenated result to be null when the character data is concatenated with a "+" variable that has a null value.

1 DECLARE @ID INT;2 SET @ID=NULL;3 --output with "+" link null value and non-null value4 PRINT 'first output @id start'5 PRINT 'the values for the current @id are:'+CONVERT(NVARCHAR( -),@ID)6 PRINT 'First output @id complete'7 --output null and non-null values separately8 PRINT 'second output @id start'9 PRINT 'the values for the current @id are:'Ten PRINT CONVERT(NVARCHAR( -),@ID) One PRINT 'Second output @id complete' A --determine if @id is null by the IF decision - IF @ID  is NULL -     BEGIN the         SELECT @ID  asID; -         PRINT 'the values for the current @id are:'+'NULL' -     END - ELSE  +     BEGIN -         PRINT 'the values for the current @id are:'+CONVERT(NVARCHAR( -),@ID) +     END A PRINT 'assigns a value of 0 to @id' at --assigns a non-null value to the @id and outputs - SET @ID = 0 - PRINT 'the values for the current @id are:'+CONVERT(NVARCHAR( -),@ID) - GO
Sample Code

The first output @ID start the first output @ID finish The second output @ID start the current @ID value is : The second output @ID complete (1  rows affected) The value of the current @ID is :NULL for @ID is assigned a value of 0 Current the @ID value is :0
Output Results

Memory Essentials:

1. Unlike languages such as C #, the link string in SQL must convert non-character variables to type, otherwise an error will be made;

2. The result of a character type and a null connection may be null;

The initial value of the 3.SQL numeric variable is null;

4.SQL numeric variables can be assigned to null values directly with assignment operations;

5. Another: The value of the variable is null when a select is assigned and no record is queried.

"SQL Server Notes" nullability of SQL Server numeric types

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.