Tech Point Fundamentals

Tuesday, August 24, 2021

SQL Primary Key Constraint Interview Questions

SQL Primary Key Constraint Interview Questions

SQL-Primary-Key-Interview-Questions

In SQL Primary Key is a value that is unique for every record in the table.  A Primary Key is used to uniquely identify the row of the table. The Primary Keys are stored within the index. Normally the Primary Key creates the Clustered Index by default. A table can have only one Primary Key.


The primary key is the most frequent topic for the interview today. For experienced developers, there can be a lot of questions based on this topic. In this article, we will see some common interview questions based on Primary Key Constraints.  Please visit our Youtube Channel for more SQL Interview Questions and Answers videos by the below link:







Below are some common interview questions based on the SQL Primary Key Constraint:


QA. What is the difference between PRIMARY KEY and UNIQUE KEY?


Please watch the Unique Key video here.


QB. What is the difference between PRIMARY KEY and FOREIGN KEY?


Please watch the Foreign Key video here.


QC. What is the difference between INDEX and KEY?




Q01. What is the difference between PRIMARY KEY and Non-Nullable UNIQUE KEY?


Q02. What is the difference between the PRIMARY KEY and Unique Clustered Index?


Q03. How many NULL values are allowed in a PRIMARY KEY column?


Q04. Can a PRIMARY KEY Column contain any empty(blank) value or whitespace?


Q05. Can a PRIMARY KEY Columns contain duplicate values?


Q06. Can you add a Clustered Index on any column explicitly in SQL?


Q07. Is it mandatory for a PRIMARY KEY to be Clustered Index? or Can a PRIMARY KEY have a Non-Clustered Index?


Q08. Can you create a PRIMARY KEY on a table that has already a Clustered Index or vice-versa?


Q09. Can you add both Clustered and Non-Clustered Indexes on a column?


Q10. If a column contains a Clustered Index, is it mandatory that the column must be PRIMARY KEY also?



Q11. Can you add both Clustered and Non-Clustered Indexes on the same column of the database?


Q12. Can you add multiple PRIMARY KEY on any table? or Can you add multiple Clustered Indexes on any table in SQL?


Q13. Can you create a PRIMARY KEY on the Temp Table?


Please watch the Temp Table video here.


Q14. Can you add a PRIMARY KEY on a view?


Q15. What is the difference between table level and column level PRIMARY KEY?


Q16. When the database is in first normal form (1NF)?


Q17. Can you update or delete the PRIMARY KEY value of a table?


Q18. Can you add the PRIMARY KEY constraint on a column that contains data?


Q19. What is IAM (Index Allocation Map) Page in SQL?


Q20. What is a Composite Key?



Q21. What is a Candidate Key?


Q22. What is an Alternate Key?


Q23. Can you add a PRIMARY KEY Constraint on a nullable column?


Q24. How many PRIMARY KEYs are allowed in a table?


Q25. How many Clustered Indexes are allowed in any table?


Q26. Can you DROP the index created by the Primary Key?


Q27. How can you DROP the Primary Key Constraint?


Q28. Can you make a varchar(max) column as PRIMARY KEY in SQL?


Q29. Is it mandatory to make the PRIMARY KEY column an identity column? What will happen if two users will try to add the same value in PRIMARY KEY at the same time?


Q30. If you have Clustered Index already on a column i.e. UserName in a table, Now you have to create a PRIMARY KEY on the UserId column. How will you do that?



Q31. In which order the data will be displayed by default if execute the select command on the table without any order by clause?


Q32. Why PRIMARY KEY enforces it to be non-nullable and UNIQUE KEY as Nullable?


Q33. What is a HEAP in SQL?


Q34. Can you create Primary Key in the Table Variable?


Please watch the Table Variable video here.


Q35. Can you create Primary Key in the Table-Valued Type?


Please watch the Table-Valued Types video here.



Live Demo





Watch our related videos here




Recommended Articles


Most Frequently Asked SQL Interview Questions
Most Frequently Asked C# Interview Questions
Derived Table (DT) Interview Questions
Unicode vs Non-Unicode Data Types Interview Questions
Table Variable (TV) Interview Questions
Table-Valued Type (TVT) Interview Questions
Common Table Expression(CTE) Interview Questions
Temp Table Interview Questions
Static Class Interview Questions and Answers
Sealed Class Interview Questions and Answers
Sealed Method Interview Questions and Answers
Abstract Class vs Interface
Interface Interview Questions and Answers





Thanks for visiting this page. Please follow us on Twitter, Facebook, LinkedIn, Telegram, WhatsApp, Youtube, and Quora for regular updates.

2 comments:

  1. This is certainly a awesome article. Thanks a ton for bothering to summarize all this out for folks. It really is a great help! best iPhone cases

    ReplyDelete

Please do not enter any HTML. JavaScript or spam link in the comment box.