Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjlampstack
23,932 PointsCan you delete a row with a Primary Key?
Lets say you have a table with 20 rows and the Primary keys are auto-incremented from 1 thru 20.
You then decide you no-longer need row number 5 which has a Primary Key of the integer 5.
First, can the row be deleted?
IF deleted, can we assign 5 as the primary key of the next row added? Or must the primary key of the new row be 21?
1 Answer
Steven Parker
231,248 Points- You can always delete a row or rows, and every row will have a primary key in the same column.
- You can re-assign deleted keys if you include them explicitly instead of allowing the auto-increment mechanism to assign them for you. But you might not want to because it could make it difficult to track down information about the change history of the table later.