Reputation: 109
I have 3 statements that i want to combine into one; Just so i can learn is there anyway of doing it?
Insert
INSERT INTO plants (name, latin_name, type, stock, price, flower_colour, foilage_colour, features, sun_exposure, soil_type, hardiness, competance, height, spread, description, flowering_season)
VALUES
(dandelion, `Taraxacum officinale`, weed, 12, 1.99, white, green, flower, `full sun`, alkaline, `annual hardy`, low, 12cm, 7cm, d, summer)
Update
UPDATE plants SET flower_colour='white', soil_type='clay', height='15cm', spread='4cm', description='Weed' AND price='£1.99'
Delete
DELETE FROM plants WHERE name='dandelion' AND type='weed'
Upvotes: 1
Views: 110
Reputation: 71565
The first question I would ask is "Why would you want to do this"? Given your example, you insert, change and then delete an entry. Unless there's hidden logic such as triggers updating other elements of the data, the state of the data layer won't change as a result of these three commands executing.
Also, your UPDATE statement is not syntactically correct; AND
can only be used in a WHERE
or HAVING
clause, so I think there's something you mistakenly omitted there.
There really isn't any way to combine inserting, updating and deleting into one single command. You can usually send all three commands as one "script" from whatever code layer you are using, or encapsulate these SQL commands into a stored procedure and execute that, but each statement does something very different to the underlying data, which is why they're different commands to begin with.
Upvotes: 1