MSSQL用户定义的表类型中的可选列

发布于 2025-02-13 23:22:09 字数 729 浏览 0 评论 0原文

我有一个用户定义的表类型:

CREATE TYPE [dbo].[UDT_MyTable] AS TABLE(
    col1 int NULL,
    col2 int NULL,
    col3 int NULL
)

将此类型传递给过程,并从代码中的几个位置使用。

最近,需要使用此类型的地方之一添加另一列。

因此,我修改了类型,当然更新了使用此类型的过程来使用该过程的新类型:sp_refreshsqlmodule 因此,现在的类型是:

CREATE TYPE [dbo].[UDT_MyTable] AS TABLE(
    col1 int NULL,
    col2 int NULL,
    col3 int NULL,
    Col4 INT NULL default(0) 
)

通过thor列的位置已更新,但我想避免所有位置参考此表。

获得此数据类型的所有其他呼叫过程的位置:

尝试通过3列传递表值参数,其中相应的用户定义表类型需要4列。

我想避免更改所有位置,请参阅此类型以传递第四参数或使用“默认”作为参数。

我只是想能够通过3列,而SQL将知道自己添加第四列。

是否可以?

I have a user defined table type:

CREATE TYPE [dbo].[UDT_MyTable] AS TABLE(
    col1 int NULL,
    col2 int NULL,
    col3 int NULL
)

This type is being passed to procedures and being used from several places in the code.

Recently, one of the places that uses this type is needed to add another column.

So I modified the type and of course update the procedures which uses this type to use the new type by the procedure: sp_refreshsqlmodule
so now the type is:

CREATE TYPE [dbo].[UDT_MyTable] AS TABLE(
    col1 int NULL,
    col2 int NULL,
    col3 int NULL,
    Col4 INT NULL default(0) 
)

The place which pass the forth column was update but I want to avoid all the places refer this table.

All the other places which call procedure which gets this datatype gets:

Trying to pass a table-valued parameter with 3 column(s) where the corresponding user-defined table type requires 4 column(s).

I want to avoid changing all the places refer to this type to pass the forth parameter nor use "DEFAULT" as parameter.

I simply want to be able to pass 3 columns and the SQL will know to add the forth by itself.

Is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文