EasyCFM.COM ColdFusion Forums / Coding Help! / how to stop from deleting last record

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: how to stop from deleting last record

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

specific
01-12-2008 @ 2:40 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

how can i make sure that if the record is last in the table, then it should not delete it from the table ...

i tried it like this:

<cfif table.recordcount LTE 0>

soory you can't delete admin records
<cfelse>
start delete query
</cfif>

cheers

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Door to Coldfusion Community Will Remain Open Till World Ends

Want a Web Portal Contact Me

randhawaz81@gmail.com

<cf_visitwebsite>

http://portal.randhawaworld.com/

</cf_visitwebsite>

louissto56
01-12-2008 @ 3:06 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1149
Joined: Jan 2007

Aaaaaggghh another specific topic!!

How do you mean last in the table? Do you mean that the last record can't be deleted?

You can do something like this:

<cfquery name="maxid">
SELECT MAX(ID) AS maximus
FROM myTable
</cfquery>

<cfquery name="recordinfo">
SELECT ID
FROM myTable
WHERE ID = [id to delete]
</cfquery>

<cfif recordinfo.id EQ maxid.maximus>
No delete for you!
<cfelse>
Delete this biatch
</cfquery>

Is that what you mean?

____________________________
My Biz List.com.au :: Feb 08

specific
01-12-2008 @ 6:39 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006


quote:


Aaaaaggghh another specific topic!!



hahahahaha, well i do learn new things by experimenting..

Anyways, the secret code this timefor me was BEEFS as aussies eat a lot????

What i am actually trying is i hav eone table  like login and i do not want to delete all records of login.. if the record is last then my query should not delete it

Hope u underdtand

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Door to Coldfusion Community Will Remain Open Till World Ends

Want a Web Portal Contact Me

randhawaz81@gmail.com

<cf_visitwebsite>

http://portal.randhawaworld.com/

</cf_visitwebsite>

megan
01-12-2008 @ 8:25 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

OK, lets rub our brain cells together and think about the problem

in your example that you tried

<cfif table.recordcount LTE 0> which means if it is less than or equal to 0 and you said you do not to get down to 0 records, so if you want it to only go down to 1 (one) record then what number would you use??? would you use 0?? no, you would use 1 (one) and also not "less than" 1 (one)

<cfif table.recordcount EQ 1>

hth ~megan

We have art so that we shall not die of reality ~ Nietzsche

CJ
01-12-2008 @ 2:25 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

it'd be a whole lot smarter to set an 'isAdmin' bit field and set it to 1 for the record(s) that you don't want deleted.

then you could simply do DELETE FROM table WHERE isAdmin = 0 (or WHERE isAdmin <> 1).

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

Teachers open the door. You enter by yourself.
—Chinese Proverb

megan
01-12-2008 @ 5:01 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 2398
Joined: Jan 2003

CJ - I agree!, but that wasn't his question ;P ~megan

We have art so that we shall not die of reality ~ Nietzsche

Sponsored By...
iOpenSoft, LLC is a Houston, Texas Advanced Technology Studio Specializing in Web Design, Web Development, iPhone App Development and Android App Development.