RedGate - Computed Column Dependent on Function Fails in Migration - sql-server

We've added a new computed column to a SQL Server database table. The new computed column is dependent on a new function.
When we attempt to deploy the branch, migrations reports the error shown below.
Error: Synchronization of 'Scripts.RedGate' and 'SomeServer.SomeDb' failed:
Cannot find either column "dbo" or the user-defined function or aggregate
"dbo.IsACredit", or the name is ambiguous. Error executing the following SQL:
ALTER TABLE [dbo].[SomeTable] ADD [IsCredit] AS ([dbo].[IsACredit]([ID]))
How can we successfully deploy these needed database changes?
Thank you in advance!

Related

How to update db's column name wihout creating a new db? (Android Studio ,SQLite)

I changed one of the column's name in my db and when I run my app I get this error :
5 10449-10449/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.liavbapps.mascoret, PID: 10449
android.database.sqlite.SQLiteException: no such column: TarrifHolyDay (code 1): , while compiling: UPDATE MySettings SET TarrifHolyDay=?
I know that happens beacuse it try to update a column that doesnt exist in my current db.
If I will open a new db it will contain the new column name , but I lose my data.
My question is how can I update my current db's column name, in oreder to keep my data ?
Thanks!
You need to alter the table, check ALTER TALBE SQL command :
http://www.techonthenet.com/sql/tables/alter_table.php
Take a look of MODIFY COLUMN IN TABLE section.

Database Access Mdb how to set a default value to existing column via SQL

I have a 12 years old mdb database and I was asked to add a new column to a table and set to a default value of "1".
My knowledge of asp/mdb is close to zero. I also have no Access or similar softwares.
I tried with:
ALTER TABLE Members ADD COLUMN Privacy Double Default 1
but generates error:
Error: An action query cannot be used as a row source.
Then I tried with:
ALTER TABLE Members MODIFY COLUMN Privacy VARCHAR(4) NOT NULL DEFAULT 'Yes';
but this also triggers another error:
Microsoft JET Database Engine error '80040e14'
How can I set an existing column to a default value?
Should I use an offline tool? If so which one?
Note: I also used an online tool to create the new column but it has no option to set a default value.
So I can either create the new column with the tool and set a default value with SQL, or do the creation of the column with the default value still with SQL.
I solved using AxBase from SourceForge.net.
I could properly open the *.mdb database and run the above SQL commands and they worked perfectly:
ALTER TABLE Members ALTER COLUMN Privacy SET DEFAULT 1
hi your access database is may be in office 2003 or office xp.
You can try to enable sql syntax and then try to run your query.
Tools -> Options -> Tables/Queries -> (At the bottom right:) Sql Server Compatible Syntax - turn option on for this database.
ALTER TABLE Members ADD COLUMN Privacy number Default 1

Unable to update a table using sql query in sql server

I use sql server 2014.
I have a table in my ManuDB database called (waqf).
I am trying to update the table
but not allowed and a message (invalid object name waqf) appears.
I don't know what is the reason although I have a table called waqf.
Because you are executing the statement in Master Database as shown in the snip shot.
select the correct database from drop down list shown in picture or execute the following statement.
USE ManuDB
GO
UPDATE ......
From the drop down list of database; set it to ManuDB.
At the moment, it's pointing to Master which doesn't have your table.
Type USE <yourdatabasename> before your update statement

Unable to carry out operations (create trigger, drop table) for a table I created

I am using a SQL Server database with SQL Server Management Studio where I have existing tables. I add a few tables to it and it works just fine. However, for subsequent operations such as
Drop table XXX --OR
Create Trigger YYY on XXX
I run into a error statement that reads:
i) Cannot drop table XXX as it does not exist or you do not have permissions
ii) The object 'XXX' does not exist or is invalid for this operation
I tried to carry out an Insert operation but that showed me a similar error (The object 'XXX' does not exist). I can see this maybe a permissions issue since I am using an existing database. However, in that case, I should have been unable to create a table as well?
Can anyone pinpoint how I can work myself around this and what the problem is?
What is your default schema?
SELECT name, default_schema_name
FROM sys.database_principals
WHERE type = 'S';
Try qualifying your references to the table as SchemaName.XXX and see if that helps.
Most of times when I had similar situations tables were created in system databases (master, tempdb..). Of course it was my mistake.
So maybe try to search for a tables in other databases?

Cannot insert duplicate record in a table

I am trying to execute stored proc through SSIS and it gives me following error:
[Execute SQL Task] Error: Executing
the query "Exec sp1 ?" failed with
the following error: "Procedure: sp1
Line: 66 Message: Cannot insert
duplicate key row in object
'table.sq1' with unique index
'UIX_sp1_Key'.". Possible failure
reasons: Problems with the query,
"ResultSet" property not set
correctly, parameters not set
correctly, or connection not
established correctly.
Actually the stored Proc sp1 is truncating & reloading a data into a table.
I am not able to figure out where exactly its trying to insert duplicate record.
Thanks in advance.
Your data must have duplicate values across the key column(s). You could remove the primary key temporarily (or create another table with the same structure but without the definition of the primary key, but that would mean changing the stored procedure), then load the data into the table. Then use this SQL statement:
select keycol1 {,keycol2 {,keycol3} ...}, count(*)
from tablename
group by keycol1 {,keycol2 {,keycol3} ...}
having count(*) > 1
That will show you the data values that are duplicates across the key column(s).
If you are truncating the table before load, then you must have duplicate data in the source.
Examine this to see what there is. use Excel or Access or some such if needed to assist. Or drop the unique constraint then query the staging table with an aggregate query.

Resources