We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 172,248 times

Contents

Related Categories

SQL Commands - Adding Records

Adding Records

To add a record to the database, you use the INSERT INTO command. First you give the name of the table, and then you list the values for the fields. For example,

INSERT INTO Users VALUES (10, 'James Crowley', 'PASSWORD')

will add a new record to the Users table, filling the fields with 10, and James Crowley. Obviously, in this case, you need to know the order in which the fields come, and you can't miss any out. A better way is to specify the field names, thus telling the database what order you are giving the values for the fields in, and also which fields you want to include. For example

INSERT INTO Users (UserName, UserID) VALUES ('James Crowley', 10)

Note that in the above example, the UserID is given last, and the Password field is ignored. If you do miss any fields out, they will remain Null, or be given their default value. Please note that if a field is an AutoNumber, you should not include it when adding the records. The database will automatically assign a new value to it. For example, if the UserID field was an AutoNumber field (which would be very likely, as it would need a unique number for each record), you would use something like this:

INSERT INTO Users (UserName, Password) VALUES ('James Crowley', 'PASSWORD')

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Check for Failed SQL Query

    Posted by zible on 24 Jan 2007

    This seems simple, yet I can't find how you do this. I need to run a query in VB on a very simple database. There is the possibility that the query would be unsuccessfull, and if so I need to do ot...

  • Sql Info

    Posted by darshan on 25 Apr 2005

    you need to fire sql statement like this
    select idno, name, email, return from [table_name] where [your_condition]

    this will return record set lets say "rs" is object of recordset
    then you will n...

  • Another database issue

    Posted by Abzmoh2007 on 11 Mar 2004

    Basically am trying to search a database by getting an input from the users selection on a list.
    the list contains names of countries and when i click that search button, how can i get the result of...

  • Filling Table With Datagrid

    Posted by NightChillz on 23 Dec 2003

    hey, i see how i can fill a datagrid with data from an sql table, but i am having trouble figuring out how to do the exact opposite, take data from a datagrid and fill an sql table with it/overriding ...

  • update data

    Posted by tomoko on 26 Nov 2003

    hi,
    pls help as i'm new in asp. i'm developing the administrative part of a website for my project. i'm having trouble with the "updating data" part. for example, i have done the 'add staff' and "de...