SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete if exists
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Madhavi.extarc
Starting Member

India
7 Posts

Posted - 04/25/2014 :  09:39:44  Show Profile  Reply with Quote
ACADEMIC_YEAR COURSE_REFERENCE TERM
------------- ---------------- --------
2014 -1465586182 TERM4
2014 -772484485 TERM4

With the above data, user must check and delete the row only if exist

I have query some thing like this:

DELETE FROM epas_publish_course where COURSE_REFERENCE IN ( SELECT * FROM (SELECT COURSE_REFERENCE FROM epas_publish_course WHERE COURSE_REFERENCE) AS X) ;

which deleting the complete table but i need to delete one particular row...


Madhavi

chbala85
Starting Member

49 Posts

Posted - 04/25/2014 :  09:47:29  Show Profile  Reply with Quote
Hi,

Please send more explanation.


Thanks,

krishna
Go to Top of Page

Madhavi.extarc
Starting Member

India
7 Posts

Posted - 04/25/2014 :  09:50:50  Show Profile  Reply with Quote
from the above data for example if i want to delete the row with course ref -1465586182, one must check if the id exist in the table and delete the row

Madhavi
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/25/2014 :  10:48:56  Show Profile  Reply with Quote
Why do you need to check for the existence of the row first? Is this for a class or something?

There is no need to check, just delete. If you want to do something if no row is deleted, then you can check the @@ROWCOUNT and do something.
DELETE 
	epas_publish_course 
where 
	COURSE_REFERENCE = -1465586182
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000