Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Testimonials Advertise Contact Us About Us Link to Us
Source Codes E-Books Downloads Jobs Web Hosting Chats

SQL Server
SQL Server Automating Administration
SQL Server Full Text Searching
SQL Server Installing
SQL Server Selecting XML Data
SQL Server XSL Stylesheets
SQL Server Stored Procedures
SQL Server XDR Schemes
SQL Server Indexed Views
SQL Server Introduction
SQL Server Data Statements
SQL Server SELECT Statement
SQL Server Modification Statements
SQL ServerTransaction Statements
SQL Server Schema Statements
SQL Server XML Introduction
SQL Server XML Templates

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
Oops
Data Ware Housing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft FrontPage
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Computer Basics
Basics of Computer


SQL Modification Statements

Previoushome Next




SQL Modification Statements


The SQL Modification Statements make changes to database data in tables and columns. There are 3 modification statements:




INSERT Statement


The INSERT Statement adds one or more rows to a table. It has two formats:

    INSERT INTO table-1 [(column-list)] VALUES (value-list)
    

and,

    INSERT INTO table-1 [(column-list)] (query-specification)
    

The first form inserts a single row into table-1 and explicitly specifies the column values for the row. The second form uses the result of query-specification to insert one or more rows into table-1. The result rows from the query are the rows added to the insert table. Note: the query cannot reference table-1.

Both forms have an optional column-list specification. Only the columns listed will be assigned values. Unlisted columns are set to null, so unlisted columns must allow nulls. The values from the VALUES Clause (first form) or the columns from the query-specification rows (second form) are assigned to the corresponding column in column-list in order.

If the optional column-list is missing, the default column list is substituted. The default column list contains all columns in table-1 in the order they were declared in CREATE TABLE, or CREATE VIEW.


VALUES Clause

The VALUES Clause in the INSERT Statement provides a set of values to place in the columns of a new row. It has the following general format:

    VALUES ( value-1 [, value-2] ... )
    

value-1 and value-2 are Literal Values or Scalar Expressions involving literals. They can also specify NULL.

The values list in the VALUES clause must match the explicit or implicit column list for INSERT in degree (number of items). They must also match the data type of corresponding column or be convertible to that data type.

 


INSERT Examples

    INSERT INTO p (pno, color) VALUES ('P4', 'Brown')
    

    Before   After
    pno descr color
    P1 Widget Blue
    P2 Widget Red
    P3 Dongle Green



    =>


    pno descr color
    P1 Widget Blue
    P2 Widget Red
    P3 Dongle Green
    P4 NULL Brown

    INSERT INTO sp
    SELECT s.sno, p.pno, 500
    FROM s, p
    WHERE p.color='Green' AND s.city='London'
    

    Before   After
    sno pno qty
    S1 P1 NULL
    S2 P1 200
    S3 P1 1000
    S3 P2 200



    =>


    sno pno qty
    S1 P1 NULL
    S2 P1 200
    S3 P1 1000
    S3 P2 200
    S2 P3 500




UPDATE Statement


The UPDATE statement modifies columns in selected table rows. It has the following general format:

    UPDATE table-1 SET set-list [WHERE predicate]
    

The optional WHERE Clause has the same format as in the SELECT Statement. See WHERE Clause. The WHERE clause chooses which table rows to update. If it is missing, all rows are in table-1 are updated.

The set-list contains assignments of new values for selected columns. See SET Clause.

The SET Clause expressions and WHERE Clause predicate can contain subqueries, but the subqueries cannot reference table-1. This prevents situations where results are dependent on the order of processing.


SET Clause

The SET Clause in the UPDATE Statement updates (assigns new value to) columns in the selected table rows. It has the following general format:

    SET column-1 = value-1 [, column-2 = value-2] ...
    

column-1 and column-2 are columns in the Update table. value-1 and value-2 are expressions that can reference columns from the update table. They also can be the keyword -- NULL, to set the column to null.

