怎样在sql中把主键值设成是自动加1

或者用语句也行,谢谢大家了
string strSql = "Insert into z_GoodsInfo(Goods_ID,Goods_name,Type_typeID,Goods_addDate) values (............'" + strName + "','" + strType + "','" + DateTime.Now + "');";

1、如果你用的是SQL Server数据库,在你设计库表时把Goods_ID字段的数据类型设置为Int,在下面的标识中选择“是”,在标识种子中输入“1”,在标识递增量中输入“1”。这样你的这个Goods_ID字段就可以自动增加1了。

2、如果你用的是Access数据库,那才好设置呢,在表中的字段Goods_ID数据类型中选择“自动编号”。

3、如果不是以上两种数据库,那我就帮不上了。
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-03-15
主键值自动加1的方法如下:
create table mytest
(
id int primary key identity(1,1),--主键,自动+1
name varchar(20) unique not null,--不允许重复,不允许为空
Age tinyint,
notetime smalldatetime default getdate()
)
第2个回答  2007-05-15
自动加1,要数据库支持,要不就插入前先select max goods_ID
第3个回答  2007-05-15
select max(id)+1
相似回答