SQL Commands

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')

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous