New answers tagged primary-key
I would suggest NOT to use Designer in creating key constraints or doing any DDL / DML operations. Best is to use T-SQL - much flexible, more options, more powerful and you can automate many things with it. There is a learning curve, but its worth learning TSQL rather than keep using GUI. Also, make sure you are using the latest version of SSMS - sql ...
First I'm assuming that both ID and Type are INT columns. Second that this is going to be a somewhat active table with a fair number of inserts (and possibly deletes). And last but not least that you aren't going to be pulling a "range" of IDs. For example you don't need to look at ID 10000-15000. If so I would create a third column that is an INT ...
No there isn't anything similar to what you are asking built into the product. Standard SQL has the concept of a NATURAL JOIN that joins on common column names but SQL Server does not implement this and there would be no guarantee that any such names would correspond with the PK anyway. It would be possible in theory for you to write some sort of script ...
Nevermind. I used mysqli_insert_id and it worked. The documentation for this solution is available here.
I have used a hybrid approach with success. Tables contain BOTH an auto-increment primary key integer id column AND a guid column. The guid can be used as needed to globally uniquely identify the row and id can be used for queries, sorting and human identification of the row.
I know my answer might be late. Yes, this used to happen when SQL server is restarted. See here for more information (as given in other answers). With SQL Server 2014, it has been fixed (identity wont increased by 1000) only if there was a planned SQL Server restart. I have solved in another way by adding a start up stored procedure in SQL Server 2012. ...
Top 50 recent answers are included