Solved

Trigger

Posted on 2011-03-08
6
201 Views
Last Modified: 2012-05-11
How can I create a trigger to INSERT UNIQUE records (id and name for eg.) to Table1 from Table2 and Table3? Table structures:

Table1  
Id (varchar) PK  Name

Table2
.......  Id Name

Table3
........ Id Name

ayha
0
Comment
Question by:ayha1999
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:madgino
ID: 35069814
Are you sure you want a trigger ?
I think you should define a view instead of table 1, this should be the definition:

select id,name from table2
union
select id,name from table3

Union clause will remove duplicate rows if the same values are in both table2 and table3.

0
 
LVL 7

Author Comment

by:ayha1999
ID: 35069863
is it possible to call this view in specified time? What I am trying to do is fill unique records from two tables to one table in a specified time.

thanks

ayha
0
 
LVL 11

Expert Comment

by:madgino
ID: 35069903
The view will behave like a table and you will always have in the view the actual/present data.
So the view is not actually storing data it will always pick the correct data from the tables.
Is this what you want?
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 7

Author Comment

by:ayha1999
ID: 35069976
Even a View is ok as long as I can bind a dagrid from the View. could you please give the complete sql script?
0
 
LVL 11

Accepted Solution

by:
madgino earned 200 total points
ID: 35070603
You have attached the code for creating the view.
You can bind the datagrid to it but it won't editable, it's just for displaying data.
CREATE VIEW [dbo].[View1]
AS
SELECT   id, name FROM         dbo.Table1
union 
SELECT   id, name FROM         dbo.Table2

GO

Open in new window

0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 35083186
thanks
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question