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 302563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:06:32+00:00 2026-05-12T07:06:32+00:00

I would like to know how you can prevent to use of two same

  • 0

I would like to know how you can prevent to use of two same tags in a database table.
One said me that use two private keys in a table. However, W3Schools -website says that it is impossible.

My relational table

alt text http://files.getdropbox.com/u/175564/db/db7.png

My logical table

alt text http://files.getdropbox.com/u/175564/db/db77.png

The context of tables

alt text http://files.getdropbox.com/u/175564/db/db777.png

How can you prevent the use of duplicate tags in a question?

  • 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-12T07:06:32+00:00Added an answer on May 12, 2026 at 7:06 am

    I have updated my NORMA model to more closely match your diagram. I can see where you’ve made a few mistakes, but some of them may have been due to my earlier model.

    I have updated this model to prevent duplicate tags. It didn’t really matter before. But since you want it, here it is (for Postgres):

    START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE;
    
    CREATE SCHEMA so;
    
    SET search_path TO SO,"$user",public;
    
    CREATE DOMAIN so.HashedPassword AS 
        BIGINT CONSTRAINT HashedPassword_Unsigned_Chk CHECK (VALUE >= 0);
    
    CREATE TABLE so."User"
    (
        USER_ID SERIAL NOT NULL,
        USER_NAME CHARACTER VARYING(50) NOT NULL,
        EMAIL_ADDRESS CHARACTER VARYING(256) NOT NULL,
        HASHED_PASSWORD so.HashedPassword NOT NULL,
        OPEN_ID CHARACTER VARYING(512),
        A_MODERATOR BOOLEAN,
        LOGGED_IN BOOLEAN,
        HAS_BEEN_SENT_A_MODERATOR_MESSAGE BOOLEAN,
        CONSTRAINT User_PK PRIMARY KEY(USER_ID)
    );
    
    CREATE TABLE so.Question
    (
        QUESTION_ID SERIAL NOT NULL,
        TITLE CHARACTER VARYING(256) NOT NULL,
        WAS_SENT_AT_TIME TIMESTAMP NOT NULL,
        BODY CHARACTER VARYING NOT NULL,
        USER_ID INTEGER NOT NULL,
        FLAGGED_FOR_MODERATOR_REMOVAL BOOLEAN,
        WAS_LAST_CHECKED_BY_MODERATOR_AT_TIME TIMESTAMP,
        CONSTRAINT Question_PK PRIMARY KEY(QUESTION_ID)
    );
    
    CREATE TABLE so.Tag
    (
        TAG_ID SERIAL NOT NULL,
        TAG_NAME CHARACTER VARYING(20) NOT NULL,
        CONSTRAINT Tag_PK PRIMARY KEY(TAG_ID),
        CONSTRAINT Tag_UC UNIQUE(TAG_NAME)
    );
    
    CREATE TABLE so.QuestionTaggedTag
    (
        QUESTION_ID INTEGER NOT NULL,
        TAG_ID INTEGER NOT NULL,
        CONSTRAINT QuestionTaggedTag_PK PRIMARY KEY(QUESTION_ID, TAG_ID)
    );
    
    CREATE TABLE so.Answer
    (
        ANSWER_ID SERIAL NOT NULL,
        BODY CHARACTER VARYING NOT NULL,
        USER_ID INTEGER NOT NULL,
        QUESTION_ID INTEGER NOT NULL,
        CONSTRAINT Answer_PK PRIMARY KEY(ANSWER_ID)
    );
    
    ALTER TABLE so.Question 
        ADD CONSTRAINT Question_FK FOREIGN KEY (USER_ID) 
        REFERENCES so."User" (USER_ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
    
    ALTER TABLE so.QuestionTaggedTag 
        ADD CONSTRAINT QuestionTaggedTag_FK1 FOREIGN KEY (QUESTION_ID) 
        REFERENCES so.Question (QUESTION_ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
    
    ALTER TABLE so.QuestionTaggedTag 
        ADD CONSTRAINT QuestionTaggedTag_FK2 FOREIGN KEY (TAG_ID) 
        REFERENCES so.Tag (TAG_ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
    
    ALTER TABLE so.Answer 
        ADD CONSTRAINT Answer_FK1 FOREIGN KEY (USER_ID) 
        REFERENCES so."User" (USER_ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
    
    ALTER TABLE so.Answer 
        ADD CONSTRAINT Answer_FK2 FOREIGN KEY (QUESTION_ID) 
        REFERENCES so.Question (QUESTION_ID) ON DELETE RESTRICT ON UPDATE RESTRICT;
    
    COMMIT WORK;
    

    Note that there is now a separate Tag table with TAG_ID as the primary key. TAG_NAME is a separate column with a uniqueness constraint over it, preventing duplicate tags. The QuestionTaggedTag table now has (QUESTION_ID, TAG_ID), which is also its primary key.

    I hope I didn’t go too far in answering this, but when I tried to write smaller answers, I kept having to untangle my earlier answers, and it seemed simpler just to post this.

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

Sidebar

Related Questions

I would like to know how can I use tinyint in SQL Server 2005
I would like to know how can I use jQuery to select multiple items
I would like to implement a custom database initialization strategy so that I can
i would like to know how to use a DocumentListener/DocumentEvent in java to prevent
i would like know some reference. I know i can googling it. but prefer
I would like to know how can I create a regexp to match the
I would like to know how can I write a pointer array: short* myArray
I would like to know how can I output a number with 2 decimal
I would like to know how can i read a value of input text
I would like to know how can we validate the Credit Card. We have

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.