手机
当前位置:查字典教程网 >编程开发 >mssql数据库 >Sql Server代码设置主键并自动生长
Sql Server代码设置主键并自动生长
摘要:新建一张数据表,将Userid设为主键并自动增长createtableT_UserLogin(UserIdintnotnullprimary...

新建一张数据表,将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)

【Sql Server代码设置主键并自动生长】相关文章:

Sql server 取当天或当月的记录

sqlserver如何从外网通过IP连接

SQLServer中master数据库分析

SQL Server 中查看SQL句子执行所用的时间

SQL server 2005中设置自动编号字段的方法

SQL Server 2005 更改安装路径目录的方法小结

SQL Server 索引介绍

SQLServer2005中的SQLCMD工具使用

关于SQLServer2005的学习笔记 XML的处理

SQL Server数据库的修复SQL语句

精品推荐
分类导航