Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Script To Create Table and Trig Based on Existing

Author  Topic 

KevMull
Starting Member

11 Posts

Posted - 2007-02-21 : 12:53:08
I've got 7 existing tables which I need to make copies of as 'audit tables' plus 2 extra columns for UpdateDate and UpdateType.

Also each exsiting table will need 3 triggers for insert, update and delete.

Can all this be automated via a MS Acess form?

What I want to do is....

From a MS Access form, via a dropdown, select a table and a 'type' ('insert', 'update', 'delete') and then from these selctions generate a second table and trigger based on the selected 'type'.

I've done the form and have dropdowns for table names and type
.
I can generate a the trigger part of the script but NOT the 'CREATE TABLE' part, this is where i'm struggling.

Many Thanks

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-02-21 : 14:06:08
Creating tables on the fly is a bad idea. It is simply asking for more trouble than you can possibly imagine. I would rethink the design. Seriously.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-02-21 : 14:11:26
Not quite answering your question, but there is some stuff about suitable code for a Trigger here:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Trigger,Triggers,audit%20changes

Kristen
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-02-21 : 14:19:17
here's an app I wrote that will generate scripts for you using SMO.

it would be a simple matter to change it (source is available) to add columns dynamically if you know a little C# and SMO. however this should never be part of a runtime system. It's only meant for generating scripts from existing objects.

http://www.elsasoft.org/tools.htm


www.elsasoft.org
Go to Top of Page
   

- Advertisement -