<!--设为主键-->
alter   table   DataTest add primary key (Id);

 --删除主键
 DECLARE @Constraint_Name varchar (200)
 select @Constraint_Name = Name
 from dbo.sysobjects
 where Xtype = 'PK'
       and Parent_Obj = (select [ID]
                                from dbo.sysobjects
                                where id = object_id(N'[Test]')
       and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 EXEC ('alter table Test drop constraint '+@Constraint_Name ) 
 print(@Constraint_Name)

<!--插入列-->
alter table DataTest add UserPwd nvarchar(20)  null;

<!--删除列 -->
ALTER TABLE DataTest drop column UserPwd;

<!--修改列UserPwd改为PassWord-->
ALTER TABLE DataTest ALTER column UserPwd PassWord  ;

<!--修改字段类型和范围-->
ALTER TABLE DataTest ALTER COLUMN UserName nvarchar(30);

<!--给表改名字 给一个表重命名:-->
ALTER TABLE DataTest alter  Test;

--修改表名
exec   sp_rename   'DataTest','Test'

相关文章:

  • 2022-12-23
  • 2022-01-22
  • 2022-03-08
  • 2021-07-01
  • 2021-08-05
  • 2021-07-26
猜你喜欢
  • 2021-12-27
  • 2021-07-16
  • 2022-12-23
  • 2021-09-29
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案