Hosting gratis - Working with MySQL SQL 48 UPDATE [LOW_PRIORITY] [IGNORE]

Working with MySQL SQL 48 UPDATE [LOW_PRIORITY] [IGNORE] tbl_name SET col_name1=expr1 [, col_name2=expr2, …] [WHERE where_definition] [LIMIT #] If you have a user who changes his or her password, you can use the UPDATE command to make the change in the database. Consider the following SELECT, UPDATE, SELECT combination: mysql> SELECT * FROM acc WHERE username=’jime’; +———+———-+———-+—————-+ | acc_id | username | password | ts | +———+———-+———-+—————-+ | 1034034 | jime | NULL | 20021014165845 | +———+———-+———-+—————-+ 1 row in set (0.00 sec) mysql> UPDATE acc SET password=’ime’ WHERE username=’jime’; Query OK, 1 rows affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM acc WHERE username=’jime’; +———+———-+———-+—————-+ | acc_id | username | password | ts | +———+———-+———-+—————-+ | 1034034 | jime | ime | 20021014204947 | +———+———-+———-+—————-+ 1 row in set (0.00 sec) In this combination of SQL commands, we display the row where the username is jime. The password is shown to be NULL. We use the UPDATE command to change the password to ime. Notice that the UPDATE command instructs a specific table to be updated; then the column that needs to be changed is indicated by SET. If we have to change numerous columns, we can use multiple SETs and separate them by commas. Finally, we can use a condition to limit the rows changed. The last SELECT command shows that the row was updated correctly. The second way to update a database is to never change a row in the database but instead to inactivate one row and insert a new one. In order to do this type of update, you must include two timestamp fields in each row. The first is called an active timestamp, and the second is just the timestamp. The most active row in the database for a particular key has a timestamp of 0. The active timestamp will be the time when the row was inserted. Once the row is inserted, the active timestamp of the current row is copied to the timestamp (ts field) of the inactive row.

Hint: This post is supported by Gama web hosting php services

Comments are closed.