How to generate a new Guid in stored procedure?

前端 未结 5 847
时光说笑
时光说笑 2021-02-03 16:16

I currently have a stored procedure in which I want to insert new rows into a table.

insert into cars
(id, Make, Model)
v         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-03 17:22

    You didn't ask about this in your question, but I think it's worth pointing out that using a GUID for a primary key is not always a good idea. While it's simple, it can affect performance when a GUID is used in an index. Have you considered using an Identity column that is an integer value instead?

    Here are a couple of articles that might be helpful to read.

    • Performance Effects of Using GUIDs as Primary Keys (SQL Server Magazine)
    • Primary Keys: IDs versus GUIDs (Jeff Atwood)
    • The Cost of GUIDs as Primary Keys (Jimmy Nelson's article referenced by the two other articles)

提交回复
热议问题