Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Inserting Values Into A Mapping Table


I am using a mapping table with two primary keys (ID1, ID2). When I try to insert data into this table I get the following error:
Quote:

Violation of PRIMARY KEY constraint 'PK_myTable'. Cannot insert duplicate key in object 'dbo.myTable'. The statement has been terminated.

I am able however to insert values if I do it directly into my table.
Here is an excerpt of my

comm = New SqlCommand( _
"INSERT INTO myTable (ID1, ID2) " & _
"VALUES (@ID1, @ID2)", conn)
' Add command parameters
comm.Parameters.Add("@ID1", System.Data.SqlDbType.Int)
comm.Parameters("@ID1").Value = ID1List.SelectedItem.Value
comm.Parameters.Add("@ID2", System.Data.SqlDbType.Int)
comm.Parameters("@ID2").Value = ID2List.SelectedItem.Value




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
INSERTing Into A Table, With Values From Another Table
I'm programming a shopping cart application, where the products are categorized into different lines. I have a table that defines the different product lines, and now want to populate the product table.

However, the text file with the products in it, which I will use to populate the products table, uses the line NAME for each product, when I wish to use the line ID instead. To get the line ID, I would need to get the value from the line table.

My question is: is it possible to populate the products table with data from the products text file, as well as a column from the lines table?

That is, the INSERT (or LOAD DATA) statement will insert column values from the text file, but the line id from the lines table instead of the line name found in the file (WHERE line name = line name in the lines table).

I'm still not sure whether to use an INSERT, and write PHP code to go through the text file, or to use LOAD DATA for this task, because I don't know which statement would support what I'm looking for.



Inserting Values From 1 Table Into Another Table
I have 2 tables: A and B
Table A contains fields u, x and y
Table B contains fields u and z

Table A has all possible variations of u.
Table B has some of the varaiations of u in it.

My problem is that I'm trying to insert the z-values from Table B into Table A's y field and link them up based on the u-values.

I'm running into problems like truncating at row 0.

I've tried the following queries:

update TableA set y =(select TableB.z from TableB where TableA.u=TableB.u)

update TableA,TableB set TableA.y =(select TableB.z from TableB where TableA.u=TableB.u)

Updating A Mapping Table
I have a Publications table and a Themes table. There is also a mapping table for these tables as well.

When I input new records into Publications, my mapping does not get updated. When I delete, then the mapping table will get updated. (This is MySQL 4.x, so no trigger statements.)

My fear is that as I use the mapping table to display some information on a Web page, I will need to update that table "by hand" after I've entered a new record for Publications. Is there some method that I don't know of that will update my mapping table whenever I put in new records into Publications (esp. via a Web form)?

This is the setup for the mapping table: it has foreign keys on the primary key (ID) column of both Publications and Themes. That's it, nothing else in there.

Graphical Database/table Mapping
is there any application that can graphically map the relationship of tables? or probably create tables with a "graphical" UI? stupid question?

Use A Mapping Table To Get Query Results From Several Tables
Ok, so I have 4 tables...

Projects -> id, project_name, project_type
Variables -> id, variable_name
Symbols -> id, symbol_name
Mapped -> project_id, variable_id, symbol_id

if I had to find

(project_id=5, variable_id=2, symbol_id=3) AND
(project_id=2, variable_id=14, symbol_id=1) AND
(project_id=34, variable_id=78, symbol_id=44)

How could I write a query that would return the results for these all at once?

I would like project_name, project_type, variable_name and symbol_name returned from their respective tables for each. Is that possible? I've been looking at inner joins and managed to make it work for 2 ids but not 3

Use A Mapping Table To Get Query Results From Several Tables
Hi all,

Ok, so I have 4 tables...

Projects -> id, project_name, project_type
Variables -> id, variable_name
Symbols -> id, symbol_name
Mapped -> project_id, variable_id, symbol_id

if I had to find

(project_id=5, variable_id=2, symbol_id=3) AND
(project_id=2, variable_id=14, symbol_id=1) AND
(project_id=34, variable_id=78, symbol_id=44)

How could I write a query that would return the results for these all at once?

I would like project_name, project_type, variable_name and symbol_name returned from their respective tables for each. Is that possible? I've been looking at inner joins and managed to make it work for 2 ids but not 3 ....

Inserting Values
I need a big database only 2 table. i have been able to do the tables and all not problem. I can add and delete no problem. One of my problem is I do not want duplicate entries for one field. The problem is because database is so big and the entries have duplicats i have to add them in 1 batch or I will be adding then one by one forever. Is there a way around this?

