January 20, 2023 at 12:00 am
Comments posted to this topic are about the item More ANSI_PADDING Tables
January 20, 2023 at 8:23 am
The correct answer to this will depend on the setting of ANSI_NULL_DFLT_ON, since the NULLability of the CHAR column isn't specified.
January 20, 2023 at 8:50 am
I think you might be missing '2' in the answer...;0)
January 20, 2023 at 1:32 pm
I noticed that the actual answer did not appear in the results. I tried to guess the intent of the question, but was wrong.
January 20, 2023 at 2:01 pm
I noticed that the actual answer did not appear in the results. I tried to guess the intent of the question, but was wrong.
There are two results that can be correct, depending on if the CHARCOL column is nullable or not. Both are among the provided alternatives.
If connecting through the native client or ODBC, the ANSI_NULL_DEFAULT_ON setting is ON after connection, so if this hasn't been explicitly changed by the connecting application, you will get the behaviour where trailing blanks are trimmed. If connecting through DB-library, however, ANSI_NULL_DEFAULT_ON will be OFF, and in that case the CHAR column will be NOT NULL, and the value will be padded with blanks to the declared size.
To quote from Books Online:
For a more reliable operation of Transact-SQL scripts that are used in databases with different nullability settings, it is better to specify NULL or NOT NULL in CREATE TABLE and ALTER TABLE statements.
January 20, 2023 at 4:30 pm
The correct answer to this will depend on the setting of ANSI_NULL_DFLT_ON, since the NULLability of the CHAR column isn't specified.
The default is NULL for columns if not specified for most drivers. As you noted, this might be different, but the question is based around defaults. I'll adjust the question to say SSMS, which connects with a .NET provider.
January 20, 2023 at 4:41 pm
Scott Arendt wrote:I noticed that the actual answer did not appear in the results. I tried to guess the intent of the question, but was wrong.
There are two results that can be correct, depending on if the CHARCOL column is nullable or not. Both are among the provided alternatives.
If connecting through the native client or ODBC, the ANSI_NULL_DEFAULT_ON setting is ON after connection, so if this hasn't been explicitly changed by the connecting application, you will get the behaviour where trailing blanks are trimmed. If connecting through DB-library, however, ANSI_NULL_DEFAULT_ON will be OFF, and in that case the CHAR column will be NOT NULL, and the value will be padded with blanks to the declared size.
To quote from Books Online:
For a more reliable operation of Transact-SQL scripts that are used in databases with different nullability settings, it is better to specify NULL or NOT NULL in CREATE TABLE and ALTER TABLE statements.
Is DB-library used anymore? I recall it from many years ago, but haven't seen it mentioned recently.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply