Home All Groups Group Topic Archive Search About

CREATE TABLE Defaults have double passwords

Author
14 Jul 2006 8:43 PM
Dr. Network
SQL 2005, Service Pack 1 using SSMS:

I'm creating a table with default values for the columns. When I create the table, there are no parentheses around the default values. Then when I script out the table using SSMS, the default values have a double set of parentheses around them. Further, the values in SYS.SYSCOMMENTS for the columns have the double parentheses. I deliberately mixed up the order of the defaults in the creation script hoping to see if this made any difference. Here are the scripts:

The creation script:
create table dbo.TEST(
TEST_CDE char(5) NOT NULL,
Test1 int DEFAULT (1) NOT NULL,
TEST2 numeric(5,4) DEFAULT 2 NOT NULL,
Test3 numeric(11,2) NOT NULL DEFAULT 0,
Test4 numeric(11,2) DEFAULT 0 NOT NULL,
Test5 char(1) NULL) ON 'PRIMARY'

The output of scripting the table out:
CREATE TABLE [dbo].[TEST](
[TEST_CDE] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Test1] [int] NOT NULL DEFAULT ((1)),
[TEST2] [numeric](5, 4) NOT NULL DEFAULT ((2)),
[Test3] [numeric](11, 2) NOT NULL DEFAULT ((0)),
[Test4] [numeric](11, 2) NOT NULL DEFAULT ((0)),
[Test5] [char](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]

This is a problem as I have an application that I support that compares the creation script with the created table, looking for differences to see if I need to update the table structure, including the default values. It shows this difference between the two scripts.

Thanks,

Chuck Hawkins

Author
14 Jul 2006 10:18 PM
Erland Sommarskog
Dr. Network (charles.hawk***@jenzabar.net) writes:
> I'm creating a table with default values for the columns. When I create
> the table, there are no parentheses around the default values. Then when
> I script out the table using SSMS, the default values have a double set
> of parentheses around them. Further, the values in SYS.SYSCOMMENTS for
> the columns have the double parentheses. I deliberately mixed up the
> order of the defaults in the creation script hoping to see if this made
> any difference. Here are the scripts:

That's the way it is, and it's not much you can do about it. I had this
once explained by an SQL Server developer, but I've forgotten the details.

I guess you will have to adapt the table scripts to keep the compare tool
silent. Or learn the compare tool to disregard the parens.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button