Solved

Trigger

Posted on 2011-03-08
6
198 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

920 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

14 Experts available now in Live!

Get 1:1 Help Now