T4VN is an online PHP Help community that provides PHP Tutorials, PHP Examples, PHP Scripts, PHP Support
    HOME  |  HOSTING COUPON  |  TEMPLATE  |  PHP SCRIPTS  |  LINK TO US  |  LINK  |  REGISTER | CONTACT
::: Member Login :::
 Username
 Password
 
Forgot your password ?
::: PHP Tutotal :::
  PHP Basic (7)
  PHP Advanced (4)
  PHP Database (2)
  Coding Step By Step (8)
  PHP and AJAX (0)
::: PHP Example :::
  Arrays (1)
  Code Highlighters (3)
  Database Functions (12)
  Date & Time (5)
  E-Mail (6)
  Forms (5)
  Guestbooks (1)
  Logging (2)
  Miscellaneous (10)
  Password Generators (3)
  Randomizers (3)
  String Manipulation (10)
  User Authentication (6)
::: Search On T4VN :::
::: T4VN Statistics :::
  PHP Scripts : 35
  PHP Example : 67
  PHP Tutorials : 21
  PHP News : 91
  Total Coupon : 36
  Other Tutorials :
  Member : 168
  Visitor Online : 1
  Today Visit: 24
  Total Visitor : 88739
  Most Online : 25
::: Sponsored Links :::

PR 4 For This Webpage
Home Today :

Insert,Update,Delete Into A Table


In this tutorials,we will teach you some statement as insert,update,delete record in table.This tutorials written by T4VN Team.

1 - Inserting into a Table
The SQL INSERT into syntax has 2 main forms and the result of either of them is adding a new row into the database table.

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

INSERT INTO "tablename"
(first_column,...last_column)
values (first_value,...last_value);


In the example below, the column name first will match up with the value 'ken', and the column name city will match up with the value 'Hochiminh'.

insert into employee
(first, last, age, address, city)
values ('ken', 'zoki', 20, '25 Hung Vuong',
'Hochiminh');


2 - Update Statement

The SQL UPDATE clause changes the data in already existing database row(s) and usually we need to add a conditional SQL WHERE clause to our SQL UPDATE statement in order to specify which row(s) we intend to update.
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.

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.

Example :

UPDATE Customers
SET Phone = '626 321-987568',City='Ho Chi Minh'
WHERE LastName = 'Ken'


3 - Delete Statement

Sometimes we may wish to get rid of records from a table. To do so, we can use the DELETE FROM command. The syntax for this is :

DELETE FROM "table_name"
WHERE {condition}


If you skip the SQL WHERE clause when executing SQL DELETE expression, then all the data in the specified table will be deleted. The following SQL statement will delete all the data from our Customers table and we’ll end up with completely empty table:

DELETE FROM "table_name";

Example :

Let's delete this new row back out of the database:

DELETE FROM ANTIQUES
WHERE ITEM = 'Ottoman';


But if there is another row that contains 'Ottoman', that row will be deleted also. Let's delete all rows (one, in this case) that contain the specific data we added before:

DELETE FROM ANTIQUES
WHERE ITEM = 'Ottoman' AND BUYERID = 01 AND SELLERID = 21;


Author : T4VN Team.

Other Tutorials
Introduction to SQL - The SQL Language

::: Resources :::
  Links Directory
  Programming 2 3
  Webmaster 2 3
  Web Design 2 3
  Web Hosting 2 3
  Other Links 2 3
  Asian ShowBiz News
  Teach Seo For You
::: New Templates :::




::: Other Tutorials :::
 Program Design

  Powered By T4VN.NET - Version 2.0 - CopyRight © T4VN.NET 2005-2007