Re: [PHP-DB] inserting same data into multiple tables question (?)
Hi, John W. Holmes wrote: From: "JeRRy" <[EMAIL PROTECTED]> I want to input the same data into multiple tables in one query if possible. It's not. You really have to question your database schema if you need to do this. Yeah, I agree w/ John -- you probably want to examine your database schema if you think you need to do that. If you are building a really complex application that really does require a whole bunch of inserts for adding a user, then you should probably consider using TRIGGERS -- and a database that supports them (e.g. PostgreSQL). http://www.postgresql.org/docs/7.4/interactive/plpgsql-trigger.html You would do something like (in Postgres): CREATE FUNCTION do_other_inserts RETURNS trigger AS ' BEGIN INSERT INTO table2 (username) VALUES (NEW.username); INSERT INTO table3 (username) VALEUS (NEW.username); END; ' LANGUAGE plpgsql; CREATE TRIGGER other_inserts AFTER INSERT ON table1 FOR EACH ROW EXECUTE PROCEDURE do_other_inserts(); Of course you'll probably want to also add triggers to handle deleting and updating users. The better/faster solution would be to use integer (user_id rather than username) foreign keys and specify ON UPDATE CASCADE and ON DELETE CASCADE so that the updates and deletes would propogate automatically. You'd probably still need an INSERT trigger, though, if you have related rows which must be added. I'm assuming that since you asked whether you can INSERT into multiple tables, that this is probably sounding a little overwhelming. I encourage you to spend some time to figure this stuff out now, though, because it will only become a nightmare when you actually have production data & you realize that your data model is inefficient & unscalable. Hans -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] inserting same data into multiple tables question (?)
From: "JeRRy" <[EMAIL PROTECTED]> > I want to input the same data into multiple tables in > one query if possible. It's not. You really have to question your database schema if you need to do this. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] inserting same data into multiple tables question (?)
You can't with standard SQL, nor with MySQL. _ - Original Message - From: "JeRRy" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, April 30, 2004 3:04 PM Subject: [PHP-DB] inserting same data into multiple tables question (?) > > > > Hi, > > I want to input the same data into multiple tables in > one query if possible. > > So what I want to do is input about 6 usernames I have > into about 15 tables. > > How would I do this? In one query? I really don't > want to run multiple queries over 15 times to put in > the data in each table. Would this work? > > INSERT into tbl1 , tbl2 , tbl3 ... ? > > J > > > Find local movie times and trailers on Yahoo! Movies. > http://au.movies.yahoo.com > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] inserting same data into multiple tables question (?)
Hi, I want to input the same data into multiple tables in one query if possible. So what I want to do is input about 6 usernames I have into about 15 tables. How would I do this? In one query? I really don't want to run multiple queries over 15 times to put in the data in each table. Would this work? INSERT into tbl1 , tbl2 , tbl3 ... ? J Find local movie times and trailers on Yahoo! Movies. http://au.movies.yahoo.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php