Hi everyone,
I have two tables one for 'users' information and one for their 'profiles'.
After a user fills his registration and profile information form, I would
like to insert those information into the previously mentioned tables and
keep the relation between the records.
Ex.
Table 1. 'users'
Col 1. ID INT Autoincrement
Col 2. UserName
Col 3. Password
Table 2. 'profiles'
Col 1. ID
Col 2. Age
Col 3. Gender
What is the most efficient way to accomplish this task?
Thanks in advance. 5 1517
Will wrote: Table 1. 'users' Col 1. ID INT Autoincrement Col 2. UserName Col 3. Password
Table 2. 'profiles' Col 1. ID Col 2. Age Col 3. Gender
What is the most efficient way to accomplish this task?
LAST_INSERT_ID( )
See this page for more info and examples: http://dev.mysql.com/doc/mysql/en/Ge...unique_ID.html
Few pointers:
- I recommend to write all table and column names with lower case,
because some operating systems are case sensitive and others are not.
And this can cause problems at some point when moving to another platform.
- You propably just gave a simplified example, but with that table
structure, I would recommend using only one table, where id, username,
password, age and gender are. This will make the queries faster and the
database will be more simple to understand and use.
Note that the above won't work if each user can have multiple profiles.
But if each user have only one profile, that is propably the smartest
thing to do.
Thanks Aggro for your quick response.
I knew about LAST_INSERT_ID( ), but I was wondering if there is a better,
safer way or some type of syntax that I don't know about.
Thanks again.
"Aggro" <sp**********@y ahoo.com> wrote in message
news:Mr******** *******@read3.i net.fi... Will wrote:
Table 1. 'users' Col 1. ID INT Autoincrement Col 2. UserName Col 3. Password
Table 2. 'profiles' Col 1. ID Col 2. Age Col 3. Gender
What is the most efficient way to accomplish this task?
LAST_INSERT_ID( ) See this page for more info and examples: http://dev.mysql.com/doc/mysql/en/Ge...unique_ID.html
Few pointers: - I recommend to write all table and column names with lower case, because some operating systems are case sensitive and others are not. And this can cause problems at some point when moving to another platform. - You propably just gave a simplified example, but with that table structure, I would recommend using only one table, where id, username, password, age and gender are. This will make the queries faster and the database will be more simple to understand and use.
Note that the above won't work if each user can have multiple profiles. But if each user have only one profile, that is propably the smartest thing to do.
Will wrote: I knew about LAST_INSERT_ID( ), but I was wondering if there is a better, safer way or some type of syntax that I don't know about.
Not really.
But what do you mean about safer?
FYI the return value from LAST_INSERT_ID( ) is not mixed between
different connections to MySQL server. So even if you run a webserver
with thousands of clients inserting rows simultaneously, you can still
safely use that, and you don't even have to lock tables for that (unless
your logic needs it for other reasons).
I apologize for the late reply.
I meant by safer is I'm worrying that the second insert may fail and ends
with a raw in the 'users' table that doesn't correspond to a raw in the
'profiles' table.
Thanks a lot for the follow-up.
"Aggro" <sp**********@y ahoo.com> wrote in message
news:UN******** *******@read3.i net.fi... Will wrote:
I knew about LAST_INSERT_ID( ), but I was wondering if there is a better, safer way or some type of syntax that I don't know about.
Not really.
But what do you mean about safer?
FYI the return value from LAST_INSERT_ID( ) is not mixed between different connections to MySQL server. So even if you run a webserver with thousands of clients inserting rows simultaneously, you can still safely use that, and you don't even have to lock tables for that (unless your logic needs it for other reasons).
Will wrote: I meant by safer is I'm worrying that the second insert may fail and ends with a raw in the 'users' table that doesn't correspond to a raw in the 'profiles' table.
Why would the second fail? If you validate the data before you try
inserting it into table, it is very unlikely that it will happen.
But of course, you should validate the data also when you load it from
the database. If you don't have profile for some user, you should
perhaps just delete it and give user an error message asking him to try
to create the account again. You need to do this anyway, because it is
always possible that for some reason all or some of the rows are deleted
from the profiles table. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marko Poutiainen |
last post by:
Situation:
We had to make our SQLServer 2000 database multi-lingual. That is, certain
things (such as product names) in the database should be shown in the
language the user is using (Finnish, Swedish or English). There are about
a dozen tables with columns that need localization.
Doing this in the application level was a no-goer. It would have taken far
too much time (there is a *lot* of code and unfortunately most of the...
|
by: Greg Ofiesh |
last post by:
Anyone who can help,
I have two tables T1 and T2. T1 has fields K1 and F2 and T2 has fields
K2 and F1. F1 is the foreign key relating to K1 and F2 is the foreign
key relating to K2.
My initial question has been how can I add a row to both tables with
accurate Fx values in one SQL INSERT statement? I have been told it
cannot be done.
|
by: Joachim Klassen |
last post by:
Hi all,
first apologies if this question looks the same as another one I recently
posted - its a different thing but for the same szenario:-).
We are having performance problems when inserting/deleting rows from a large
table.
My scenario:
Table (lets call it FACT1) with 1000 million rows distributed on 12
|
by: Tom Dauria |
last post by:
What I am trying to do is write a resume into a word document from
information in an Access database. I have been using bookmarks and
inserting table results into the document and so far it's working but
I have run into a problem.
The final section of the resume deals with Experience which is
subgrouped by Market Segments and then experience.
What I want it to look like is
|
by: a |
last post by:
NEW Post
Here's my best guess at how to insert this dataset....
the code runs, but no new records are added to the sql table.
I've read and split a delimited text file into a dataset.
It looks fine in a datagrid (5 columns and 5,000 rows),
but I've been trying, without success, to then insert
the resulting dataset called "result" into a single sql
table that has an auto-increment and PK column called ID,
| |
by: aniket_sp |
last post by:
i am using a data adapter and a dataset for filling and retrieving data
into .mdb database.
following is the code.....
for the form load event
Dim dc(0) As DataColumn
Try
If OleDbConnection1.State = ConnectionState.Closed Then
OleDbConnection1.Open()
Else
|
by: c676228 |
last post by:
Hi everyone,
I am just wodering in asp program, if there is anybody writing store
procedure for inserting data into database since there are so many parameters
need to be passed into store procedure(assume there are many columns in the
table).
I need to insert data into two separate tables, the relation between these
two tables is 1 row of data in table1 could have multiple rows in table2
related to table1, but if the data insertion into...
|
by: gp |
last post by:
I am and have been using PDO for about a year now...and have finally
gotten around to solving the "DB NULL value" issues I ran into early
on...
I am looking for suggestions and techniques to deal with inserting DB
NULL values into my MySQL 5.x DB Tables....I am running PHP 5.2.x on BSD
6.x with Apache 2.2.x....
As mentioned I am writing all my web apps using the PDO extension to
connect and operate on the database. I realized early...
|
by: toyin |
last post by:
hello, pls help look through this code its not inserting the record in dataset into the another database.
i want to insert the row in the dataset into another table in another database.
pls help. it urgent i submit this application. when it runs it gives: this OdbcTransaction has completed,it no longer usable.
thx
toyin
here is the code
Sub ProcessAllSynchOperations()
Dim sSourceURL, sWebSiteIP As String
Dim...
|
by: AlexanderDeLarge |
last post by:
Hi!
I got a problem that's driving me crazy and I'm desperately in need of help.
I'll explain my scenario:
I'm doing a database driven site for a band, I got these tables for their discography section:
Discography
---------------------
DiscID
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |