MSSQL Server index ' Uq_f_username ' relies on column ' F_username '. ALTER TABLE ALTER COLUMN F_USERNAME failed because one or more objects access this column

Source: Internet
Author: User
Tags mssql mssql server

--Requirements change, need to add a foreigner name to the F_username field of the T_login table, the previous set of varchar (10) is not enough, the negotiation decision to change to varchar (30), when executing, the message index ' Uq_f_username ' depends on the column ' F_ UserName '. ALTER TABLE ALTER COLUMN F_USERNAME failed because one or more objects access this column.
--Originally, a unique index uq_f_username was added to prevent f_username duplication.
--After doing the following, the problem is duly resolved.
--Table name: T_login (Login table)
--Field: f_username (user name)
--Execution requirements: Change the f_username length from varchar (10) to varchar (30)
--Syntax format
--Delete the previous index
Drop Index uq_f_username on T_login
Go
--Modify field length
ALTER TABLE t_login ALTER COLUMN f_username varchar (30)
Go
--Re-create INDEX
Create unique nonclustered index [uq_f_username] on [dbo]. [T_login]
(
[F_username] ASC
)
--created when the index does not exist
where ([f_username] is not null)
--This is a series of SQL Server indexes, self-brain: https://msdn.microsoft.com/zh-cn/library/ms188388.aspx
With (Pad_index = off, Statistics_norecompute = off, sort_in_tempdb = off, Ignore_dup_key = off, drop_existing = off, Onli ne = off, allow_row_locks = on, allow_page_locks = ON)
Go
--After the previous index fails, modify the index to prevent the index modification from failing
Alter INDEX [UQ_F_USERNAME] on [dbo]. [T_login] Disable
Go

MSSQL Server index ' Uq_f_username ' relies on column ' F_username '. ALTER TABLE ALTER COLUMN F_USERNAME failed because one or more objects access this column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.