Adding new rows with select  Inserting data into some columns

Chapter 7: Adding, Changing, and Deleting Data

Using computed columns

You can use computed columns in a select statement inside an insert statement. For example, imagine that a table named tmp contains some new rows for the titles table, which contains some out-of-date data—the price figures need to be doubled. A statement to increase the prices and insert the tmp rows into titles looks like:

insert titles 
select title_id, title, type, pub_id, price*2,
    advance, total_sales, notes, pubdate, contract
from tmp

When you perform computations on a column, you cannot use the select * syntax. Each column must be named individually in the select list.





Copyright © 2005. Sybase Inc. All rights reserved. Inserting data into some columns

View this book as PDF