Solved

Trigger

Posted on 2011-03-08
6
202 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
[X]
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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

724 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