473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

mysql: how create a temp table as a copy of a existing table?

dev
how create a temp table as a copy of a existing table and then update1 field
and insert the hole temp table back in the existing table?
please any help?

if i have 10 fields in 1 record and about 100 records and a field.status=1
in a existing_table and
i want to create a temp_table with all the recordse and values of the
existing_table and then update the field.status to 2 and insert in 1 query
the temp_table in the existing_table

Best regards,
m
Jul 17 '05 #1
6 6549
dev wrote:
how create a temp table as a copy of a existing table and then update1 field
and insert the hole temp table back in the existing table?
please any help?

if i have 10 fields in 1 record and about 100 records and a field.status=1
in a existing_table and
i want to create a temp_table with all the recordse and values of the
existing_table and then update the field.status to 2 and insert in 1 query
the temp_table in the existing_table

Best regards,
m


Apparently you have never studied anything about [relational] databases and how
they function in a multi-user environment. You obviously have a problem that
needs to be solved, but this isn't the way to do it. Explain the business
challenge that led you to believe that this was the solution.

What's wrong with:

Update existing_table set field_status = 2 where field_a = 'somevalue';

or to update all records and set the status to 2:::

update existing_table set field_status=2;

Again, what problem are you trying to solve?

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #2
me
Michael Austin wrote:

Apparently you have never studied anything about [relational] databases and
how
they function in a multi-user environment. You obviously have a problem that needs to be solved, but this isn't the way to do it. Explain the business
challenge that led you to believe that this was the solution.

What's wrong with:

Update existing_table set field_status = 2 where field_a = 'somevalue';

or to update all records and set the status to 2:::

update existing_table set field_status=2;

Again, what problem are you trying to solve?

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)


Hey Michael,

wel the problem is not so easy i must adjust (alter) a existing table
structuur and php.
First i need the old value's! because i want to insert a PREVIEW function in
the content-layer tool
so i need a copy of the existing table (also relative on demand by user
input) and set the status to 2 so that i wil use for the preview
functionalty without change the old value's in the table..

so i hope this sort explaination is enough?

anyhelp on how to duplicate a table in a temp table with all the indexes
correct?

Cheers,
Jul 17 '05 #3
me wrote:
Michael Austin wrote:

Apparently you have never studied anything about [relational] databases and
how
they function in a multi-user environment. You obviously have a problem


that
needs to be solved, but this isn't the way to do it. Explain the business
challenge that led you to believe that this was the solution.

What's wrong with:

Update existing_table set field_status = 2 where field_a = 'somevalue';

or to update all records and set the status to 2:::

update existing_table set field_status=2;

Again, what problem are you trying to solve?

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)

Hey Michael,

wel the problem is not so easy i must adjust (alter) a existing table
structuur and php.
First i need the old value's! because i want to insert a PREVIEW function in
the content-layer tool
so i need a copy of the existing table (also relative on demand by user
input) and set the status to 2 so that i wil use for the preview
functionalty without change the old value's in the table..

so i hope this sort explaination is enough?

anyhelp on how to duplicate a table in a temp table with all the indexes
correct?

Cheers,


Again, you are going to have a REAL hard problem syncronizing the tables with
this approach in a multi-user environment, especially if you try to have more
than 1 user "replacing" the "existing_table" at the same time- who wins? the
last person to overwrite it... and the changes from the other users will be lost.

In a WEB-based environment you CANNOT ever assume that this will/can never
happen, because it will and if this data is imperative to your process, you are
now hosed. What happens if your user "aborts" and goes home for the night? now
you have abandoned/orphaned temp tables that you must clean up.

Bad plan Stan!

Read ONLY the data "to be changed" into a session variable and pass it along
until you get to the end... something like _SESSION['ROW1_COL1']="abc". and then
update only the row necessary.

Sounds like you could use a (DBA) consultant to help with this... :)

Beware of programmers posing as DBA's.
Beware of programmers with screw-drivers.
Beware of programmers in the computer room.

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #4
me
Michael wrote:
"Michael Austin" <ma*****@firstdbasource.com> wrote in message
news:A%******************@newssvr23.news.prodigy.c om...
me wrote:
Michael Austin wrote:

Apparently you have never studied anything about [relational] databases and how
they function in a multi-user environment. You obviously have a problem
that
needs to be solved, but this isn't the way to do it. Explain the businesschallenge that led you to believe that this was the solution.

What's wrong with:

Update existing_table set field_status = 2 where field_a = 'somevalue';

or to update all records and set the status to 2:::

update existing_table set field_status=2;

Again, what problem are you trying to solve?

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)

Hey Michael,

wel the problem is not so easy i must adjust (alter) a existing table
structuur and php.
First i need the old value's! because i want to insert a PREVIEW function in the content-layer tool
so i need a copy of the existing table (also relative on demand by user
input) and set the status to 2 so that i wil use for the preview
functionalty without change the old value's in the table..

so i hope this sort explaination is enough?

anyhelp on how to duplicate a table in a temp table with all the indexes
correct?

Cheers,


Again, you are going to have a REAL hard problem syncronizing the tables

with this approach in a multi-user environment, especially if you try to have more than 1 user "replacing" the "existing_table" at the same time- who wins? the last person to overwrite it... and the changes from the other users will be lost.
In a WEB-based environment you CANNOT ever assume that this will/can never
happen, because it will and if this data is imperative to your process, you are now hosed. What happens if your user "aborts" and goes home for the night? now you have abandoned/orphaned temp tables that you must clean up.

Bad plan Stan!

Read ONLY the data "to be changed" into a session variable and pass it along until you get to the end... something like _SESSION['ROW1_COL1']="abc". and then update only the row necessary.

Sounds like you could use a (DBA) consultant to help with this... :)

Beware of programmers posing as DBA's.
Beware of programmers with screw-drivers.
Beware of programmers in the computer room.

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)



Hey,

wel it is only for 1 user at once! admin user..
and sessions are not logic.. it has a whole content layout of some products
i must display..
so any help on the mysql table?

Cheers and thank for your help anyway..

Jul 17 '05 #5
"dev" <NO***********************@hotmail.com> wrote in message
news:40*********************@news.xs4all.nl...
how create a temp table as a copy of a existing table and then update1 field and insert the hole temp table back in the existing table?
please any help?

if i have 10 fields in 1 record and about 100 records and a field.status=1
in a existing_table and
i want to create a temp_table with all the recordse and values of the
existing_table and then update the field.status to 2 and insert in 1 query the temp_table in the existing_table


Try this, pulled straight from the MySQL on-line manual.
=======
As of MySQL 3.23, you can create one table from another by adding a SELECT
statement at the end of the CREATE TABLE statement:
CREATE TABLE new_tbl SELECT * FROM orig_tbl;

MySQL will create new column for all elements in the SELECT.
=======

I haven't tested it myself, but it looks like what you need, followed by the
necessary UPDATE statements. I don't think it will build your indexes and
such, but if you are content with copying the whole table, you probably
don't need supporting indices.

If you're using MySQL 4.1, there is a 'CREATE TABLE new_tble LIKE old_tbl'
syntax as well. That, I think retains the characteristics of the table,
including indices.

Again, haven't tried these myself. Just exploring along with you.

- Virgil
Jul 17 '05 #6
On Fri, 23 Jul 2004 19:02:34 GMT, Virgil Green wrote:
"dev" <NO***********************@hotmail.com> wrote in message
news:40*********************@news.xs4all.nl...
how create a temp table as a copy of a existing table and then update1 field
and insert the hole temp table back in the existing table?
please any help?

<snip>
Try this, pulled straight from the MySQL on-line manual.
=======
As of MySQL 3.23, you can create one table from another by adding a SELECT
statement at the end of the CREATE TABLE statement:
CREATE TABLE new_tbl SELECT * FROM orig_tbl;

MySQL will create new column for all elements in the SELECT.
======= <snip> - Virgil


But belive the other fellow here: the point is you don't need to do that;
it is a *bad* idea.
--
Timothy Madden
Romania
------------------------------------
And I don't wanna miss a thing
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
1
by: deko | last post by:
DoCmd.CopyObject copies data, but I only need structure. I'm trying to clone several tables in my Access 2003 mdb. The goal is to link to a series of Excel spreadsheets and then run various...
1
by: no-email | last post by:
Hi, Below is a bunch of programs to demo the basic sql commands. Suggestions on possible improvements will be appreciated. <?php // mysql-demo.php include ("connectdb.php"); $setSQL="SET...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.