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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:33:00+00:00 2026-06-10T16:33:00+00:00

I have two tables which both have a ‘Name’ column. The tables are not

  • 0

I have two tables which both have a ‘Name’ column. The tables are not related to each other. I’d like to enforce uniqueness across these two columns.

I’ve been trying to create an indexed view out of the two columns but have found out that I cannot use a union all nor a full join to get the full list of names. I feel like I’m missing an obvious alternative which would allow me to add the unique index.

  • 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-06-10T16:33:01+00:00Added an answer on June 10, 2026 at 4:33 pm

    Assuming both of your base tables have a unique constraint on ‘Name’ then the only way uniqueness can be violated is if the same name is in both tables.

    i.e. you expect a join against them to return zero rows. So you can cross join the result of that join against a table with 2 rows and create a unique index against that.

    CREATE TABLE dbo.Two
      (
         N INT PRIMARY KEY
      )
    
    INSERT INTO dbo.Two
    VALUES      (1),
                (2)
    
    GO
    
    CREATE VIEW dbo.UniqueNames
    WITH SCHEMABINDING
    AS
      SELECT T1.Name
      FROM   dbo.T1
             INNER JOIN dbo.T2
               ON T1.Name = T2.Name
             CROSS JOIN dbo.Two
    
    GO
    
    CREATE UNIQUE CLUSTERED INDEX IX
      ON dbo.UniqueNames(Name) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two or more tables which hold values under the same column name.
I have two tables which both have the column DateTime. How can I get
Hi I want to have two tables each have an INT id column which
I have two tables for properties and images Which have the same column name
I have two tables invoices and pending_payments both of which have the following rows
I have two tables, Users and People, both of which share a common attribute,
I have two tables which looks something like this Table Queue int ID; string
I have two tables which both contain 'pipe separated values' e.g: Table 1: DataField_A
I have two tables in my database: test1 which looks like: ID pubmed_ID -------------------
I have two tables. CustomersTable and BusinessDirectory Both tables have a column called businessName.

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.