我该如何编写触发器 [英] How do I write a trigger for

查看:145
本文介绍了我该如何编写触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,如果我修改了表,就像我插入新列时,当我为现有表添加新主键时,修改也将存储在审计表中我怎么能这样做iam面对这个问题可以有人说答案请



我的尝试:



在我的数据库中,如果我修改了表就像当我插入新列时,当我为现有表添加新主键时,修改也将存储在审计表中我怎么能这样做iam面对这个问题可以任何人说答案请我没有得到结果

In my database if i modified table like when i inserted new columns and when i add new primary key for existing table that modifications also will be stored in audit table how can i do that iam facing this problem can anybody say the answer please

What I have tried:

In my database if i modified table like when i inserted new columns and when i add new primary key for existing table that modifications also will be stored in audit table how can i do that iam facing this problem can anybody say the answer please i did'nt get the result

推荐答案

你要找的是 DDL 触发器:

DDL触发器| Microsoft Docs [ ^ ]

在SQL Server 2005中使用DDL触发器捕获架构更改 [ ^ ]

SQL Server DDL触发器以跟踪所有数据库更改 [ ^ ]
What you're looking for is a DDL trigger:
DDL Triggers | Microsoft Docs[^]
Using DDL Triggers in SQL Server 2005 to Capture Schema Changes[^]
SQL Server DDL Triggers to Track All Database Changes[^]


Google是你的朋友:好看并经常拜访他。他可以比在这里发布问题更快地回答问题...



一次非常快速的搜索提供超过1200万次点击:TRIGGER sql - Google搜索 [ ^ ]

这是google发现的官方文档: CREATE TRIGGER(Transact-SQL)| Microsoft Docs [ ^ ]

这里有几篇关于CP google的文章:

触发器 - SQL Server [ ^ ]

SQL Server数据库触发器概述 [ ^ ]

在SQL Server 2000中实现触发器 [ ^ ]

非常小心当您编写SQL触发器时​​ [ ^ ]

这个网站上有几千个关于这个主题的文章!



将来,请尝试自己做至少基础研究,不要浪费你的时间或我们的时间。
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search gave over 12 million hits: TRIGGER sql - Google Search[^]
Here's the official documentation that google found: CREATE TRIGGER (Transact-SQL) | Microsoft Docs[^]
Here are a couple of articles on CP google found:
Triggers -- SQL Server[^]
Overview of SQL Server database Triggers[^]
Implementing Triggers in SQL Server 2000[^]
Be Very Careful When You Write SQL Trigger[^]
Are are several thousand other articles on the subject just on this site!

In future, please try to do at least basic research yourself, and not waste your time or ours.


也许你可以使用 INFORMATION_SCHEMA.COLUMNS ,触发监视新列的触发器。

更多信息: INFORMATION_SCHEMA .COLUMNS [ ^ ]

另外 COLUMNS_UPDATED 可能有用,请看这里:COLUMNS_UPDATED(Transact-SQL)| Microsoft Docs [ ^ ]
Maybe you can use INFORMATION_SCHEMA.COLUMNS, put a trigger on that which monitors new columns.
More info here: INFORMATION_SCHEMA.COLUMNS[^]
Also COLUMNS_UPDATED might be usefull, see here: COLUMNS_UPDATED (Transact-SQL) | Microsoft Docs[^]


这篇关于我该如何编写触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