need NULL defined when adding to the table

  • I need your help. I have instruction to update a table. The instruction is simple "IsValidSap (should have null defined when adding to the table)". I am unclear about what is needed. I know you can set defaults on tables if no value is sent into the insert statement. But this wordking is confusing for me and unsure that is what is being asked. For those out there with much more SQL experience then me I ask for your interpretation of what you think is being asked?

    Table definition:

    USE [ReceiptRepository]

    GO

    /****** Object: Table [Lkup].[ReceiptReasonCodes] Script Date: 10/15/2013 13:21:35 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [Lkup].[ReceiptReasonCodes](

    [ReceiptReasonCodeId] [int] IDENTITY(-2147483648,1) NOT NULL,

    [ReceiptReasonCode] [varchar](4) NOT NULL,

    [ReceiptReasonCodeMultiplier] [decimal](4, 2) NOT NULL,

    [LongDescription] [varchar](255) NOT NULL,

    [BillingEntityTypeId] [int] NULL,

    [IsMergeAllowedFlag] [bit] NOT NULL,

    [ActiveFlag] [char](1) NOT NULL,

    [InsertedBy] [varchar](128) NOT NULL,

    [InsertTs] [datetime] NOT NULL,

    [UpdatedBy] [varchar](128) NOT NULL,

    [UpdateTs] [datetime] NOT NULL,

    [PaymentClassificationId] [int] NULL,

    [IsValidSap] [bit] NULL,

    CONSTRAINT [PK_ReceiptReasonCodes_ReceiptReasonCodeId] PRIMARY KEY CLUSTERED

    (

    [ReceiptReasonCodeId] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] WITH CHECK ADD CONSTRAINT [FK_ReceiptReasonCodes_BillingEntityTypes_BillingEntityTypeId] FOREIGN KEY([BillingEntityTypeId])

    REFERENCES [Lkup].[BillingEntityTypes] ([BillingEntityTypeId])

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] CHECK CONSTRAINT [FK_ReceiptReasonCodes_BillingEntityTypes_BillingEntityTypeId]

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] WITH CHECK ADD CONSTRAINT [FK_ReceiptReasonCodes_PaymentClassifications_PaymentClassificationId] FOREIGN KEY([PaymentClassificationId])

    REFERENCES [Lkup].[PaymentClassifications] ([PaymentClassificationId])

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] CHECK CONSTRAINT [FK_ReceiptReasonCodes_PaymentClassifications_PaymentClassificationId]

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] ADD CONSTRAINT [DC_ReceiptReasonCodes_IsMergeAllowedFlag] DEFAULT ((0)) FOR [IsMergeAllowedFlag]

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] ADD CONSTRAINT [DC__ReceiptReasonCodes__ActiveFlag] DEFAULT ('Y') FOR [ActiveFlag]

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] ADD CONSTRAINT [DC__ReceiptReasonCodes__InsertedBy] DEFAULT (suser_sname()) FOR [InsertedBy]

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] ADD CONSTRAINT [DC__ReceiptReasonCodes__InsertTs] DEFAULT (getdate()) FOR [InsertTs]

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] ADD CONSTRAINT [DC__ReceiptReasonCodes__UpdatedBy] DEFAULT (suser_sname()) FOR [UpdatedBy]

    GO

    ALTER TABLE [Lkup].[ReceiptReasonCodes] ADD CONSTRAINT [DC__ReceiptReasonCodes__UpdatedTs] DEFAULT (getdate()) FOR [UpdateTs]

    GO

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • Maybe ask whoever gave you that requirement for clarification? We can guess what that person meant, but we'll probably be wrong.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • The person is inexcessable for the next two weeks and this needs to be completed before that time. You have as much information as I do about it, so from what you said it sounds like this verbiage is ambigious and vague as I suspected. The person is a senior programmer and because I am not I wanted to check with the forum in case it means something clear to people more experienced than me?

    Thanks for your reply

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • I think the code below is a reasonable interpretation, but whether it's correct or not is far from certain:

    ALTER TABLE [Lkup].[ReceiptReasonCodes]

    ADD [IsValidSap] [bit] NULL

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • ScottPletcher (10/15/2013)


    I think the code below is a reasonable interpretation, but whether it's correct or not is far from certain:

    If the table definition posted is correct, the column already exists (as a nullable column) in the table.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • That column is already in the table definition i provided. That table/column already allows NULLs. My guess is that the persom wants a default value set to the column rather then NULLs being there. The potentially problem with making that change is that any number of other sprocs/functions/scripts could be hitting this table and column and a change like that could impact any number of unknown processes. I think the chick just wants to screw me because i am new and they are senior and politically connected

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • If you need to update the table, then the question is: what rules do apply?

    The table is already defined as requested ("IsValidSap (should have null defined when adding to the table)") so there's nothing to do with this part.

    Therefore, there's no need to update (= alter) the table (definition).

    It might be to fill the new column with values based on certain (unknown) requirements.

    If the application still runs without any error, I would leave it as it is. In case it fails, it might be due to a bad coding habit of not referencing all column names in an insert statement. In such a case address it to the App Dev team.

    Whoever request you to finish this task should describe what's expected. If this can't be done, the implementation of the "requirement" should be postponed until clarification is available.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Thank you. That is solid good advice. Your right best not to mess with it until clarification can be achieved.

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply