gpt4 book ai didi

sql-server - 为什么 UPDATE .WRITE() 仅在我使用 [column].WRITE() 时才有效,而不是 [table].[column].WRITE()?

转载 作者:行者123 更新时间:2023-12-03 02:20:09 28 4
gpt4 key购买 nike

我正在执行 UPDATE .WRITE() 语句,并发现它显然只有在您像这样定义它时才有效:

string sql = "UPDATE [dbo].[Table] SET [Column].WRITE(@data, @offset, @count) WHERE ...";
...
sqlCommand.ExecuteNonQuery();

但是,如果我使用 [dbo].[Table].[Column].WRITE(...)[Table].[Column].WRITE(... ),抛出异常:

Incorrect syntax near 'WRITE'.

Stack trace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
...

这是为什么呢?它似乎与构建 SQL 语句的通常方式不太一致。这种看似特殊的约定有什么意义吗?显然不允许您显式指定表名称和架构?

最佳答案

It doesn't seem very consistent ...

它实际上与 SET clause 的其余部分一致:

SET
{ column_name = { expression | DEFAULT | NULL }
| { udt_column_name.{ { property_name = expression
| field_name = expression }
| method_name ( argument [ ,...n ] )
}
}
| column_name { .WRITE ( expression , @Offset , @Length ) }
| @variable = expression
| @variable = column = expression
| column_name { += | -= | *= | /= | %= | &= | ^= | |= } expression
| @variable { += | -= | *= | /= | %= | &= | ^= | |= } expression
| @variable = column { += | -= | *= | /= | %= | &= | ^= | |= } expression
} [ ,...n ]

也就是说,在 SET 子句中,在赋值的左侧指定表或架构是永远有效的(当然,您可以引用其他表的全名或别名,在右侧的表达式中)。要更新的表已在 UPDATESET 之间标识。

关于sql-server - 为什么 UPDATE .WRITE() 仅在我使用 [column].WRITE() 时才有效,而不是 [table].[column].WRITE()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17521476/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com