Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete and update records in database

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to delete and update records in the database, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to delete and update records in this database. Let's take a look.

Delete record

The format used to delete records is as follows:

Db.transaction (function (tx) {

Tx.executeSql ('DELETE FROM LOGS WHERE id=1')

});

Deleting the specified data id can also be dynamic:

Db.transaction (function (tx) {

Tx.executeSql ('DELETE FROM LOGS WHERE id=?', [id])

});

Update record

The format used to update records is as follows:

Db.transaction (function (tx) {

Tx.executeSql ('UPDATE LOGS SET log=\' www.w3cschool.cc\ 'WHERE id=2')

});

Updating the specified data id can also be dynamic:

Db.transaction (function (tx) {

Tx.executeSql ('UPDATE LOGS SET log=\' www.w3cschool.cc\ 'WHERE id=?', [id])

});

Complete instance

Example

Var db = openDatabase ('mydb',' 1.0, 'Test DB', 2 * 1024 * 1024)

Var msg

Db.transaction (function (tx) {

Tx.executeSql ('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)')

Tx.executeSql ('INSERT INTO LOGS (id, log) VALUES (1, "Rookie tutorial"))

Tx.executeSql ('INSERT INTO LOGS (id, log) VALUES (2, "www.runoob.com"))

Msg ='

The data table has been created and two pieces of data have been inserted.

'

Document.querySelector ('# status') [xss_clean] = msg

});

Db.transaction (function (tx) {

Tx.executeSql ('DELETE FROM LOGS WHERE id=1')

Msg ='

Delete a record with an id of 1.

'

Document.querySelector ('# status') [xss_clean] = msg

});

Db.transaction (function (tx) {

Tx.executeSql ('UPDATE LOGS SET log=\' www.w3cschool.cc\ 'WHERE id=2')

Msg ='

Update the record with id 2.

'

Document.querySelector ('# status') [xss_clean] = msg

});

Db.transaction (function (tx) {

Tx.executeSql ('SELECT * FROM LOGS', [], function (tx, results) {

Var len = results.rows.length, I

Msg = "

Number of query records: "+ len +"

"

Document.querySelector ('# status') [xss_clean] + = msg

For (I = 0; I < len; iTunes +) {

Msg = "

"+ results.rows.item (I) .log +"

"

Document.querySelector ('# status') [xss_clean] + = msg

}

}, null)

});

This is the end of the article on "how to delete and update records in the database". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to delete and update records in the database". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report