Since the assignment expressions can reference columns from the current row, the expressions are evaluated first. After the values of all Set expressions have been computed, they are then assigned to the referenced columns. This avoids results dependent on the order of processing.


UPDATE Examples

    UPDATE sp SET qty = qty + 20
    

    Before   After
    sno pno qty
    S1 P1 NULL
    S2 P1 200
    S3 P1 1000
    S3 P2 200



    =>


    sno pno qty
    S1 P1 NULL
    S2 P1 220
    S3 P1 1020
    S3 P2 220

    UPDATE s
    SET name = 'Tony', city = 'Milan'
    WHERE sno = 'S3'
    

    Before   After
    sno name city
    S1 Pierre Paris
    S2 John London
    S3 Mario Rome



    =>


    sno name city
    S1 Pierre Paris
    S2 John London
    S3 Tony Milan




DELETE Statement


The DELETE Statement removes selected rows from a table. It has the following general format:

    DELETE FROM table-1 [WHERE predicate]
    

The optional WHERE Clause has the same format as in the SELECT Statement. See WHERE Clause. The WHERE clause chooses which table rows to delete. If it is missing, all rows are in table-1 are removed.

The WHERE Clause predicate can contain subqueries, but the subqueries cannot reference table-1. This prevents situations where results are dependent on the order of processing.


DELETE Examples

    DELETE FROM sp WHERE pno = 'P1'
    

    Before   After
    sno pno qty
    S1 P1 NULL
    S2 P1 200
    S3 P1 1000
    S3 P2 200



    =>


    sno pno qty
    S3 P2 200

    DELETE FROM p WHERE pno NOT IN (SELECT pno FROM sp)
    

    Before   After
    pno descr color
    P1 Widget Blue
    P2 Widget Red
    P3 Dongle Green



    =>


    pno descr color
    P1 Widget Blue
    P2 Widget Red


 Related SQL Server Books
Professional ADO.NET 2 Programming with SQL Server 2005 Oracle and MySQL
Beginning SQL Server 2005 Programming
Beginning Transact-SQL with SQL Server 2000 and 2005
Pro SQL Server 2005
Professional ADO.NET 2 Programming with SQL Server 2005, Oracle and MySQL
More Link » »
 
 SQL Server FAQs
Why are my insert, update statements failing with the following error?
How to programmatically find out when the SQL Server service started?
How to get rid of the time part from the date returned by GETDATE function?
How to upload images or binary files into SQL Server tables?
How to run an SQL script file that is located on the disk, using T-SQL?
More Link » »
 
 SQL Server Interview Questions
What is Cascade and Restrict when we use DROP table in SQL SERVER ?
What is COMMIT & ROLLBACK statement in SQL ?
What is diffrence between OSQL and Query Analyzer ?
What is SQL whats its uses and its component ?
What is DTS in SQL Server ?
More Link » »
 
 SQL Server Articles
Buffer Managment in SQL
Data Retrieval
Data Storage in SQL
More Link » »
 
 SQL Server News
Microsoft Confirms SQL Server 2005 SP3
Microsoft Simplifies Data-Centric Development in Heterogeneous IT Environments
Virtual database storage for SQL Server: Friend or foe?
SQL Server Compact Edition FAQs
More Link » »


Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: SQL Modification Statements, SQL Server, SQL Server, SQL Server Tutorial, SQL Server tutorial pdf, history of SQL Server, SQL Server Administration, learn SQL Server


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
Oops Quiz
Data Ware Housing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizes
Oracle Quiz
MySQL Quiz
Operating System Quizes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizes
Testing Quiz
Firewalls Quiz
SAP Module Quizes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizes
Corba Quiz
Networking Quiz
Microsoft Office Quizes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft FrontPage Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizes
Financial Accounting Quiz
Managerial Accounting Quiz
Computer Basics Quizes
Basics of Computer Quiz
Copyright © 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Quick2Host | Quick2Host Mirror | Quick Site Kit | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World
Copyright © 2003-2009 Vyom Technosoft Pvt. Ltd., All Rights Reserved.