I have two SQLite database query INSERT into UserAccessLevels VALUES (12,"a", 21, "bb", 21) and INSERT INTO UserPersonalInfo VALUES (17, "a","a1",2,"a2","a3") two of them are working fine separately. I am tying to combine two of them together is it possible to do for SQL Database.
2 Answers
BEGIN
INSERT INTO UserAccessLevels VALUES (12,"a", 21, "bb", 21)
INSERT INTO UserPersonalInfo VALUES (17, "a","a1",2,"a2","a3")
END
2 Comments
SQLiteManager: Likely SQL syntax error: BEGIN INSERT INTO UserAccessLevels VALUES (12,"a", 21, "bb", 21) INSERT INTO UserPersonalInfo VALUES (17, "a","a1",2,"a2","a3") END [ near "INSERT": syntax error ]Short answer: use a transaction to make sure both inserts happen as an atomic unit (the entire transaction will either succeed completely or fail completely).
If you are using SQLite, an example transaction would look something like this:
BEGIN;
INSERT INTO UserAccessLevels VALUES (12,"a", 21, "bb", 21);
INSERT INTO UserPersonalInfo VALUES (17, "a","a1",2,"a2","a3");
COMMIT;
If you are submitting a single string of all this for execution, the semicolons are critical.
If you don't actually need a transaction, or if there is one already created for you (by SQLiteManager, etc.), then simply run the INSERT statements with semicolons after each one, and you can exclude the BEGIN and COMMIT statements.
3 Comments
SQLiteManager: BEGIN; [ cannot start a transaction within a transaction ] error..........
;is used to delimter queriesINSERTusually only works on one table, although some databases do have methods for combining them into a single query.