O'Reilly logo

Beginning SQL by John W. Colby, Paul Wilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Entering Information

The last chapter examined creating a database and adding tables, so now you're ready to start adding data. Most RDBMSs provide management tools that allow you to view tables and the records they hold, as well as allowing you to add, modify, and delete the data. These tools are very convenient when you have small amounts of data or when you're just testing the database. However, you don't generally enter data using the management tools. Much more common is some sort of program or Web page that acts as a pleasant front end into which the user enters and views data. This chapter's focus is on how to use SQL statements to insert, update, or delete data contained in a database.

This chapter covers the three SQL statements that deal with altering data. The first is the INSERT INTO statement, which inserts new data. The UPDATE statement updates existing data in the database. Finally, this chapter covers the DELETE statement, which (surprise, surprise) deletes records.

Inserting New Data

The INSERT INTO statement makes inserting new data into the database very easy. All you need to do is specify into which table you want to insert data, into which columns to insert data, and finally what data to insert. The basic syntax is as follows:

INSERT INTO table_name (column_names) VALUES (data_values)

This line of code adds a record to the Category table:

INSERT INTO Category (CategoryId, Category) VALUES (1, 'Thriller');

You can see that inserting data is simply a matter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required