SQL Server sql 操作

1、重命名表
将表OLD重命名为NEW:

EXEC sp_rename 'OLD','NEW'

2、重命名列
将表table1中的列old重命名为new:

EXEC sp_rename 'table1.old','new','COLUMN'

3、删除主键:

Declare @Pk varChar(100);
Select @Pk=Name from sysobjects where Parent_Obj=OBJECT_ID('tableName') and xtype='PK';
if @Pk is not null
exec('Alter table tableName Drop '+ @Pk)

4、创建主键:

ALTER Table tableName ADD CONSTRAINT pkName PRIMARY KEY (pkfield)

5、联表更新

update t1 set t1.column2 = t2.column2  from table1  t,table2  t2  where t.column1 = t2.column1;
上一篇:在MVC5和webAPI下是用Autofac依赖注入


下一篇:Spring Security入门(3-1)Spring Security的登录页面定制