問題描述
create table ImagenesUsuario
{
idImagen int primary key not null IDENTITY
}
這不起作用.我該怎么做?
This doesn't work. How can I do this?
推薦答案
只需對語法進(jìn)行簡單的更改即可:
Simple change to syntax is all that is needed:
create table ImagenesUsuario (
idImagen int not null identity(1,1) primary key
)
通過顯式使用constraint"關(guān)鍵字,您可以為主鍵約束指定一個特定名稱,而不是依賴 SQL Server 自動分配名稱:
By explicitly using the "constraint" keyword, you can give the primary key constraint a particular name rather than depending on SQL Server to auto-assign a name:
create table ImagenesUsuario (
idImagen int not null identity(1,1) constraint pk_ImagenesUsario primary key
)
如果根據(jù)您對表的使用情況最有意義,請?zhí)砑覥LUSTERED"關(guān)鍵字(即,搜索特定 idImagen 和寫入量的平衡超過了通過其他索引對表進(jìn)行聚類的好處).
Add the "CLUSTERED" keyword if that makes the most sense based on your use of the table (i.e., the balance of searches for a particular idImagen and amount of writing outweighs the benefits of clustering the table by some other index).
這篇關(guān)于創(chuàng)建 SQL 身份作為主鍵?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!