The object 'DF__*' is dependent on column '*' - Changing int to double
Try this:
Remove the constraint DF_Movies_Rating__48CFD27E before changing your field type.
The constraint is typically created automatically by the DBMS (SQL Server).
To see the constraint associated with the table, expand the table attributes in Object explorer, followed by the category Constraints as shown below:
You must remove the constraint before changing the field type.
EF migration for changing data type of columns
You have a default constraint on your column. You need to first drop the constraint, then alter your column.
public override void Up()
{
Sql("ALTER TABLE dbo.Received DROP CONSTRAINT DF_Receiv_FromN__25869641");
AlterColumn("dbo.Received", "FromNo", c => c.String());
AlterColumn("dbo.Received", "ToNo", c => c.String());
AlterColumn("dbo.Received", "TicketNo", c => c.String());
}
You will probably have to drop the default constraints on your other columns as well.
I've just seen Andrey's comment (I know - very late) and he is correct. So a more robust approach would be to use something like:
DECLARE @con nvarchar(128)
SELECT @con = name
FROM sys.default_constraints
WHERE parent_object_id = object_id('dbo.Received')
AND col_name(parent_object_id, parent_column_id) = 'FromNo';
IF @con IS NOT NULL
EXECUTE('ALTER TABLE [dbo].[Received] DROP CONSTRAINT ' + @con)
I know this probably doesn't help the OP but hopefully it helps anyone else that comes across this issue.
I'm trying this query to change attribute name
This seems to be a potential solution:
Error trying to rename columns with space in oracle table. Error - SQL Error : ORA- 00946 : missing TO keyword
alter table car rename column "office-id" to office_id
Change PostgreSQL column type from money to double precision
You cannot cast directly from money
to double precision
. First cast to numeric
:
ALTER TABLE tableName
ALTER price TYPE double precision USING price::numeric::double precision,
ALTER price DROP DEFAULT,
ALTER price SET NOT NULL;
This is actually explained in the documentation:
Conversion from the real and double precision data types can be done by casting to numeric first, for example:
. SELECT '12.34'::float8::numeric::money;
Change all bit columns to int with default value NULL
The solution is I had to add more brackets as delimiters to fix the syntax. The following query works perfectly:
ALTER TABLE dbo.Customers DROP CONSTRAINT [DF_Customers_Is item returned?]
ALTER TABLE dbo.Customers ALTER COLUMN [Is item returned?] int not null
ALTER TABLE dbo.Customers WITH NOCHECK ADD CONSTRAINT [DF_Customers_Is item returned?] DEFAULT NULL FOR [Is item returned?]
Related Topics
How to Transform Comma Separated Column into Multiples Rows in Db2
Does Assigning Stored Procedure Input Parameters to Local Variables Help Optimize the Query
Move Cells Left in SQL If Left Contains Null and Right Contains Value
Function-Based Indexes in SQL Server
Rowset Does Not Support Scrolling Backward
Multiple Column Foreign Key Contraints
How to Create a Decimal Field in Access with Alter Table
Concurrency Handling of SQL Transactrion
Oracle- Split String Comma Delimited (String Contains Spaces and Consecutive Commas)
Faster Way to Insert, via Script, in Oracle
How to Group Timestamps into Islands (Based on Arbitrary Gap)
How to Use If/Else Statement to Update or Create New Xml Node Entry in SQL
Using Ssis to Extract a Xml Representation of Table Data to a File
Checking If a String Is Found in One of Multiple Columns in MySQL
How to Expand Comma Separated Values into Separate Rows Using SQL Server 2005