自动递增主键 [英] Auto increment primary key

查看:96
本文介绍了自动递增主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表,其中有4列:

Food_Id
Food_Name
卡路里
食物类型


我正在制作一个小型应用程序,能够将数据添加到数据库中.我需要能够将主键(Food_Id)设置为自动递增,但是用于自动放大的所有选项均显示为灰色且无法选择.

因此,简单的问题是如何自动增加主键?

在此先感谢

Hi, I have a simply table with 4 columns:

Food_Id
Food_Name
Calories
Food_Type


I am making a small app to be able to add data to the database. I need to be able to set the primary key (Food_Id) to be auto incremented however all the options for auto incremeted are greyed out and unavailble for selection.

So the simply question is how do I auto increment a primary key?

Thanks in advance

推荐答案

简单:
创建字段时(假设您正在使用SQL Management Studio),请为其提供int数据类型,然后在"Identity Specification"的属性中查找.单击左侧的加号"以展开树.
双击身份",它将从否"变为是".

现在它是一个自动递增字段,并且选项可用.

[edit]

刚刚意识到,如果您在VS中执行此操作,则原理是相同的:
将字段创建为Int,然后将"Identity"更改为"true".然后可以使用这些选项.

OriginalGriff
[/edit]

[edit2] Do! 不"更改为现在"-OriginalGriff [/edit2]
Easy:
When you create the field (I assume you are using SQL Management studio), give it an int datatype, then look in the properties for "Identity Specification". Click on the "plus" sign to it''s left to expand the tree.
Double click on "Is identity" and it will change from "No" to "Yes".

It is now a autoincrementing field, and the options are available.

[edit]

Just realized, if you are doing this in VS, then the principle is the same:
Create the feild as an Int, then change "Identity" to "true". The options are available then.

OriginalGriff
[/edit]

[edit2]Doh! "Not" changed to "Now" - OriginalGriff[/edit2]


这篇关于自动递增主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