SQL Insert

The SQL insert command is used to insert data into your SQL database. Our SQL tutorial teaches you SQL commands. It covers the insert, create, join,� import, retrieve, order, update, and delete commands.

Table of Contents

Inserting Rows

You can insert new rows into a table by using Scalable SQL.

Syntax:

Insert into tablename ( fieldname, fieldname, fieldname)
values ( value, value, value);

Explanation:

  • When inserting data, use the Start Transaction command so that any errors can be rolled back.
  • You must specify the values to be inserted.
  • When performing an insert, enclose character values in single quotes.
  • Do not enclose numeric values in single quotes.
  • Use the Rollback Work command to undo changes.
  • Use the Commit Work command to finalize changes.
Example:

Insert the following vendor into the TrnVendor table.

Vendor Id: TV055
Name: Party Games
Address: PO Box 136
City: Chicago
State: IL
Current Balance: 2498.62

  1. To start the transaction, type:

Start transaction;

  1. To insert the records, type:

Insert into TrnVendor (VendId, Name, Addr1, City, State, 
CurrBal )
values ( 'TV055', 'Party Games', 'PO Box 136', 'Chicago', 'IL', 2498.62);

  1. To view the record, type:

Select VendId, Name, Addr1, City, State, CurrBal [-ZZZ,ZZZ.99]
from TrnVendor
where VendId = 'TV055';

  1. To roll back your work, type:

Rollback work;

Table of Contents

Legal Dot Privacy