Ask a Question related to Coldfusion Database Access, Design and Development.
-
turtle #1
Delete record without leaving orphans
I have 2 MS access tables "links" and "linkCategory" where links get
assigned to a category for display.
I want to be able to delete a "linkCategory" record but there could be
"links" records associated with the category so I want to check if there are
any before deleting the category so that I don't leave orphan links.
Everything works when I do not query the links table but when I place a
query to find if there are any links associated with the linkCategory I get
the following error:
Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in string in query
expression 'linkCategoryID=4"'.
SQL = "select count(*) as liveLink from links where linkCategoryID=4""
Coding below (the query that is separated by blank lines is the problematic
one):
<cfif NOT IsDefined("form.deleteLinkCategory")>
<cfupdate datasource="#application.dsn#" tablename="linkCategory"
formfields="linkCategoryID, (remaining fields)......">
<cfelse>
<cfquery datasource="#application.dsn#" name="checkForLinks">
select count(*) as liveLink
from links
where linkCategoryID=#Val(linkCategoryID)#"
</cfquery>
<cfif #liveLink# is 0>
<cfquery name="DeleteLinkCategory" datasource="#application.dsn#">
delete from linkCategory
where linkCategoryID = #Val(linkCategoryID)#
</cfquery>
<cfelse>
<cfset #errorID#=2>
<cflocation url="./errorpage.cfm?#errorID#">
<cfabort>
</cfif>
</cfif>
turtle Guest
-
Not able to delete record from datagrid
hi friends, i simply want to delete record by using asp.net datagrid control for that i need to pass one cell value to my function which will... -
How do you delete a record form multiple tables
I have a dbase that has about 30 tables in it. How can I delete a record out of all of the tables without doing 30 DELETE statements? Example:... -
#25286 [Csd]: dba_delete() cant delete record when key is null
ID: 25286 User updated by: audwox at jiran dot com Reported By: audwox at jiran dot com Status: Closed Bug Type: ... -
Session variable from delete record page in PHP
I cannot pass data from delete record page to next page, though session variables works ok on other pages. I found this article... -
delete subform record
Hi, can anyone tell me the best way to delete the current record in a subform, using a command button on a mainform? I know this should be easy,... -
SafariTECH #2
Re: Delete record without leaving orphans
You cannot COUNT a wildcard, nor use wildcards in a query that contains COUNT
or other such aggregate functions.
Another option would be to create a custom view that shows related data in
both tables based on the ID - call your query against the custom View and all
data in either table should be removed.
SafariTECH Guest
-
mxstu #3
Re: Delete record without leaving orphans
>You cannot COUNT a wildcard, nor use wildcards in a query that
Glen,>contains COUNT or other such aggregate functions.
What do you mean by this? Did I miss something?
mxstu Guest
-
Dan Bracuk #4
Re: Delete record without leaving orphans
Somebody missed something, possibly me. I thought it was the double quote after the number 4.
Dan Bracuk Guest
-
mxstu #5
Re: Delete record without leaving orphans
>Somebody missed something, possibly me. I thought it was the double quote
If the double quote is in the actual code, then you're right that it might>after the number 4.
cause a problem. I got side tracked by the wildcard comment ;-)
mxstu Guest
-
The ScareCrow #6
Re: Delete record without leaving orphans
While I agree that the double quote is the problem, I just thought I would post
another solution other than having 2 queries.
delete
from linkCategory
where linkCategoryID Not In (Select linkCategoryID from links)
and linkCategoryID=#Val(linkCategoryID)#
Ken
The ScareCrow Guest
-
mxstu #7
Re: Delete record without leaving orphans
Ken,
I definitely prefer your "delete" query over the original version. It also
looks like the OP wants to return some type of status indicating the
success/failure of the delete operation. Since they are using Access I think
they may still need an additional query to get the final status of the
operation... even if it is only using something like @@ROWCOUNT.
It looks like there are a few other minor issues with the code, like a missing
query name, extra pound signs, etc.
<cfif #liveLink# is 0>
... should be ....
<cfif checkForLinks.liveLink eq 0>
.... and this .....
<cfelse>
<cfset #errorID#=2>
<cflocation url="./errorpage.cfm?#errorID#">
<cfabort>
</cfif>
...... should probably use a parameter name in the cflocation ....
<cfelse>
<cfset errorID =2>
<cflocation url="./errorpage.cfm?errorID=#errorID#">
<cfabort>
</cfif>
mxstu Guest
-
The ScareCrow #8
Re: Delete record without leaving orphans
mxstu,
Yes, I agree. But it is hard to determine what the OP wants to do from this.
I actually do not like deleting records. While the OP has only listed 2
tables being linked here, in my experience it usually involves others. Eg you
might want to keep stats on the links clicked. Then if you delete, then you
have to delete them all and thus your stats go to crap.
I prefer to have an extra column (isActive) which is a bit column. This
allows for the column to be "deleted" (made not active), but still keep all the
records.
Ken
The ScareCrow Guest
-
mxstu #9
Re: Delete record without leaving orphans
Ken,
Absolutely. Using an IsActive or IsDeleted flag is they way to go IMO too.
With "logical" deletes you never have to worry about inadvertently hosing other
database information. Although, after a few hours scrambling through backups,
frantically searching for information that was deleted, but shouldn't have
been, most people become converts too. Experience is a good teacher... bad
experience is even better ;-)
mxstu Guest



Reply With Quote

