Adding columns  Adding NOT NULL columns

Chapter 8: Creating Databases and Tables

Adding columns appends column IDs

alter table adds a column to the table with a column ID that is one greater than the current maximum column ID. For example, Table 8-5 lists the default column IDs of the salesdetail table:

Table 8-5: Column IDs of the salesdetail table

Column name

stor_id

ord_num

title_id

qty

discount

Col ID

1

2

3

4

5

This command appends the store_name column to the end of the salesdetail table with a column ID of 6:

alter table salesdetail
add store_name varchar(40) 
default
"unknown" not null

If you add another column, it will have a column ID of 7.

NoteBecause a table’s column IDs change as columns are added and dropped, your applications should never rely on them.





Copyright © 2005. Sybase Inc. All rights reserved. Adding NOT NULL columns

View this book as PDF