Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Trigger

Posted on 2011-03-08
6
200 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

839 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