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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:54:42+00:00 2026-05-11T08:54:42+00:00

How can I join these 2 queries to get all table info in one

  • 0

How can I join these 2 queries to get all table info in one result?

A – Get all columns and their datatype belonging to table Customers

select COLUMN_NAME, DATA_TYPE from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'Customers' 

B – Get all constraints on the table Customers

SELECT        KCU1.CONSTRAINT_NAME AS 'ConstraintName', KCU1.COLUMN_NAME AS 'ColumnName', KCU2.TABLE_NAME AS 'ForeignTableName',                               KCU2.COLUMN_NAME AS 'ForeignColumnName'     FROM            INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC INNER JOIN                              INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU1 ON KCU1.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG AND                               KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME INNER JOIN                              INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU2 ON KCU2.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG AND                               KCU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA AND KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME AND                               KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION AND KCU1.TABLE_NAME = 'Customers' 

The result I want is a list of all columns and those that have a foreign key connection to another table should be denoted as such. (Sorry for my poor terminology)

  • 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. 2026-05-11T08:54:43+00:00Added an answer on May 11, 2026 at 8:54 am

    Ah! Got it ! Here it is:

    SELECT        CL.COLUMN_NAME AS 'ColumnName', CL.DATA_TYPE AS 'DataType', CL.CHARACTER_MAXIMUM_LENGTH AS 'MaxLength',                           KCU1.CONSTRAINT_NAME AS 'ConstraintName', KCU2.TABLE_NAME AS 'ForeignTableName', KCU2.COLUMN_NAME AS 'ForeignColumnName' FROM            INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC INNER JOIN                          INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU1 ON KCU1.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG AND                           KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME INNER JOIN                          INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU2 ON KCU2.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG AND                           KCU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA AND KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME AND                           KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION AND KCU1.TABLE_NAME = 'Customers' RIGHT OUTER JOIN                          INFORMATION_SCHEMA.COLUMNS AS CL ON KCU1.TABLE_NAME = CL.TABLE_NAME AND KCU1.COLUMN_NAME = CL.COLUMN_NAME WHERE        (CL.TABLE_NAME = N'Customers') ORDER BY CL.ORDINAL_POSITION 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know you can combine multiple table-selects using a Join statement but is there
How can you join between a table with a sparse number of dates and
I have 12 columns separated by a tab. How can I join them side-by-side?
Do any queries exist that require RIGHT JOIN, or can they always be re-written
I'm trying to build a HQL that can left join values from a collection,
Along the lines of my previous question , how can i join a list
Can/Should I use a LIKE criteria as part of an INNER JOIN when building
How can I create a query for a full outer join across a M2M
In Python, I can do: list = ['a', 'b', 'c'] ', '.join(list) # 'a,
I have a table, Foo. I run a query on Foo to get the

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.