Pages

16 February 2014

SQL Questions PART-3


Q How many columns can a view support ?
       A view can support maximum of 1024 columns.

Q What is the difference between Primary Key and Unique Key ?
    There can be only one one Primary Key per table but there can be more than one unique key per table. Primary Key does not allow NULL  but Unique Key can allow one NULL . Primary Key creates Clustered Index on the column by default where as Unique Key creates non clustered index on the column by default.

Q How to count number of columns in a table in SQL Server ?
      Following query will return number of columns in a table.
SELECT COUNT(*) AS ColumnCount
FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='TableName'

Q Up to what level, subqueries can be nested in SQL Server?
     Subqueries can be nested up to 32 level in SQL Server.