Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6917459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:43:59+00:00 2026-05-27T09:43:59+00:00

I have a table with a nullable FK field. I made it nullablle to

  • 0

I have a table with a nullable FK field. I made it nullablle to avoid changing the loader.

In order to achieve (Advertisers)* 1(Currencies), I wrote a simple trigger:

ALTER TRIGGER InsertedAdvertisersDefaultCurrency
ON dbo.Advertisers
FOR INSERT
AS
    UPDATE Advertisers
    SET Currency_Id=(SELECT TOP 1 Id FROM Currencies WHERE Name='USD')
    WHERE Currency_Id=NULL

My question is basically about how I am checking the whole table for null rows on every insert.

I feel like I should be using the inserted table (?)

Here’s the table:

CREATE TABLE [dbo].[Advertisers](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](max) NOT NULL,
    [Currency_Id] [int] NULL,
 CONSTRAINT [PK_Advertisers] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Advertisers]  WITH CHECK ADD  CONSTRAINT [FK_CurrencyAdvertiser1] FOREIGN KEY([Currency_Id])
REFERENCES [dbo].[Currencies] ([Id])
GO
ALTER TABLE [dbo].[Advertisers] CHECK CONSTRAINT [FK_CurrencyAdvertiser1]
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:44:00+00:00Added an answer on May 27, 2026 at 9:44 am

    Yes, you should just update the insertd records:

    UPDATE Advertisers
    SET Currency_Id=(SELECT TOP 1 Id FROM Currencies WHERE Name='USD')
    WHERE Id in (select Id from inserted)
    

    Or you may use a default value in that field

    ALTER TABLE [dbo].[Advertisers] ADD  CONSTRAINT [DF_Advertisers_Currency_Id]  DEFAULT ((101)) FOR [Currency_Id]
    GO
    

    Where 101 is the USD id

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a nullable datetime field. I'll execute queries like this:
I have a table with a nullable field of type text. When I run
I have a table with a nullable integer field that is a foreign key.
I'm working with .NET strongly-typed datasets and have a table with a nullable int
I have a nullable DateTime column in my SQL Server 2005 table called DateTimeDeleted.
I have a table which has some nullable fields and when the user enters
I have such mapping for ProductVariant table: Id(x => x.Id).Nullable(); Map(x => x.IsEnabled); Map(x
I have the following SQL table: ObjectTable -------------------------------------------------- | ID | Name | Order
I have a field (say, foo) in a table in a SQL Server database
I have a table in Sql Server that contain an int field price that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.