how to find number of columns in a table in sql server 2000
and 2005 also
Answer Posted / anuruddha
SELECT
K_Table = FK.TABLE_NAME,
FK_Column = CU.COLUMN_NAME,
PK_Table = PK.TABLE_NAME,
PK_Column = PT.COLUMN_NAME,
Constraint_Name = C.CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON
C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON
C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON
C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
INNER JOIN (
SELECT i1.TABLE_NAME, i2.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 ON
i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY'
) PT ON PT.TABLE_NAME = PK.TABLE_NAME
Is This Answer Correct ? | 3 Yes | 3 No |
Post New Answer View All Answers
what number files will a information contain in SQL Server? How many forms of information files exist in SQL Server? How many of those files can exist for a single database?
Define outer join?
What happens if null values are involved in boolean operations?
How to replace null values in expressions using isnull()?
Explain the phases a transaction has to undergo?
List the advantages of using stored procedures?
What are the disadvantages of indexes?
What do you understand by triggers?
What are constraints in microsoft sql server?
What is trigger in salesforce?
What is the difference between coalesce() & isnull()?
How to backup encryption key ?
What is the default schema of your login session in ms sql server?
What does man by sql wildcard characters in sql server?
How to change the data type of an existing column with "alter table" statements in ms sql server?