Second I have an entry like below

INSERT INTO `table` VALUES ('2005.02.13 19:06:35', '853edbd1c9fdbcf0a9ff5cbf5e347267', 'sajdhs'dhs');

Second I cannot put the above in mysql unless as it throws and error becuase of the ' used in thrid entry. I need these entries to go in as they are.

Inserting Hexadecimal Values
I am attempting to insert data into a field of CHAR(16). The data is hexadecimal ie. x'24te48we123456788765432112345678' I have not been able due to syntax errors. Keeps telling me the "data is too long". Does not seem to recognise that it is a hex.

Inserting Lots Of Mysql Values At Once
I have about 100 items i want to insert into a mysql database, how can i go about doing this quickly?

Inserting Multiple Values In One Column
I have a web form that has a drop down list where you can select more than one item. I'd like both of these values to be entered into the same column in a table. For example, the table is set out as follows

TAG_TABLE
tag_id
user_id
software_id

all of the above are integers whose value is referenced in another table.

eg the software_id table is as follows

SOFTWARE_TABLE
software_id
software

The dropdown list in the form is populated from the software table. What happens is that when I select an item from the drop down list say Microsoft Visio it enters the corresponding integer in the main table. But if I select Microsoft Visio and Micrsoft Project, I want both of those integers to somehow be added into the user_id column in the TAG_TABLE.

I also have a web based reports form .....

Update Values On Inserting Duplicate Index
I am very new to mysql. I have a question about using the "on duplicate
update" clause with insert command.

my table "data" has two columns, field1 and field2, where field1 is the
index and is "unique".

when I run

insert ignore into `data` ( `field1`,`field2`)
values
(1,2)
(2,6)
(2,9)
(5,1)

I got
1,2
2,6
5,1

because the third value pair, (2,9) was ignored due to duplication in
field1.

here is what I want to do: when inserting new record with duplicate
index, I want the existing record gets updated. in the above case, I
want the output look like the following after the insert command:
1,2
2,9
5,1
after searching mysql online document, I only found the "on duplicate
update" clause can do something similar, however, all the examples only
show setting the duplicate record to somthing unrelated to the new
values.

Inserting Money (Dollar Amount) Values
I'm having a problem inserting money (dollar amount) values into a MySQL 5.0 database.

I'm using a text box in a ColdFusion web form that allows users to enter the dollar amount for sales. For example, they can enter 1,000.00 for a thousand dollar sale. Everything seems to work fine until the user enters any value that has a comma such as 1,000.00 or 150,000.00 or 1,000,000.00, etc...

I've tried using different data types within the database for this column. I've tried Int, BigInt, and Decimal (10,2) but nothing likes the commas. Does anyone know how I can get around this problem?

SQL*plus Inserting New Row With Values = To Existing Rows Data
I am trying to insert a new employee into an empolyee table and get some of the values (namely phone no.) to be the same as what another employee currently has. This new employee is replacing the old employee, but i have to keep the old employee alive in the db as other data is reliant on its existance.

I was wondering how do i insert the new employee asking the, VALUE ('etc', 'etc',) line, to assign a value to certain fields equal to the value contained in other employee rows.

Inserting Multiple Items (# Unknown) Into A Table Using Primary Id From Master Table
In my database I have a master table for products using a auto-num id column. One product may have several purchase options (items) which have to be entered into another table.

To enter a new product and items I use a form that gathers the information for the master product and one item. This information is then inserted into the database. For the items I use mysql_insert_id() to get the id into the items table.

My challenge is getting this same id for additional items. Once the user has input the initial product and first item they hit a submit button to call a form for adding any additional items, and this is repeated until all items for that product are entered.

The new items are inserted into the database okay, but always with an id of 0. The mysql_insert_id() no longer works. Is there a way to pass this id from the previous insertion to the new one by passing a variable? or echoing input type"hidden"?

Or even better yet, Im wondering if I can ask the user at the time of entering information for the product how many items that particular product has and then bring up that many form fields to enter multiple items? Can this be done using something like an incremented loop to call form fields?

Inserting Into A Table From Antoher Table With A Different Structure
Say i have table A with column structure 'a','b','c','d'
and I have table B with column structure 'a','b','c'

I've tried doing an insert into A select * from B; but it says I cannot do this due to the size difference in tables.

Inserting Data From One Table To Another Table In Same Database
I have got about 80 tables (same structure/fields) from my client. I want data of all 80 tables in one single table. There are around 90 lakhs records in 80 tables. How do I get to do this ?

MyODBC Mapping
I have an VB frontend that can't be changed for various reasons, and have
been attempting to move the database (access) out to MySQL (for various
other reasons ;). I haven't been able to successfully read True/False
fields, and after much research it appears that I need to map any true/false
or yes/no to 1/0 in the MyODBC source code.

I've downloaded the source code, but I haven't been able to determine what
and how to change the mapping. Any assistance would be GREATLY appreciated!

FYI: I tried treating the MySQL side as an enum field, but the VB front end
won't accept the result.

O/R Mapping With MySQL
What i want to know from u is :
Is it possible to do this mapping just with mySQL, without using others soft like Hibernate ...., i.e Is there functions or methodes in MySQL which allows O/R mappings.

Inserting Value From One Table To Another
In my database called 'asterisk',
I have a table named 'sip'.
It has the fields:
id,keyword,data,flags -- Primarykeys:id,keyword

I have another table named 'userdata'.
It has the fields:
id(autoincrement),account,username,secret,Mobile,SIP,MSN -- PK: id

Now, in table sip, id will have values '0' for the first few records, say 13 records.
After that, it must have the value '1' for the next 3 records, value '2' for the next 3 more records and so on..
So value of id shd b incrmented by 1 every 3 records after id=0.

Now, the 3 records tat wil b entered into sip table are: Code:

Inserting Into Table
I'm having some trouble inserting variables into my database. All the variables I'm trying to insert have been declared above this part, used atleast once, so they are correct. But when I view my table, the entires are not there.

code..

The lastName string is "O'Brien." I took out the apostrophe by hardcoding in another name, but it is still not being inserted. The last empty var is for the ID which autoincrements.

Query Collation Mapping?
is it possible to query the code mapping mysql uses for different collations -- I want to review the code mapping to compare

latin1_swedish_ci
latin1_german1_ci
latin1_bin
latin1_general_cs

====
this has a nice explanation of collation mapping:

MyODBC Mapping Question
I have an VB frontend that can't be changed for various reasons, and have
been attempting to move the database (access) out to MySQL (for various
other reasons ;). I haven't been able to successfully read True/False
fields, and after much research it appears that I need to map any true/false
or yes/no to 1/0 in the MyODBC source code.

I've downloaded the source code, but I haven't been able to determine what
and how to change the mapping. Any assistance would be GREATLY appreciated!

FYI: I tried treating the MySQL side as an enum field, but the VB front end
won't accept the result.

Inserting Date Into Table
I am wanting to insert a date into a table for the date something was inputted into the database. Which would be the best (or only) way to do that?

1. DATE function in MySQL
2. date() function in PHP and submit the output into MySQL

If there are any other ways, let me know, as I would like this to be the best possible way and work all the time.

Inserting ENUM Value Into TABLE? How?
i'm trying to insert an ENUM value into table,
the field column inside a table is also set to ENUm.

$query = "INSERT INTO users (activated)
VALUES (Ƈ')";

mysql_query($query) or die('Error, insert query failed');

Inserting Data Into Table
My task is to create a table which works as a "linker" of two other tables. In this linker table as foreign keys I am using keys from this two tables.

I am inserting data into first table t1 in one loop in Perl script, then in a second loop I am inserting data into table t2 and immediately after into t3 which is a linker table between t1 and t2. I have no problems with id (primary key) from t2 , but while extracting keys from t1 there is message:

Subquery returns more than 1 row
after subquery:

insert into t3 (t1id,t2id) values ((select id from t1 where name like 'x'),(select max(t2id) from t2)); simply because value '' are present in table t1 two times so it has two keys. How this problems can be solved?

I tried to use:
insert into t3 (t1id,t2id) values ((select id from t1 where name like 'x'=ANY(select id from t1 where name like 'x')),(select max(t2id) from t2));

however then there was a message:ERROR 1048 (23000): Column 'id' cannot be null because it is t1 primary key? Are there any ways of dealing with this problem?

Inserting Records From Another Table
i am using the following SQL to insert records into Summary table from another table but i keep getting a syntax error.  When i run teh sqls individually, they work ok... any thought on how i can get this done?

INSERT INTO tSummary
(ssnumber,unitid,projectid,tenant_lname,tenant_fname)
VALUES(select ssnumber,unitid,projectid,tenant_lname, tenant_fname from tExternalData)

The error that i get follows:

[admin] ERROR 1064: You have an error in your SQL syntax near 'select ssnumber,unitid,projectid,tenant_lname, tenant_fname from tExternalData)' at line 3

Inserting Data Into A Table
insert into enrolls (section_id,total)
values(324,max(sub) +.1);

how can I make it work so the value for the total of this entry is the max of the sub column from the same table + .1?

Error Inserting Into Table
(MySQL 4.1.7 using phpMyAdmin 2.6.0-pl3)

Here's a file called info.csv:

"e-mail","Subscribe_to_Newsletter ",""
"ajak@myway.com","on",""
"anthony_knight@hotmail.com","off",""

I created a table called mail, with 2 columns (e-mail       Subscribe_to_Newsletter)

Then ran this query:

INSERT INTO mail (email, Subscribe_to_Newsletter)
VALUES ("ajak@myway.com","on",""
"anthony_knight@hotmail.com","off","");

But got this error message:

Error

SQL-query:

INSERT INTO mail( email, Subscribe_to_Newsletter )
VALUES (
"ajak@myway.com", "on", "" "anthony_knight@hotmail.com", "off", ""
)

MySQL said: Documentation
#1136 - Column count doesn't match value count at row 1.

Inserting Date In To The Table
my table structure is
temp( name varchar(10), da date);
it is only accepting dates in the format 'yyyy-mm-dd' ex: 2005-02-16
and for any other vaules it is inserting 0000-00-00.

Inserting Unicode In Table
I have created a table as follows -

CREATE TABLE verb_table (verb VARCHAR(25), briathar VARCHAR(25), conjugation VARCHAR(5), past_tense VARCHAR(25), aimsir_chaite VARCHAR(25)) TYPE=InnoDB CHARACTER SET utf8;

Now how do I insert unicode values into a database using the following format -

insert INSERT INTO MyFirstTable ("To run","rith","1","ran","rith");

How do I escape a unicode value?
For example, how do I insert a "long r" (u027c) in place of a normal r in the example above?

Are Using A Lot Of Mapping Tables A Sign Of Bad DB Design?
I find when I am conceptualizing data relationships that I find I often define mapping tables.

Here is the structure where very different choices could have been made....

Mapping Category Id's Between Tables
I have to import all available categories from a pricelist en place them in my webshop.
Now the problem: the id's in the pricelist are alphanumerical, and de id's in my webshop must be integers.

This is what my DB looks like

I've created a TABLE that holds the pricelist:
TABLE pricelist
---------
Prod_id, major_id, minor_id, sub_id
  001     AAA2005   BAC3256  GHD6254

And an extra table that holds all the category id's:
The 'shop_cat_id' is auto-increment INT(11):
TABLE categorie_mapping
-------
shop_cat_id, pricelist_cat_id
     1           AAA2005
     2           BAC3256
     3           GHD6254

And it all has to go into this table:
TABLE categories
----------
shop_cat_id, parent_id
     3           2
     2           1

Major_id is the parent of minor_id and minor_id is of course the parent of sub_id

I thought that by using TABLE categorie_mapping, i could easily convert the category id's into integers. But I'm stuck with creating the SQL to put it in TABLE categories.

Inserting Charcter String Into Table
We are trying to insert a string of characters similar to N234ND into a table. Everytime we try this we get the 1054 Error code. Stating "Unknown column 'N' in 'field list'. The N relates to the first N in N234ND.

Error Inserting Into Temporary Table
I create a temporary table by using following statement:

CREATE TEMPORARY TABLE ttable1(
id tinyint( 4 ) ,
q decimal( 5, 0 )
) TYPE = HEAP

tryng insert a record by statement:
INSERT INTO ttable1 VALUES ('1','1') return the following:
#1146 - Table 'rail.ttable1' doesn't exist

How can I insert in my temp table?

Inserting Variables In MySQL Table!
Have you guys tried inserting variables in mySQL tables? Do I have to
use 'quote' as we had been doing to insert strings?

mysql> INSERT INTO occurrence (word_id,page_id) VALUES
($word_id,$page_id);
ERROR 1054: Unknown column '$word_id' in 'field list'

Inserting A Record In Table That Has Auto_Increment
I'm trying to insert a row into a table using data from variables with values from an excel sheet. the problem I'm having is that the table I'm inserting them into has an Auto_increment field and I can't get the code right for it to work. Here is a sample of what I have: Code:

Inserting 100 Rows Of Data Into An Existing Table
I want to import 100 rows of data from an Excel spreadsheet into an existing MySQL table. Both the spreadsheet table, and the MySQL table have the same exact format & headers.

In MySQl Query Browser, I can locate only the Edit function, which seems to only allow me to type in the data line by line. Can I import the data in MySQL Query Browser, or do I need another product? And if I can import, how do I do this?

Trouble Inserting Ph Variable Containg A Number Into Sql Table
I select an id from one table to use in another so I can have them related to one nother. My code was working yesterday, now I get this error atabase error storing file: MySQL server has gone away--------and sometimes I get the database store error and my version is wrong, it points to the filename=".
Do I use single, double or no quotes when I have a variable that contains a number and want to insert that variable into MySQL?
This is part of the code if this helps:

//get member id to insert into file store table

$get_id = "SELECT DISTINCT id FROM member WHERE soc_num = '{$_SESSION['soc']}'";
$get_id_res = mysql_query($get_id) or die("Couldn't get id"); #90
$id2 = mysql_fetch_array($get_id_res, MYSQL_ASSOC) or die("Could'nt get id2");
$id2['id'] = $member_id;

// Create the SQL query.
$sql = "INSERT INTO filestore SET
member_id = $member_id,
filename = '$uploadname',
mimetype = '$uploadtype',
description = '$uploaddesc', #100
filedata = '$filedata'";

Insert Table Values From Another Table
I have two tables: Users and metadata

Users:
id
userid
username

Metadata:
id
userid
value

I would like to extract a list of the userid's from the users table and enter them into the metadata table, with an additional value.

Example:
I want to take all of the userid's from the User table and insert them into the Metadata table, and make the value="one" for each entry into the Metadata table.

Update One Table Value With Values From Another Table
I am trying to update one table value with values from another table, and I cannot get it to work. What am I doing wrong?

This is my SQL-command:
UPDATE tabel1 SET tabel1.name=tabel2.name WHERE tabel1.ID=tabel2.ID

Add Values To Table
I have a table tblMailingList. It has 3 columns; Name, EmailAdd, AutoID.

I am using
mysql> INSERT INTO pet
-> VALUES ('name1','u@me.com');

but I am unsure as to what to do for the AutoID field. If I use the example given, the error message says that the number of fields is different.
How do I get this info into my table?

INSERT Values From One Table To Another
In table A i have a.id and name and in table B, i have b.id, a.id(FK) and owns.

Table A
--------------
a.id | name |
--------------
12 | James |
13 | Paul |
14 | Tom |
15 | Andy |


Table B
--------------

b.id | a.id | owns |
--------------------
1 | 12 | Car |
2 | 12 | Bike |
3 | 13 | PC |

Now what i want is to add two new names to table A which will be Tom and Andy and have the same data in table B for Tom and Andy with just different b.id (PK).

How can i insert this new data in table B using insert?

Update A Table With Values In Another
I have the following table

tableA
column_a
column_x
column_y
column_z

tableB
column_x
column_y
column_z

How do I update the rows of tableA that match rows of tableB (all rows
of tableB are unique)

What I want to acheive is a check against tableA.column_x with
tableB.column_x, if they match, then update the row in tableA.column_y
with the value of tableB.column_y and tableA.column_z with
tableB.column_z

Edit Values In Table Through GUI
I wonder which GUI tool I can use if I want to edit some values in a table? I can't find it in Query Browser. Do I really need to execute SQL to make a simple change to a field?

Update Table Values
I have a csv.txt file with contacts and their information in it. Then I also have a table in mysql with the same contacts and their various information. I need to merge these to so that if a field value in the database is NULL the value that is in the csv.txt file is inserted into the database field.

I have been looking at the mySQL site on how to do this but have not been able to produce a working solution. Below is a more detailed example of what I am looking for. Code:

Returning Values That Are In One Table, But Not In Another
I'm looking for a query to return values which occur in one table, but not in the other.

Say we have two tables (table_1, table_2) each with a column titled "appointments".

I want a list of results for appointments which are in table_1, but not in table_2

I have tried the following, but all I get is a huge list of duplicate appointments which occur in both tables:

SELECT table_1.appointments
FROM table_1, table_2
WHERE table_1.appointments<>table_2.appointments;

I've also tried 'NOT IN' for this but the result was just the same.

Get The 3 Highest Values From A Table
My problem is to get the 3 highest values from a table

Editing Values In A Table
I just moved from SQL Server to MySQL and in the Enterprise Manager in SQL Server I could query the entire table and then modify the values with the table without writing an UPDATE statement.
I cannot do that in one of my tables because the EDIT at the bottom is greyed out. There are other tables where I can make a modification to any value I want within the table.


Copyright © 2005-08 www.BigResource.com, All rights reserved