Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Default value for columns

When you use default value for a column in SQL Server Management Studio table designer, SSMS change your default and stand Parenthesis around of that (In all editions and all versions of SQL Server). For example if you set 0 as default value, this default changed to (0). I don't know why sql server use parenthesis, and is there a practical reason.

Thanks in advance.

like image 489
mehdi lotfi Avatar asked Apr 21 '26 06:04

mehdi lotfi


2 Answers

There are certain types of objects, such as DEFAULTs and CHECK constraints that SQL Server doesn't store the original, textual form of - in contrast with, say, stored procedures, where you can (absent encryption) always retrieve it in the exact form you gave it to the server - complete with any white space, formatting, comments, etc.

Because SQL Server doesn't store the textual form, it always has to re-generate textual forms to show to users when they ask for such objects. When and where it chooses to insert parentheses can be a bit of a mystery (it's not documented) but since they don't change the meaning of the expression, they shouldn't be a concern.

like image 66
Damien_The_Unbeliever Avatar answered Apr 24 '26 00:04

Damien_The_Unbeliever


Actually, 0 and (0) will evaluate to the same result, so there is nothing to really overcome. Ignore it. It's just how SQL stores them internally and a visibility issue. It does that is you do it interactively as well. Not sure why does this , but not to worry.

like image 37
Hamed Kamrava Avatar answered Apr 24 '26 01:04

Hamed Kamrava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!