Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

O erro 1934 do SQL Server ocorre em INSERT para tabela com coluna computada PHP/PDO


Acontece que o problema tinha a ver com os parâmetros SET. Usei o código abaixo obtido em Aqui . Para determinar quais opções foram definidas no SQL Server Management Studio (onde a inserção funcionou). Em seguida, colocar cada um deles em um exec antes da minha instrução de inserção fez com que as coisas funcionassem novamente. Não precisei manter todas as opções, então abaixo mostro as que foram necessárias para que funcionasse.
DECLARE @options INT
SELECT @options = @@OPTIONS

PRINT @options
IF ( (1 & @options) = 1 ) PRINT 'DISABLE_DEF_CNST_CHK' 
IF ( (2 & @options) = 2 ) PRINT 'IMPLICIT_TRANSACTIONS' 
IF ( (4 & @options) = 4 ) PRINT 'CURSOR_CLOSE_ON_COMMIT' 
IF ( (8 & @options) = 8 ) PRINT 'ANSI_WARNINGS' 
IF ( (16 & @options) = 16 ) PRINT 'ANSI_PADDING' 
IF ( (32 & @options) = 32 ) PRINT 'ANSI_NULLS' 
IF ( (64 & @options) = 64 ) PRINT 'ARITHABORT' 
IF ( (128 & @options) = 128 ) PRINT 'ARITHIGNORE'
IF ( (256 & @options) = 256 ) PRINT 'QUOTED_IDENTIFIER' 
IF ( (512 & @options) = 512 ) PRINT 'NOCOUNT' 
IF ( (1024 & @options) = 1024 ) PRINT 'ANSI_NULL_DFLT_ON' 
IF ( (2048 & @options) = 2048 ) PRINT 'ANSI_NULL_DFLT_OFF' 
IF ( (4096 & @options) = 4096 ) PRINT 'CONCAT_NULL_YIELDS_NULL' 
IF ( (8192 & @options) = 8192 ) PRINT 'NUMERIC_ROUNDABORT' 
IF ( (16384 & @options) = 16384 ) PRINT 'XACT_ABORT'

Aqui estão as opções que acabei precisando:
$dbPDO->exec("SET ANSI_WARNINGS ON");                                                                               
$dbPDO->exec("SET ANSI_PADDING ON");
$dbPDO->exec("SET ANSI_NULLS ON");
$dbPDO->exec("SET QUOTED_IDENTIFIER ON");
$dbPDO->exec("SET CONCAT_NULL_YIELDS_NULL ON");

Atualização:Parece que as restrições FK resultaram no seguinte erro. O acima também corrigiu esse erro.