Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to Create DML Trigger

Author  Topic 

Arunraj
Starting Member

18 Posts

Posted - 2015-01-06 : 06:01:10
Hi Friends,

I need a help from you.

THe Scenario is We have Tables like parent and Child Table.

Like we have Child Table as Name AcademyContacts,In that we have Columns like

Guid(PK)Not Null,

AcademyId(FK), Not Null,

Name,Null

WorkPhone,Null

CellPhone,Null

Email Id,Null

Other.Null

Since we have given Null to ''Workphone'',''Cellphone '', ''Email ID''.when inserting the data into these table

if the particular columns are empty while inserting also the data will get populate into the table.And

I need is if these columns are ''Workphone'',''Cellphone'' , ''Email ID'' they cant insert the data into table.

Like it must trigger like ''Please enter atleast one of these ''Workphone'',''Cellphone'' , ''Email ID'' columns.

How to do this in triggers please suggests me friends !!!!

I am waiting for your response !!!

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2015-01-06 : 06:17:06
it would be better to do this in your application code

Javeed Ahmed
https://www.linkedin.com/pub/javeed-ahmed/25/5b/95
Go to Top of Page

Arunraj
Starting Member

18 Posts

Posted - 2015-01-06 : 06:33:06
Hi,
Thank yu for your reply.

I know very well we can use it in Stored Procedure as well as when we are creating a UI . But my Manager told to create a Triggers for this.Thats Y I have posted.

quote:
Originally posted by ahmeds08

it would be better to do this in your application code

Javeed Ahmed
https://www.linkedin.com/pub/javeed-ahmed/25/5b/95

Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2015-01-06 : 08:25:27
Seems a bit overkill for validation, why dont you add a check to the fields?

ALTER TABLE AcadmenyContacts
ADD CHECK (Workphone is not null)

We are the creators of our own reality!
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2015-01-06 : 08:30:47
You can suggest your manager that,for every field check your app needs to hit the database which will be a over head.
You need to avoid triggers as much as you can.


Javeed Ahmed
https://www.linkedin.com/pub/javeed-ahmed/25/5b/95
Go to Top of Page
   

- Advertisement -