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

In Vim, one can join two lines by typing capital J. However, these are
How I can join this queries to single select (without temp table)? SELECT t2.value,
I have 3 table: [Order, Order_to_goods, Goods] I want to get of all participants
I want to know if these two queries can be merged, I will explain
So, how can I drop all indexes in a SQL database with one command?
Say I have a sequence of queries that progressively get more expensive. I can
in F#, array.append can join two arrays; is there a way to append 2
Ok so I know we can join tables 'across' in MySQL to tables using
Can I join SELECT and UPDATE statement? If yes, how can I do that?
Can i join two tables using LINQ for NHibernate like I can do in

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.