Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Default value doesn't work anymore

Author  Topic 

Bennov
Starting Member

5 Posts

Posted - 2008-10-06 : 14:36:12
I have a very strange problem. Suddenly the 'default value' option in SQL server doesn't work properly anymore.
I have two the same databases, one on a SQL 2005 server and one on a SQL 2000 server. In a table I have some fields with default value (0). As far as I know this always worked fine. Now, when I add a record all these fields get TRUE as default value. I added a new field with exactly the same properties in the middle. This one also doesn't work properly. When I move the field to the last position it seems to work fine. But when I add a record through a standard form it goes wrong again.

After trying a lot of thinks I just created a new table with only 2 fields ('Number' (primary key) and 'Ready' (bit, with standard value = (0).
I now add the first record: this works fine, the default value of the field 'Ready' changed automatically to FALSE. I now add the second record: here it goes wrong again! The default value for the field 'Ready' for this record changed to TRUE!!

I use this kind of values for years now and it always worked fine. The strange thing is that it happens to two different SQL servers of two different companies in two different cities.

Can anyone help?

Thanks in advance!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-06 : 14:40:49
Post the CREATE TABLE statement including the default constraint plus the INSERT INTO statement you are trying. Make sure to point out which column is having the isuse for us.

You can grab the CREATE/ALTER commands in Management Studio by right clicking on them.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Bennov
Starting Member

5 Posts

Posted - 2008-10-06 : 14:46:43
Here is the create table:

USE [VerhregBV]
GO
/****** Object: Table [dbo].[Testtable] Script Date: 10/06/2008 20:43:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Testtable](
[Number] [nvarchar](50) NOT NULL,
[Ready] [bit] NOT NULL CONSTRAINT [DF_Testtable_Ready] DEFAULT ((0)),
CONSTRAINT [PK_Testtable] PRIMARY KEY CLUSTERED
(
[Number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

And here the results of the first 4 records I just typed in through the Access ADP file without entering the 'ready' column:
(Waar=True, Onwaar=False)

Number Ready
34 Waar
333 Onwaar
444 Waar
666 Waar
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-06 : 14:47:58
I haven't a clue about Access ADP, but let's try it through a direct INSERT statement in Management Studio:

INSERT INTO Testtable (Number) VALUES ('555')

SELECT * FROM Testtable WHERE Number = '555'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Bennov
Starting Member

5 Posts

Posted - 2008-10-06 : 14:57:52
Wow! Strange, but that works OK. I added a couple of new records now and it goes great. Seems like an Access problem probably..?

In Access I open the table on the same way as in SQL Server (right click -> open table). I just navigate to the last record and keep on adding data. In SQL server this also works great!

Pffff, I will keep on searching in Access. Thanks for your help so far!!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-06 : 15:50:11
Yes it's an issue in Access. It's always best to troubleshoot these types of issues inside SQL Server so that you know if it's in your code (or tool) or something in SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Bennov
Starting Member

5 Posts

Posted - 2008-10-06 : 15:57:14
Thanks for the tip. I posted this in a Access forum also now. Because it goes wrong without use of any code they point to sql server. Because opening the table and entering data in the table goes 'hard' into the database, they say....

I think I stop using default values and fill them by code.
Go to Top of Page

Bennov
Starting Member

5 Posts

Posted - 2008-10-08 : 02:12:34
Problem happens after install of SP3 for Office 2003. Microsoft already released a hotfix!
Go to Top of Page
   

- Advertisement -