VisualBuilder
  Home > Database > Tutorials > SQL UPDATE - SQL tutorial
Tell a friend
Link to us
Total Members
      Members: 84648
     
Sitemap Forum Chat
Home
SQL Tutorial Tutorial Home
1 . History of SQL
2 . SQL Components: An Overview
3 . Data Types in SQL
4 . Planning a Database: An Example: -
5 . Creating Tables
6 . Inserting Data using Insert
7 . Getting Data with Select Statement
8 . Working with Operators
9 . Selecting Unique rows with Distinct
10 . Arraging Data with Order by
11 . Working with Strings
12 . SQL AND
13 . Basic SQL Funtion
14 . Sub-Queries, Nested Queries
15 . Constraints in the Table
16 . SQL UPDATE
17 . View
18 . Relationships in a RDBMS
19 . Structure Modification,Updation and Deletion
 
Database Group Home
Database Discussion
Database Members (506)
Database Resources
Database Source Code (0)
Database Articles (0)
Database Blogs
Database Jobs
Database Components (0)
Database Books
Database Websites (0)
Database News (0)
Database Q & A (14)
- Database Ask Question
- Database Questions
- Database Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
LINQ
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Grails Tutorial
Hibernate Tutorial
Java 1.6 Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Service-Oriented Architecture (SOA) Tutorial For Managers
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (436 )
Source Code (3275 )
Articles (11 )
Components (1589 )
News (888 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Database sql Tutorial
 SQL UPDATE
  << Prev: Constraints in the Table Next: View >>

The SQL UPDATE command is used to modify data stored in database tables. If you want to update the email of one of the users in our Users table, you’ll use a SQL statement like the one below:


UPDATE Users


SET Email = 'new_email_goes_here@yahoo.com'


WHERE Email = 'sgrant@sgrantemail.com';


Let’s examine the statement above. The first row has the keyword UPDATE followed by the name of the table we are updating. The second row is the row that defines the changes made to the database fields using the keyword SET followed by the column name, equal sign and the new value for this column. You can have more than one assignment of new value after the SET keyword,


for example if you want to update both the email and the city you will use the SQL statement below:


UPDATE Users


SET Email = 'new_email_goes_here@yahoo.com', City = 'San Francisco'


WHERE Email = 'sgrant@sgrantemail.com'


The third line is our WHERE clause, which specifies which record(s) to update. In our case it says to update the Email filed of the row having email sgrant@sgrantemail.com.


What happens if you remove the WHERE clause and your SQL query looks like this:


UPDATE Users


SET Email = 'new_email_goes_here@yahoo.com'


The answer is that all Email entries in the Users table will be changed to new_email_goes_here@yahoo.com.


Most likely you will not want to do something like this, but you might have a case when you need to update several table rows at once.


For example if one of the company’s offices has been moved from San Francisco to Los Angeles you might want to update all users with City San Francisco to Los Angeles (we assume that the employees have moved too). To do that, use the following SQL statement:


UPDATE Users


SET City = 'Los Angeles'


WHERE City = 'San Francisco';


In both UPDATE example having WHERE clause above, I’ve changed a table field to new value, using the same field in the WHERE clause criteria. This was purely coincidental and you can update different field(s) than the one used in your WHERE criteria,


for example:


UPDATE Users


SET Email = 'new_email_goes_here@yahoo.com'


WHERE FirstName = 'Stephen' AND LastName = 'Grant'


When updating make sure that the WHERE clause criteria you have specified updates only the rows you want.


Using the example above if you didn’t have FirstName = ‘Stephen’ in your WHERE criteria, you would have updated 2 records (Susan Grant and Stephen Grant), because both these users have one and the same last name.


  << Prev: Constraints in the Table Next: View >>
Database Sql Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
optimum rewards
VoIP Internettelefonie DE
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising