The index is dependent on column T-SQL
<p>I try changing primary key constraint, but get the error saying: "The index is dependent on column". I tried dropping the index but it seems to do nothing. Am I even doing drop the right way? If no, is there any way to get specific index name? Also here's the <a href="https://stackoverflow.com/questions/38326732/error-when-changing-primarykey-constraint-in-table">link</a> to previous question for more details. </p>

<pre><code>declare @CONSTRAINTNAME varchar(128);
declare @script nvarchar(max);

select top 1 @CONSTRAINTNAME = t1.CONSTRAINT_NAME
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS t1
where CONSTRAINT_TYPE = 'PRIMARY KEY' and upper(t1.TABLE_NAME) = @tableName;

set @script = N'alter table [' + @tableName + N'] drop constraint [' + @CONSTRAINTNAME + N']';
exec sp_executesql @script

--drop
set @script = N'alter table [' + @tableName + N'] drop index[' + @oldIndex+ N']';
exec sp_executesql @script

set @script = N'alter table [' + @tableName + N'] add constraint [' + @tableName + '_' + @columnName + N'] primary key (['+ @columnName +'])';
exec sp_executesql @script
</code></pre>