如何向数据库中插入一条记录,以及取得新插入记录的自动生成的主键
发布网友
发布时间:2022-04-08 19:24
我来回答
共1个回答
热心网友
时间:2022-04-08 20:53
如何向数据库中插入一条记录,以及取得新插入记录的自动生成的主键
创建表格的时候将主键设定为IDENTITY:
CREATE TABLE Test
(
<a href="https://www.baidu.com/s?wd=Id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPynYP10vuj-WPHnvPH6d0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPH0vPjTYnWm3" target="_blank" class="-highlight">Id</a> INT PRIMARY KEY <a href="https://www.baidu.com/s?wd=ID&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPynYP10vuj-WPHnvPH6d0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPH0vPjTYnWm3" target="_blank" class="-highlight">ID</a>ENTITY,
Value <a href="https://www.baidu.com/s?wd=NVARCHAR&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPynYP10vuj-WPHnvPH6d0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPH0vPjTYnWm3" target="_blank" class="-highlight">NVARCHAR</a>(128) NOT <a href="https://www.baidu.com/s?wd=NULL&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPynYP10vuj-WPHnvPH6d0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPH0vPjTYnWm3" target="_blank" class="-highlight">NULL</a>
)