--如果不考虑字段不可修改的情况(字段上有约束时,是不可以直接修改字段的) --可以用下面这一句完成所有表的修改exec sp_msforeachtable @whereand=' and exists(select * from syscolumns where id=o.id and name=''编号'' and xusertype=175 and prec=10)', @command1='alter table ? alter column 编号 varchar(20)'
主键/外键/默认值/唯一键/索引,这些都要删除才能修改--至于字段类型与长度的问题 --name=''编号'' --这个是限制修改的字段名的 --xusertype=175 --这个是限制只修改字段的类型是 char 的 --prec=10 --这个是限制只修改长度为10的 --三个条件联合起来就是限制修改:字段名=编号,类型=char(10)的,你可以根据自己的需要改exec sp_msforeachtable @whereand=' and exists(select * from syscolumns where id=o.id and name=''编号'' and xusertype=175 and prec=10)', @command1='alter table ? alter column 编号 varchar(20)'
--可以用下面这一句完成所有表的修改exec sp_msforeachtable
@whereand=' and exists(select * from syscolumns where id=o.id and name=''编号'' and xusertype=175 and prec=10)',
@command1='alter table ? alter column 编号 varchar(20)'
对象 'PK_da_scda' 依赖于 列 '编号'。
服务器: 消息 4922,级别 16,状态 1,行 1
ALTER TABLE ALTER COLUMN 版号 失败,因为有一个或多个对象访问此列。
如果先把主外键关系去掉是不是就可以了提问的时候为了说的简单一些,没有说具体
这个字段以前的类型是不完全一样的,也就是说有些是varchar(10) ,有些是char(8)
这样是不是也会受到影响还有2个表的"编号"是int型的(这个可以不考虑,我可以先手工把它改成其它名字)
--name=''编号'' --这个是限制修改的字段名的
--xusertype=175 --这个是限制只修改字段的类型是 char 的
--prec=10 --这个是限制只修改长度为10的
--三个条件联合起来就是限制修改:字段名=编号,类型=char(10)的,你可以根据自己的需要改exec sp_msforeachtable
@whereand=' and exists(select * from syscolumns where id=o.id and name=''编号'' and xusertype=175 and prec=10)',
@command1='alter table ? alter column 编号 varchar(20)'
xusertype smallint 扩展的用户定义数据类型 ID。
xusertype=175是char,在哪里可以查到其他类型对应的值