The Sql Update Statement
- We use the sql update statement to update datas of tables in databases
- If we don’t write conditions, the table’s all records are updated
- It’s the one of DML(Data Manupulation Language) codes
The Sql Update Syntax
1 |
Update tableName set columname=value[,columnName=value....] where conditions |
1 |
Update tableName set columname=value[,columnName=value....] |
TO DOWNLOAD THE SAMPLE LİBRARY DATABASE CLICK
The Sql Update Examples on Library Database
Sample 1: Update the student where the student_id equal to 30,new name Taylar
1 |
Update students set name='Taylar' where studentId = 30 |
Result Of The Query: 1 row(s) affected.
Sample 2: Update all student’s point to zero
1 |
Update students set point = 10 |
Result Of The Query: 505 row(s) affected.
Sample 3: Add 10 points to all Student
1 |
Update students set point += 10 |
or
1 |
Update students set point = point + 10 |
Result Of The Query: 505 row(s) affected.
Sample 4: Add 10 points to students who read ‘The Hobbit’ named book
Update students set point += 10 where studentId in (Select distinct studentId from borrows join books on borrows.bookId = books.bookId and books.name = 'Bleak House')Result Of The Query: 38 row(s) affected.