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

  • Home
  • SEARCH
  • 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 648247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:48:40+00:00 2026-05-13T21:48:40+00:00

I have table that I insert data with following query (from c# code): INSERT

  • 0

I have table that I insert data with following query (from c# code):

INSERT INTO [BazaZarzadzanie].[dbo].[Wycena]
   ([KlienciPortfeleKontaID]
   ,[WycenaData]
   ,[WycenaTyp]
   ,[WycenaWartosc]
   ,[WycenaWaluta]
   ,[WycenaUzytkownik]
   ,[WycenaUzytkownikData])
VALUES
   (@varKlienciPortfeleKontaID
   ,@varWycenaData
   ,@varWycenaTyp
   ,@varWycenaWartosc
   ,@varWycenaWaluta
   ,@varWycenaUzytkownik
   ,@varWycenaUzytkownikData)

Table creation script looks like this:

CREATE TABLE [dbo].[Wycena](
[KlienciPortfeleKontaID] [int] NULL,
[WycenaData] [datetime] NULL,
[WycenaTyp] [int] NULL,
[InID] [int] NULL,
[WycenaIlosc] [decimal](18, 2) NULL,
[WycenaCena] [decimal](18, 2) NULL,
[WycenaWartosc] [decimal](18, 2) NULL,
[WycenaWaluta] [nvarchar](3) NULL,
[WycenaUzytkownik] [nvarchar](50) NULL,
[WycenaUzytkownikData] [datetime] NULL
) ON [PRIMARY]

It also has couple of foreign keys but nothing that i could make primary/unique key. So i thought to prevent duplicates i would go for a trigger since to know one row is duplicate i actually have to test every single value of that row (well maybe not 2 last columns) ? This table has around 2mln rows.

Is this good idea? Or is there a better way?

Below is trigger I’ve created (not tested if it works):

CREATE TRIGGER [dbo].[trg_WycenaDuplicateCheck]
   ON [dbo].[Wycena] FOR INSERT
AS

IF EXISTS(SELECT INSERTED.[KlienciPortfeleKontaID]
  ,INSERTED.[WycenaData]
  ,INSERTED.[WycenaTyp]
  ,INSERTED.[InID]
  ,INSERTED.[WycenaIlosc]
  ,INSERTED.[WycenaCena]
  ,INSERTED.[WycenaWartosc]
  ,INSERTED.[WycenaWaluta]
  FROM INSERTED, Wycena
  WHERE INSERTED.[KlienciPortfeleKontaID] = Wycena.[KlienciPortfeleKontaID]
  AND INSERTED.[WycenaData] = Wycena.[WycenaData]
  AND INSERTED.[WycenaTyp] = Wycena.[WycenaTyp]
AND INSERTED.[InID] = Wycena.[InID]
  AND INSERTED.[WycenaIlosc] = Wycena.[WycenaIlosc]
    AND INSERTED.[WycenaCena] = Wycena.[WycenaCena]
      AND INSERTED.[WycenaWartosc] = Wycena.[WycenaWartosc]
  AND INSERTED.[WycenaWaluta] = Wycena.[WycenaWaluta]
  Group By INSERTED.[KlienciPortfeleKontaID]
  ,INSERTED.[WycenaData]
  ,INSERTED.[WycenaTyp]
  ,INSERTED.[InID]
  ,INSERTED.[WycenaIlosc]
  ,INSERTED.[WycenaCena]
  ,INSERTED.[WycenaWartosc]
  ,INSERTED.[WycenaWaluta]
  HAVING COUNT (*) > 1)

BEGIN
RAISERROR('>>>DUPLICATES PREVENTED<<< ',10,1)
ROLLBACK TRAN
END
  • 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-13T21:48:40+00:00Added an answer on May 13, 2026 at 9:48 pm

    Create a “unique” index on the fields you care about.

    CREATE UNIQUE INDEX IX_YOUR_FAVORITE_NAME
      ON [dbo].[Wycena](... list of columns goes here ...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer shortcut Properties -> Compatibility tab -> set Run this program… May 14, 2026 at 6:10 pm
  • Editorial Team
    Editorial Team added an answer If you retrieve each page without running the embedded script,… May 14, 2026 at 6:10 pm
  • Editorial Team
    Editorial Team added an answer This is a known issue for IE. KB article with… May 14, 2026 at 6:10 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.