我有一个SSIS数据流任务,它将查找匹配的记录并将它们提供给OLE DB Command组件。当我运行它时,我收到一条错误消息:
Error: 0xC0202009 at Data Flow Task, OLE DB Command [28]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E14 Description: "Property cannot be added. Property 'MS_Description' already exists for 'dbo.d_date.d_date_key'.".
我的SQL是:
UPDATE d_date
SET company_year_period = ?,
company_quarter = ?,
company_year_quarter = ?,
company_quarter_year = ?,
company_first_day_of_week = ?,
company_last_day_of_week = ?,
is_company_holiday = ?,
company_special_event = ?,
is_us_holiday = ?,
us_special_event = ?,
is_canadian_holiday = ?,
canadian_special_event = ?,
is_mexican_holiday = ?,
mexican_special_event = ?
WHERE d_company_key = ?
AND calendar_date = ?
为什么这个组件/简单更新会弄乱扩展属性?!?
这里完成的是我创建表时使用的代码。
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Primary key for the d_date table. While it is a surrogate key it never the less has the form yyyymmdd.' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'd_date', @level2type=N'COLUMN',@level2name=N'd_date_key'
CREATE TRIGGER d_date_update ON d_date
AFTER UPDATE
AS
UPDATE d_date
SET last_update = GETDATE()
WHERE d_date_key IN (SELECT DISTINCT d_date_key FROM Inserted)
;
我有一个表d_date,每列都有MS_Description的扩展属性。该表填充了2558个日期记录。我有一个没有扩展属性的第二个工作表。它还填充了一些略有不同的记录。以下更新失败:
UPDATE dd
SET dd.company_year_period = wdd.company_year_period,
dd.company_quarter = wdd.company_quarter,
dd.company_year_quarter = wdd.company_year_quarter,
dd.company_quarter_year = wdd.company_quarter_year,
dd.company_first_day_of_week = wdd.company_first_day_of_week,
dd.company_last_day_of_week = wdd.company_last_day_of_week,
dd.is_company_holiday = wdd.is_company_holiday,
dd.company_special_event = wdd.company_special_event,
dd.is_us_holiday = wdd.is_us_holiday,
dd.us_special_event = wdd.us_special_event,
dd.is_canadian_holiday = wdd.is_canadian_holiday,
dd.canadian_special_event = wdd.canadian_special_event,
dd.is_mexican_holiday = wdd.is_mexican_holiday,
dd.mexican_special_event = wdd.mexican_special_event
FROM d_date AS dd
LEFT JOIN working_d_date AS wdd ON wdd.d_company_key = dd.d_company_key
AND wdd.calendar_date = dd.calendar_date
(2558 row(s) affected)
Msg 15233, Level 16, State 1, Procedure sp_addextendedproperty, Line 37
Property cannot be added. Property 'MS_Description' already exists for 'dbo.d_date.d_date_key'.
最后评论: 我在SS2014 Enterprise上运行所有这些,我在工作站上使用试用许可证进行了设置。我不是DBA所以我没有正确设置的可能性很大。
我把所有东西都搬到我们的生产SS2008 R2服务器上,我没有看到任何问题。这可能是2014年和2008年之间的一个问题,但更可能是我2014年安装时的某种设置问题。当我们正式安装2014时,我会再次访问。
答案 0 :(得分:1)
疯狂猜测:
当您执行Create Trigger
时,您在同一批次中包含了对sp_addextendedproperty
的调用..
CREATE TRIGGER d_date_update ON d_date
AFTER UPDATE
AS
UPDATE d_date
SET last_update = GETDATE()
WHERE d_date_key IN (SELECT DISTINCT d_date_key FROM Inserted)
;
--- THIS IS YOUR PROBLEM!!!!
--- This has been included in the trigger itself.
EXEC sys.sp_addextendedproperty @name=N'MS_Description',
@value=N'Primary key for the d_date table. While it is a surrogate key it never the less has the form yyyymmdd.' ,
@level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'd_date', @level2type=N'COLUMN',@level2name=N'd_date_key'
触发器一直持续到批次结束。 分号不会结束批处理它只会结束语句。您必须说 GO
才能结束批次。
更多讨论:SQL的范围规则与C#完全不同。您可能会想象触发器由单个语句组成,该语句可以是块语句或简单语句,这是一种自然的假设,但事实并非如此。
在你说"创建触发","创建程序"或者"创建功能", 批次结束时的所有内容 是触发器,proc或功能的一部分 。