如何修改表字段类型:--加
ALTER TABLE table2 ADD row_id bigint--删
ALTER TABLE table2 DROP COLUMN row_id--改
ALTER TABLE 你的表 ALTER COLUMN 列名 你的类型 null
ALTER TABLE table2 ADD row_id bigint--删
ALTER TABLE table2 DROP COLUMN row_id--改
ALTER TABLE 你的表 ALTER COLUMN 列名 你的类型 null
解决方案 »
- 请问一句SQL怎么理解?
- 求SQL语句,如何使所有记录某列仅保留前六位,其余的全部截掉
- 安装过程提示以下错误:Command line option syntax error.Type Comemand /? for Help.
- 高分求解,关于varchar
- 同局域网不同网段的SQL数据库访问
- 登陆sqlserver2005出现18452
- 求救啊!数据查找有问题啊~~急啊~~~~~~~
- SQL SERVER 2005 安装问题,晕
- access中如何设置默认值及小数(numeric型)?
- 这种情况,设计成一张表好,还是两张表好?
- 关于表中行变列并且算和的问题?
- 请高手帮忙看一下,该存储过程哪里有问题
select @a=c.name from syscolumns a,sysconstraints b,sysobjects c where a.id=object_id('表名') and a.name='主鍵列名' and a.id=b.id and b.constid=c.id and c.name like 'PK%'if @a is not null
exec('alter table 表名 drop constraint '+@a)
会报错的。该类型已经定为主键,并且表中有数据。
declare @a varchar(20)
select @a=c.name from syscolumns a,sysconstraints b,sysobjects c where a.id=object_id('表名') and a.name='主鍵列名' and a.id=b.id and b.constid=c.id and c.name like 'PK%'
if @a is not nullexec('alter table 表名 drop constraint '+@a)
alter table 表名 add id1 intupdate 表名 set id1=主鍵列名alter table 表名 drop column 主鍵列名exec sp_rename '表名.id1','主鍵列名'alter table 表名 add constraint pk_表名_主鍵列名 primary key (主鍵列名)
declare @a varchar(200)
select @a=c.name from syscolumns a,sysconstraints b,sysobjects c where a.id=object_id('表名') and a.name='主鍵列名' and a.id=b.id and b.constid=c.id and c.name like 'PK%'
if @a is not nullexec('alter table 表名 drop constraint '+@a)
alter table 表名 add id1 intupdate 表名 set id1=主鍵列名alter table 表名 drop column 主鍵列名exec sp_rename '表名.id1','主鍵列名'alter table 表名 add constraint pk_表名_主鍵列名 primary key (主鍵列名)
ALTER TABLE table2 ADD ALTER COLUMN column_name
new_data_type [ ( precision [ , scale ]
}
ALTER TABLE table2 DROP COLUMN col_name
select @a=c.name from syscolumns a,sysconstraints b,sysobjects c where a.id=object_id('你的表') and a.name='你的列' and a.id=b.id and b.constid=c.id and c.name like 'PK%'if @a is not null
exec('alter table 你的表 drop constraint '+@a)go
alter table 你的表 add id1 int not null
go
update 你的表 set id1=你的列
go
alter table 你的表 drop column 你的列
go
exec sp_rename '你的表.id1','你的列'
go
alter table 你的表 add constraint pk_你的表_你的列 primary key (你的列)
go
update 表 set 编号1=编号
go
ALTER TABLE 表 DROP COLUMN 编号
go
exec sp_rename '表.编号1','编号'
go
ALTER TABLE table2 ADD ALTER COLUMN column_name
new_data_type [ ( precision [ , scale ]
}
ALTER TABLE table2 DROP COLUMN col_name2:在企业管理器中修改.