INSERT

INSERT is used to add data to a database table.

There are several ways to insert data into a table by using the INSERT statement.

If you insert the data without specifying the field names, the data must be inserted in the same order in which it is stored in the database. To see how the database is storing the field names, you can type DESCRIBE tablename from a MySQL prompt, and MySQL shows you the layout of the table.

INSERT INTO library VALUES (‘020163337X','Tcl and the Tk Toolkit','John K. Ousterhout','$39.99','Paperback, 458pp.','Addison Wesley Longman, Inc.',' February 1994',NULL);

If you want to insert the data, but maybe not all of the data, or in a different order, you can do so like this (notice that the ISBN is now at the end, and we've omitted the notes field):

INSERT INTO library (title, author, price, format, publisher, datepub, isbn) VALUES (‘Tcl and the Tk Toolkit','John K. Ousterhout','    $39.99',' Paperback, 458pp.',' Addison Wesley Longman, Inc.',' February 1994', ‘020163337X');

If you want to explicitly name each field name along with the data, you can do so like this:

INSERT INTO library SET isbn='020163337X', title='Tcl and the Tk Toolkit', author='John K. Ousterhout', price='$39.99', format=' Paperback, 458pp.', publisher='Addison Wesley Longman, Inc.', datepub=' February 1994');



Perl Database Programming
Perl Database Programming
ISBN: 0764549561
EAN: 2147483647
Year: 2001
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net