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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 problems with default value

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2008-04-15 : 08:36:53
Hi,

I have an int column (not null) that i try to set a default value to. I write (0) but after saving the table and returning to that column i see that the default value is ((0)).
Further, I have a sp that inserts values into that column and if the value sent to the sp for that column is empty or null then it should enter the default value ie 0 but instead it enters Null into the column.
What could be causing this problem?
Thanks

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-15 : 08:44:24
How can NULL be inserted if the column has "NOT NULL" onto it?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2008-04-15 : 08:52:49
oops my mistake. the column is null

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-15 : 09:47:31
Can you post the code you used?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2008-04-15 : 10:09:11
hi,

The code for the insert is:
--======= Insert email notification settings ======
declare @articleWarning as int
declare @articleNotification as int
select @articleWarning = ekb_enabled from tb_knbEmailKB where ekb_kbid = @kbID and ekb_etid = 3
select @articleNotification = ekb_enabled from tb_knbEmailKB where ekb_kbid = @kbID and ekb_etid = 4
insert into tb_knbArticleNotification (ano_articleID, ano_expWarning, ano_expNotification) values (@articleID, @articleWarning, @articleNotification)
select @articleID as articleID



Here is the table:
USE [ecrmKB]
GO
/****** Object: Table [dbo].[tb_knbArticleNotification] Script Date: 04/15/2008 17:08:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tb_knbArticleNotification](
[ANo_id] [int] IDENTITY(1,1) NOT NULL,
[ANo_articleID] [int] NULL,
[ANo_expWarning] [int] NULL CONSTRAINT [DF_tb_knbArticleNotification_ANo_expWarning] DEFAULT ((0)),
[ANo_expWarningInterval] [int] NULL CONSTRAINT [DF_tb_knbArticleNotification_ANo_expWarningInterval] DEFAULT ((7)),
[ANo_expNotification] [int] NULL CONSTRAINT [DF_tb_knbArticleNotification_ANo_expNotification] DEFAULT ((0)),
[ANo_reminder] [int] NULL CONSTRAINT [DF_tb_knbArticleNotification_ANo_reminder] DEFAULT ((0)),
[ANo_reminderDate] [datetime] NULL,
[ANo_reminderEmail] [nvarchar](255) COLLATE Hebrew_CI_AS NULL,
[ANo_reminderText] [ntext] COLLATE Hebrew_CI_AS NULL,
CONSTRAINT [PK_tb_knbArticleNotification] PRIMARY KEY NONCLUSTERED
(
[ANo_id] ASC
)WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
ALTER TABLE [dbo].[tb_knbArticleNotification] WITH CHECK ADD CONSTRAINT [FK_tb_knbArticleNotification_tb_knbArticle] FOREIGN KEY([ANo_articleID])
REFERENCES [dbo].[tb_knbArticle] ([Art_id])
GO
ALTER TABLE [dbo].[tb_knbArticleNotification] CHECK CONSTRAINT [FK_tb_knbArticleNotification_tb_knbArticle]


Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-15 : 11:37:11
It seems like you are getting NULL values into the variable through assigning SELECT statement and in the following insert you are assigning the value of variable to you table field which causes NULL values to be inserted to it.
Go to Top of Page

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2008-04-16 : 02:59:12
Hi,

Probably but if i have a default value set to that column shouldn't the default value be inserted instead of Null?

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
Go to Top of Page
   

- Advertisement -