如何向数据库中插入一条记录,以及取得新插入记录的自动生成的主键
1个回答
2017-09-09
展开全部
如何向数据库中插入一条记录,以及取得新插入记录的自动生成的主键
创建表格的时候将主键设定为IDENTITY:
CREATE TABLE Test
(
<a href="https://www.baidu.com/s?wd=Id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPynYP10vuj-WPHnvPH6d0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPH0vPjTYnWm3" target="_blank" class="baidu-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="baidu-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="baidu-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="baidu-highlight">NULL</a>
)
创建表格的时候将主键设定为IDENTITY:
CREATE TABLE Test
(
<a href="https://www.baidu.com/s?wd=Id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBPynYP10vuj-WPHnvPH6d0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPH0vPjTYnWm3" target="_blank" class="baidu-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="baidu-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="baidu-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="baidu-highlight">NULL</a>
)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询