我有類似以下內容的用戶定義的函數:是否可以命名由UDF返回的表的主鍵?
create function paying_customers(@report_month int, @report_year int)
returns @customer_subs table
(
customer_id int primary key not null,
amount money not null
)
as
begin
etc.
這工作得很好,但我想命名的主鍵(這似乎仍然在數據庫中的對象)。
下面給出的錯誤信息(靠近關鍵字約束不正確的語法):
create function paying_customers(@report_month int, @report_year int)
returns @customer_subs table
(
customer_id int not null,
amount money not null,
constraint pk_paying_customers primary key clustered (customer_id)
)
as
begin
etc.
我想,因爲我們有一個比較數據庫的腳本來命名的主鍵,它會找出差異 - 一個對象是在sys.objects中爲第一次運行UDF時臨時返回表的主鍵創建的(我不知道爲什麼這應該繼續存在....)。
擺脫'約束pk_paying_customers',它應該工作。 – siride 2015-01-21 02:42:00
謝謝@siride,也有效。但我仍然有sys.objects中的主鍵對象的問題。 – 2015-01-21 15:40:53