-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate Records in Table SQL.txt
More file actions
48 lines (41 loc) · 2.41 KB
/
Update Records in Table SQL.txt
File metadata and controls
48 lines (41 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Update Records in Table.
The Update statement is used existing records in a table.
syntax: UPDATE table_name SET column1 = value1, column2=value2 WHERE some_column = some_value;
ex: UPDATE student_reg SET name ='RAM',fees=100000.23 WHERE s_id =101;
mysql> select * from student_reg;
+------+---------+---------+------------+-----------+------+
| s_id | name | address | dob | fees | id |
+------+---------+---------+------------+-----------+------+
| 101 | RAM | KTM | 1998-12-15 | 100000.23 | NULL |
| 102 | SITA | KTM | 2001-10-11 | 200000.12 | NULL |
| 103 | HARI | PKR | 2001-01-12 | 10000.52 | NULL |
| 104 | BIMAl | KTM | NULL | 1001.23 | NULL |
| 105 | KAMAL | PKR | 1956-12-12 | 100000.12 | NULL |
| 106 | SITA KC | PKR | 1998-02-02 | 20000.12 | NULL |
+------+---------+---------+------------+-----------+------+
// example 2nd file data
ex:UPDATE student_reg SET name ='RAM',id=1001 WHERE s_id =101;
mysql> select * from student_reg;
+------+---------+---------+------------+-----------+------+
| s_id | name | address | dob | fees | id |
+------+---------+---------+------------+-----------+------+
| 101 | RAM | KTM | 1998-12-15 | 100000.23 | 1001 |
| 102 | SITA | KTM | 2001-10-11 | 200000.12 | NULL |
| 103 | HARI | PKR | 2001-01-12 | 10000.52 | NULL |
| 104 | BIMAl | KTM | NULL | 1001.23 | NULL |
| 105 | KAMAL | PKR | 1956-12-12 | 100000.12 | NULL |
| 106 | SITA KC | PKR | 1998-02-02 | 20000.12 | NULL |
+------+---------+---------+------------+-----------+------+
Ex: UPDATE student_reg SET fees = 100200 WHERE s_id = 104;
Output:select * from student_reg;
+------+---------+---------+------------+-----------+------+
| s_id | name | address | dob | fees | id |
+------+---------+---------+------------+-----------+------+
| 101 | RAM | KTM | 1998-12-15 | 100000.23 | 1001 |
| 102 | SITA | KTM | 2001-10-11 | 200000.12 | NULL |
| 103 | HARI | PKR | 2001-01-12 | 10000.52 | NULL |
| 104 | BIMAl | KTM | NULL | 100200.00 | NULL |
| 105 | KAMAL | PKR | 1956-12-12 | 100000.12 | NULL |
| 106 | SITA KC | PKR | 1998-02-02 | 20000.12 | NULL |
+------+---------+---------+------------+-----------+------+
Note: WHERE is necessary otherwise all records will be replace with given value.