An error occurred while modifying fields in the table.

Source: Internet
Author: User

Specific error message,

Message 5074, level 16, state 1, 2nd rows
The object 'price' depends on the column 'price '.
Message 4922, level 16, status 9, 2nd rows
Alter table alter column price failed because one or more objects access this column.

Modification fails because of check constraints in the table.

 

The correct method is to delete the constraint, modify it, and add the constraint.

 

Eg.

1 create table # books 2 3 (4 5 Id int primary key, 6 7 name nvarchar (50) not null, 8 9 price numeric (4) Check (price between 20 and 50) 10 11)

 

If I want to change the price data type to float

Alter table books

Alter column price float (2)

The above error is reported.

 

1. Delete the constraint first

You can delete a table by using the Table Designer.

 

2. Modify alter table books alter column price nvarchar (10)

3. Add the check constraint alter table books add constraint price_r check (price> = 20 and price <= 50)

 

An error occurred while modifying fields in the table.

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.