sql server - Changing the Column data type that exists in more than one table -
i'm using sql server , have column asset_serial
exists in more 1 table.
the problem when wanted change type got this:
msg 5074, level 16, state 1, line 1
object 'pk_assets' dependent on column 'asset_serial'.msg 5074, level 16, state 1, line 1
object 'fk_assigned_assets_assets' dependent on column 'asset_serial'.msg 4922, level 16, state 9, line 1
alter table alter column asset_serial failed because 1 or more objects access column.
any suggestions...?
asset_serial primary key of current table , foreign key table first should drop 2 constraint , alter field in both tables , @ last create constraints again
if (object_id('fk_constraintname', 'f') not null) begin //drop constraint alter table [tablename] drop constraint [fk_constraintname] alter table [tablename] drop constraint [pk_constraintname] //alter table change column alter table alter column asset_serial //create contraints alter table [tablename] add constraint pk_constraintname primary key (fieldname); alter table [dbo].[tablename] check add constraint [fk_tablename_tablename2] foreign key([asset_serial]) references [dbo].[tablename2] ([asset_serial]) end
Comments
Post a Comment