Re: [OT] SQL and Perl
Антон wrote:
There are (a) over 400 threads that have to be deleted entirely.
There are also (b) over 800 threads in which specific records
have to be deleted (over 2,000 such records in total).
I compiled a list of threads (a) and a list of threads (b). For each,
I wrote a Perl script that reads and stores each object's name and
number in a variable, one at a time. Threads are referred to by their
IDs assigned during their creation, and records are referred to by
their count numbers. This information could have been useful for
deleting data from the forum's database if only a delete function was
added.
You would be much better off asking this at the website of the forum
software you are using; there is probably very little anyone on this
list can do to help you. If you do not have experience with RDBMSs or
SQL, this is not an uncomplicated task you are asking about.
OK, if I understand you correctly, by "thread" you mean "a thread of
discussion in an online forum" rather than "thread" as in "a process may
have one or more threads".
The problem is, if we are speaking about SQL and any given generic DBMS
(i.e. "database"), there are not any SQL commands for dealing with
"threads" directly as an abstract concept.
Probably (hopefully!), the database will have tables. Tables will have
rows of data divided into columns. For example, there may be a table
named "Threads" which has a column named "thread_id" and maybe a column
named "thread_name".
And if by "records" you mean "messages in a thread", then the problem is
similar. In the database, records are probably not "in" a thread. There
might be, for example, a table named "Messages" which has columns
message_id, thread_id, meaning respectively the unique id of the message
and the id of the thread in which it is located.
The problem again, however, is that it could also just as easily be
nothing like what I have described. You need information about the
tables in the database, and the columns in each table.
1) What SQL commands are used for deleting threads entirely?
To delete rows from a table you would use the SQL DELETE command.
e.g: DELETE FROM Threads WHERE thread_id=5;
2) What SQL commands are used for deleting specific records in a
thread?
Again, you will use the DELETE command. If there is a table for
messages, and each message has an id ("count"?) that is unique across
all thread, it might be as simple as:
DELETE FROM Messages WHERE message_id=84834;
3) How can those commands be run from within a Perl script mentioned
above?
First you need to determine what type of database it is. This might be
something like "MySQL" or "PostgreSQL".
Then, check CPAN (cpan.org). CPAN has an entire section devoted to
database interface modules.
dircha
Reply to: