English 中文(简体)
SQL 服务器通用触发创建
原标题:SQL Server generic trigger creation

我正在尝试在 SQL 服务器上创建一个通用触发器, 该触发器可以复制表A中的所有列数据, 并将其插入表B的相应字段中。

我面对的问题不多。

我需要在三个条件下提供这一副本: INSERT , DELETE UPDATE

  1. CUD 操作后需要触发触发。 使用 AFFFTER 丢出 SQL 错误, 表示 < code> ntext 等不支持插入。 我如何解决这个错误?

  2. 使用后可以对 INSERT 工作,但不能删除。 是否有方法可以删除操作?

  3. 是否有一种方法我可以在触发器内写出通用代码,可以用于各种表格(我们可以假设表a中的所有栏目都存在于b栏中)

我对触发器或SQL服务器的DDL 问题并不熟悉。

如果有人能给我提供一些解决办法,我感激不尽。

Thanks Ben

问题回答

< a href=" "http://msdn.microsoft.com/en-us/library/ms1897999%28v=sql.105%29.aspx" rel="nofollow" >CREATE TRIGGER (Transact-SQL)

  1. Use nvarchar(max) instead of ntext.
  2. You can have an instead of trigger for delete.
  3. You can have one trigger that handles insert/update/delete for one table but you can not connect a trigger to more than one table.




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签