SQL Queries - Assignment-8
ASSIGNMENT 08
----------------------------
Interview Questions Based On IDENTITY in SQL Server
- What is the purpose of the IDENTITY property in SQL Server?
- How do you define an IDENTITY column in SQL Server?
- Can you insert values manually into an IDENTITY column? If yes, how?
- How would you reset the identity seed of a table after deleting all rows from it?
- What is the difference between an IDENTITY column and a SEQUENCE in SQL Server?
- What is SCOPE_IDENTITY() and how does it differ from @@IDENTITY and IDENT_CURRENT()?
- How can you retrieve the last identity value generated in the current session or scope?
- Explain how DBCC CHECKIDENT works.
- Can an IDENTITY column have a negative seed or increment?
- What happens if you try to insert a record after the identity value reaches its maximum limit?
- How would you handle gaps in an IDENTITY column caused by transaction rollbacks or deletions?
- If you delete a row from a table with an IDENTITY column, will SQL Server reuse that identity value for a new row? Why or why not?
- What happens when a transaction that inserts a row into a table with an IDENTITY column is rolled back? Does the identity value also roll back?
- Describe a scenario where an IDENTITY column could cause issues with replication or data synchronization.
- How would you troubleshoot or resolve an issue where SCOPE_IDENTITY() returns NULL after an insert operation?
Hands on Practicals :
- Write a SQL query that inserts a row into a table with an IDENTITY column, and then retrieves the identity value of the inserted row using SCOPE_IDENTITY()
- Demonstrate how to reset the identity value of a table to start from 1, even if there are existing rows in the table.
- Create a table with an IDENTITY column that increments by -1 starting from -100, and insert three rows into it. What identity values will be generated?
- Suppose you have a table where the identity column has reached its maximum limit for INT. How would you modify the table to handle more rows without losing existing data?
Comments
Post a Comment