Selecting the IDENTITY column more than once  Defining a column whose value must be computed

Chapter 8: Creating Databases and Tables

Adding a new IDENTITY column with select into

To define a new IDENTITY column in a select into statement, add the column definition before the into clause. The definition includes the column’s precision but not its scale:

select column_list
     identity_column_name = identity(precision)
     into table_name
     from table_name

The following example creates a new table, new_discounts, from the discounts table and adds a new IDENTITY column, id_col:

select *, id_col=identity(5)
into new_discounts
from discounts

If the column_list includes an existing IDENTITY column, and you add a description of a new IDENTITY column, the select into statement fails.





Copyright © 2005. Sybase Inc. All rights reserved. Defining a column whose value must be computed

View this book as PDF