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 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

Related Questions

I have the following code that creates my table. I insert data into it
I have a table Survey_Data_Response that is populated with an 'insert into' statement from
I have an INSERT query that is pulling data from two tables and inserting
i have the following code: <!--ajouter une carte --> <?php if($_POST[submit_dd]){ mysql_query(INSERT INTO data
I have a trigger that check data before insert to another table IF NOT
I have a multi-row insert that looks something like: insert into table VALUES (1,
When trying to INSERT data into a database table, I've been getting the following
I have a table that has duplicate email address, I need to insert just
I have 2 insert triggers, that fire on same table, they both try to
I have code similar to the following: $sql2 = ALTER TABLE table ADD UNIQUE(field2,

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.