home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book Home Perl for System AdministrationSearch this book

D.2. Inserting Data into a Table

Now that we have an empty table, let's look at two ways to add new data. Here's the first form:

USE sysadm
INSERT hosts 
     'shim shimmy shimmydoodles',
     'David Davis',

The first line tells the server we are going to work with objects in the sysadm database. The second line selects the hosts table and adds a row, one column at a time. This version of the INSERT command is used to add a complete row to the table (i.e., one with all columns filled in). To create a new row with a partial record we can specify the columns to fill, like so:

USE sysadm
INSERT hosts (name,ipaddr,owner)
     'Cindy Coltrane'

The INSERT command will fail if we try to insert a row does not have all of the required (NOT NULL) columns.

INSERT can also be used to add data from one table to another; we'll see this usage later. For the rest of our examples, assume that we've fully populated the hosts table using the first form of INSERT.

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.