• 爱情文章
  • 亲情文章
  • 友情文章
  • 生活随笔
  • 校园文章
  • 经典文章
  • 人生哲理
  • 励志文章
  • 搞笑文章
  • 心情日记
  • 英语文章
  • 范文大全
  • 作文大全
  • 新闻阅读
  • 当前位置: 山茶花美文网 > 英语文章 > 正文

    [Sql,Server代码设置主键并自动生长]设置产品代码字段为主键

    时间:2020-05-29来源:山茶花美文网 本文已影响 山茶花美文网手机站

    新建一张数据表,将Userid设为主键并自动增长

    create table T_UserLogin(UserId int not null primary key identity(1,1),UserName nvarchar(50) not null,Pass varchar(50) not null )

    修改已经建好的一张数据表,将Userid设为主键并自动生长

    alter table tb alter column id int not null

    alter table tb add constraint pkid primary key (id)

    删除主键

    Declare @Pk varChar(100);

    Select @Pk=Name from sysobjects where Parent_Obj=OBJECT_ID("tb") and xtype="PK";

    if @Pk is not null

    exec("Alter table tb Drop "+ @Pk)

    • 爱情文章
    • 亲情文章
    • 友情文章
    • 随笔
    • 哲理
    • 励志
    • 范文大全