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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need a trigger or sproc, not sure which or how
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aged Yak Warrior

651 Posts

Posted - 09/26/2013 :  10:50:39  Show Profile  Reply with Quote
Alright, probably a simple situation. In my database, i have seven tables. When a new record is added to the db, it is added to the "Servers" database. The columns in there are only three "AutoID" and INT, primary key, autonumbered. "Servers", varchar 50, "PersonAdding" Varchar 50, and "DateAdded" Datetime.

If someone adds a new record to this table, i need another table, "MainServerInfo" in the same db, to automatically receive a new record, with the same AutoID from the Servers table to go into the AutoID (the PK) in MainServerInfo, and i need the "Servers" column value for the new entry to be inserted into the Servername column for that row in MainServerInfo.

what's the best way for this to happen and, since i've never written a trigger before, how would the coding look.


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 09/26/2013 :  11:08:10  Show Profile  Reply with Quote
Would be like this:
ON dbo.ServersTable
	INSERT INTO MainServerInfo (AutoId, ServersColumn)
Don't you also need to do something if the data in the Servers table is updated or deleted?
Go to Top of Page

Aged Yak Warrior

651 Posts

Posted - 09/26/2013 :  11:21:52  Show Profile  Reply with Quote
Thanks, and no. Because in this case, the data is never deleted and the data in the servers table is never updated. All the other child tables get the updates and those updates are not dependent on each other.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000