Solved

Trigger

Posted on 2011-03-08
6
197 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now