简体   繁体   中英

How to insert and update multiple rows at the same time in JS?

I have a table which contains say X rows and 10 columns. User has an option to edit any of the rows and columns and also he can add new rows and add details to it. He has a single button 'Save' and check box upon every row. He can select the rows which he has edited and inserted using the check box and save it using the Save button.

Now my question is, consider the user has edited X-1 rows and inserted some 3 rows. and has selected only the edited and inserted rows. How can i insert and update at the same time when he clicks the 'Save' button.

PS: I am using Java Script and SQLj.

A SQL query can have multiple queries usually divided by a semicolon (;).

INSERT INTO table_name VALUES (value1, valu2, value3); UPDATE table_name SET column1=value, column2=value2 WHERE some_column=some_value

This is in fact the answer to your question, assuming that you know how to get all edited fields from your table, and make a bunch of queries from that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM