Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2004
    Posts
    660

    Unanswered: default value for integer

    I had a field called camp is integer data type. I just found it had a default value, but the value is " (0) ", not just " 0 ". It should be 0, right? why it use (0), are they same? thanks.

  2. #2
    Join Date
    Dec 2004
    Location
    York, PA
    Posts
    95
    Quote Originally Posted by yyu
    I had a field called camp is integer data type. I just found it had a default value, but the value is " (0) ", not just " 0 ". It should be 0, right? why it use (0), are they same? thanks.
    And if you insert a new record with no value in the field then select that record what is the value?

    Sql stores the default and displays it that way No biggy

  3. #3
    Join Date
    Mar 2004
    Posts
    660
    I don't understand what you mean. If no value, i would like to have value 0, but why it use (0)?

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    It's just part of the syntax

    Code:
    USE Northwind
    GO
    
    SET NOCOUNT ON
    CREATE TABLE myTable99(
    		  Col1 int IDENTITY(1,1) NOT NULL PRIMARY KEY
    		, Col2 int NOT NULL DEFAULT(0)
    		, Col3 char(1)
    )
    GO
    
    INSERT INTO myTable99(Col3) SELECT 'x'
    
    SELECT * FROM myTable99
    
    INSERT INTO myTable99(Col2,Col3) SELECT 1,'y'
    
    SELECT * FROM myTable99
    GO
    
    SET NOCOUNT OFF
    DROP TABLE myTable99
    GO
    And stop using EM, you won't learn much using it....Do you have Books Online?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Mar 2004
    Posts
    660
    If using query Analayzer, we have to use (0). If i set default value in the Enterprise Manager, i just open the table in design view, and then just type 0 in the default, not type (0) in the default, is that correct? I don't have book online, can i check online? Thanks

  6. #6
    Join Date
    Mar 2004
    Posts
    660
    Thanks, i got it, it is just syntax. Thanks all.

  7. #7
    Join Date
    Mar 2004
    Posts
    660
    I did set the default value 0 on the check box fileld, but when i check the data in the back end, it still has null value, why? Also in the front end, i set the default value to 0, it still didn't work, always give you null value if you didn't check it. But if i check it and then uncheck it. It will give you 0 value. How can i do so the if you didn't touch the check box, it will give you 0 value automatically? Thanks.

  8. #8
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    If it was NULL BEFORE you set the default it will reamin NULL

    You need to do an update statement.

    Stop using EM

    If you have Enterprise Manager, the you most likely have Books Online as well...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •