sybase: fail to drop default of a column - sybase

We want to change a column type from smallint to decimal. The 'alter table' sql statement passed in a UAT db server but failed in a production server. DBA suggests it could be related to the 'default' constraint of the column but that is all the help we got.
I am thinking of dropping the default off first before altering the column type.
I tried this sql statement:
alter table MyTable alter MyColumn drop default
But I got this error message:
Error: Incorrect syntax near the keyword 'alter'.
SQLState: ZZZZZ
ErrorCode: 156
What is wrong with this syntax? The target DB is 15.5
I used this as syntax reference

I'm going to guess that you may be using Sybase ASE, given the version number you listed, and the fact that the Sybase IQ syntax gave you an error message.
For SAP Sybase ASE you would drop the default using the sp_unbindefault command.
sp_unbindefault 'MyTable.MyColumn'
Documentation:
Adaptive Server Enterprise 15.5 > Reference Manual: Procedures > System Procedures

Related

The JPA LOCK TABLE statement causes an exception for SQL Server

In order to prevent concurrent updates to a table by different threads, we protect it with
em.createNativeQuery("LOCK TABLE mytable IN EXCLUSIVE MODE").executeUpdate();
where em is a JPA EntityManager.
This is working correctly in Postgres but not in SQL Server (and I think in Oracle it may not be working either).
Is there something to enable in SQL Server so that the above JPA statement does not give a " SQL Error: 156, SQLState: S0001, Incorrect syntax near the keyword 'TABLE'" error?

SQL Server 2016 Stored Procedure Syntax Error

I recently restored a SQL Server 2008 database into an instance of SQL Server 2016. Most of the functionality seems to work fine, but many of my stored procedures that include updates to an application database table called SYS_USER fails with the following error:
Msg 102, Level 15, State 1, Procedure SYS_USERupdate, Line 35 [Batch Start Line 0]
Incorrect Syntax near '#errorNumber'
The database does not have a stored procedure called SYS_Userupdate and none of the procedures' code includes the term #errorNumber. I attempted to run the SQL query from one of the failing procedures directly in SQL Server Management Studio and received the same error message. Here is the SQL query that is failing:
UPDATE SYS_USER
SET SYS_USER_LGF_DT = GETDATE()
WHERE SYS_USER_ID = #SYS_USER_ID
I plugged in a valid value for the #SYS_USER_ID variable. Similar queries in related to other tables run without an issue. All of the stored procedures work on a SQL Server 2008 instance with no errors. Also, the database compatibility_level to 100, which should be acceptable for SQL Server 2016.
This happens when you're not running on a correct version of SQL Server, or if the compatibility level of the database isn't set sufficiently. So change it to 130
To check compatibility level:
select compatibility_level
from sys.databases
where name = '<database name>'
To alter compatibility level:
alter database <database-name>
set compatibility level = 130 -- SQL Server 2016
Compatibility levels list for all SQL versions: ALTER DATABASE (Transact-SQL) Compatibility Level
Reposting the answer since it was proposed in a comment to the question. The solution to the problem was that there were triggers on the affected tables that I did not know were there. Syntax errors on these triggers were causing insert and update queries on the tables to fail.
Credit to Jeroen Mostert https://stackoverflow.com/users/4137916/jeroen-mostert for helping with this!

SQL Server 2008 R2 Not able to resolve Merge conflict

I am running a merge replication. During the merge process there is a conflict. If I choose the winner, the conflict just comes back. If I choose a loser, I get an error.
TITLE: Microsoft Replication Conflict Viewer
Microsoft Replication Conflict Viewer encountered an error executing the following query:
set DATEFORMAT mdy if (select OBJECTPROPERTY(OBJECT_ID('[tABLE]'),'TableHasIdentity')) =1
[SQL INSERT STATEMENT]
ADDITIONAL INFORMATION:
The insert failed. It conflicted with an identity range check constraint in database [Database], replicated table [TABLE]. , column [TABLE]. If the identity column is automatically managed by replication, update the range as follows: for the Publisher, execute sp_adjustpublisheridentityrange; for the Subscriber, run the Distribution Agent or the Merge Agent.
The statement has been terminated. (Microsoft SQL Server, Error: 548)
I have run sp_adjustpublisheridentityrange to fix this, but it does not resolve the issue or change the range on the table.
Any ideas?
I found orphaned records in the subscriber. Once deleted, the conflicts resolved themselves.

Store spss data on SQL database based on uniqueidentifier

I Imported a table from SQL database to SPSS dataset, I edited the table by adding a new column to it after some statistics, but when I try to export the table back to the database by adding the new column, by matching the Primary key from dataset and database table which is of type "uniqueIdentifier, this error is shown to me
> Error # 6492
>The ODBC subsystem has issued an error which prevents the processing of SAVE
>TRANSLATE ODBC request.
>Execution of this command stops.
>[Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed when
>converting from a character string to uniqueidentifier.
how to resolve this error?
uniqueidentifier is probably a type that the ODBC driver doesn't know how to convert to as it is probably a database internal type. Try writing your data to a new table without converting and then do an update of the database table from within the database converting the identifier type inside the database. You can put the necessary SQL in your SAVE TRANSLATE syntax using its SQL subcommand.

sqlpackage breaks when trying to alter a FILESTREAM column

I have a SQL Database project, where I have recently amended a FILESTREAM column to allow nulls. I am trying to publish the project's dacpac to a db where the column already exists, as a filestream column, but is currently NOT NULL.
I am performing the publish using the sqlpackage.exe command line tool (version 12.0.2882.1). However, it produces the error:
Error SQL72014: .Net SqlClient Data Provider: Msg 4990, Level 16, State 1, Line 1 Cannot alter column 'document' in table 'Document' to add or remove the FILESTREAM column attribute.
Error SQL72045: Script execution error. The executed script:
ALTER TABLE [dbo].[Document] ALTER COLUMN [document] VARBINARY (MAX) NULL;
The sql in the error looks like the generated script is trying to remove the FILESTREAM attribute on the column, which I guess is why SQL Server is complaining... but why is it doing this? My DB project still has the column marked as FILESTREAM
Fixed by upgrading sqlpackage.exe and associated libraries from version 12.0.2882.1 to 12.0.3021.1

Resources