You are viewing [info]irreverentangel's journal

Anne of Green Gables

May 2010

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829
3031     
Powered by LiveJournal.com
Anne of Green Gables

Busy learning curve this week, it seems.

Trying to pick up SQL (by the way, does anyone -happen- to know how to query all tables in a database? Cause I really sortof need to), started aiki last night (don't look at me, it was the father's idea, he said he'd pay for a month as a birthday present), have PHP to start today.

Busybusybusy.

I -need- a busy-bee icon.

Note to self.
Tags: ,

Comments

Personally, I have no idea how to do that.
But I am going to send this link to someone who does.
I use PHP all the time at work. It's fun. I can't help you with SQL, though.
Hi, [info]transversecity emailed me about this entry ...

First, what DBMS are you using? And, when you say "query all tables" do you mean "get a list of all tables" or "execute a query on each table"? The former is possible in almost every DBMS, while the latter requires much more hoop-jumping.

Hi Dossy - thanks for responding :-)

-First, what DBMS are you using? And, when you say "query all tables" do you mean "get a list of all tables" or "execute a query on each table"? The former is possible in almost every DBMS, while the latter requires much more hoop-jumping.

Looking to do the latter, but the former would be useful as well.

Forgive me for dumb questions - I can do a fair amount on the computer, but databases are somewhat new to me. DBM stands for Database Manager? We've been working with it through the Microsoft SQL Server Enterprise Manager v8.0. If that's not what you need, can you give me an idea of what specification you're looking for? The database file itself is a mdf.

Re: Hi Dossy - thanks for responding :-)

Sorry -- DBMS is the acronym for "Database Management System" -- in your case, Microsoft SQL Server.

Here's a web page that outlines a "manual" way of applying a query to all tables in the database. Here's another way that offers a programmatic approach to dynamic SQL.

Hope this helps.

Re: Hi Dossy - thanks for responding :-)

In case those two links don't really help clarify things, let me distill their essence for you:

The sysobjects table contains metadata about the objects in the database. Where type = 'U' will select user-created tables. The core of "dynamic SQL" is to put a SQL statement inside a variable then execute it. So, to select the count of rows of all tables in the database, you might do this:

DECLARE tmp_cursor CURSOR FOR
    SELECT name FROM sysobjects WHERE type = 'U'
OPEN tmp_cursor
FETCH NEXT FROM tmp_cursor INTO @tablename
WHILE (@@FETCH_STATUS <> -1)
BEGIN
    IF (@@FETCH_STATUS <> -2)
    BEGIN
        SELECT @tablename = RTRIM(@tablename)
        EXEC('SELECT ''' + @tablename + ''' = COUNT(*) FROM ' + @tablename)
        PRINT ' '
   END
   FETCH NEXT FROM tmp_cursor INTO @tablename
END
CLOSE tmp_cursor
DEALLOCATE tmp_cursor

Of course, this approach means having to learn Transact-SQL (aka T-SQL) which is probably not where you want to start, as a newbie. It's likely to be orders of magnitude easier to do this in a higher-level language (like PHP) -- get the list of table names using a query against sysobjects then iterate over that list using foreach or something in PHP, executing the query you want against each table.