Reputation: 97
I need to update 3 fields in a mySQL database table programmaticaly. I need to update label_id, label & company_id
What I need is an SQL query that allows me to indicate what the company_id
is and the "label" fields and then have it generate the label ids automatically.
For example, create label="test"
, company_id="17"
......and have it automatically generate the label_id. Any ideas on an sql query to do this? Table structure example:
label_id label company_id
1 Cook 8
2 Chef 8
3 Driver 9
Upvotes: 0
Views: 289
Reputation: 22572
If you're needing the label_id
to be generated automatically, it sounds like you're talking about an INSERT
rather than an actual UPDATE
INSERT INTO table_name(label, company_id) VALUES ("Company", 5)
This would require your table to be created, such as:
CREATE table_name (label_id int PRIMARY KEY AUTO_INCREMENT, label VARCHAR(255), company_id INT)
Upvotes: 2