导航

Sybase alter 用法

Posted on 2016-04-19 16:34  eastson  阅读(1695)  评论(0编辑  收藏  举报

原文地址:http://lujinan858.iteye.com/blog/437019

--示例 1 为表添加列。Adaptive Server 为表中每个现有行分配一个 NULL  
--列值:  
alter table publishers  
add manager_name varchar(40) null  
  
--示例 2 向表中添加 IDENTITY 列。Adaptive Server 为表中每个现有行分  
--配一个唯一的顺序列值。请注意,IDENTITY 列的类型为 numeric,标度  
--零。精度确定可插入到列中的最大值(10 5 - 1 或 99,999):  
alter table sales_daily  
add ord_num numeric(5,0) identity  
  
--示例 3 向 authors 表添加主键约束。如果表上有现有的主键或唯一约  
--束,请首先删除现有的约束(见示例 5):  
alter table authors  
add constraint au_identification  
primary key (au_id, au_lname, au_fname)  
  
--示例 4 在 authors 上创建索引,设置 reservepagegap 值为 16,在索引中  
--每 15 个分配的页留一个空白页:  
alter table authors  
add constraint au_identification  
primary key (au_id, au_lname, au_fname)  
with reservepagegap = 16  
  
--示例 5 删除 au_identification 约束:  
alter table titles  
drop constraint au_identification  
  
--示例 6 删除 authors 表中 phone 列的缺省约束。如果列允许空值,则没  
--有指定值时会插入空值。如果列不允许空值,则不指定列值的插入操作  
--将失败:  
alter table authors  
replace phone default null  
  
--例 7 为 titleauthor 表创建 4 个新的页链。将表分区后,现有的数据会  
保留在第一个分区。但是新的行会插入到所有这 5 个分区中:  
alter table titleauthor partition 5  
  
--示例 8 并置 titleauthor 表的所有页链,然后将其重新分区为 6 个分区。  
alter table titleauthor unpartition  
alter table titleauthor partition 6  
  
--示例 9 将 titles 表的锁定方案更改为数据行锁定:  
alter table titles lock datarows  
  
  
--示例 10 将非空列 author_type 添加到缺省值为 primary_author 的 authors 表:  
alter table authors  
add author_type varchar(20)  
default "primary_author" not null  
  
  
--示例 11 从 titles 表删除 advance、notes 和 contract 列:  
alter table titles  
drop advance, notes, contract  
  
--示例 12 将 authors 表的 city 列修改为缺省值为空值的 varchar(30):  
alter table authors  
modify city varchar(30) null  
  
--示例 13 将 stores 表的 stor_name 列修改为非空。注意其数据类型  
varchar(40) 不变:  
alter table stores  
modify stor_name not null  
  
--示例 14 修改 titles 表的 type 列,并将 titles 表的锁定方案从所有页锁定  
--更改为数据行锁定:  
alter table titles  
modify type varchar(10)  
lock datarows  
  
--示例 15 将 titles 表的 notes 列由 varchar(200) 修改为 varchar(150),将缺省  
--值由空更改为非空,并指定 exp_row_size 值为 40:  
alter table titles  
modify notes varchar(150) not null  
with exp_row_size = 40  
  
--示例 16 添加、修改和删除一列,然后在同一查询中添加另一列。改变  
--锁定方案,并指定新列的 exp_row_size 值:  
alter table titles  
add author_type varchar(30) null  
modify city varchar(30)  
drop notes  
add sec_advance money default 1000 not null  
lock datarows  
with exp_row_size = 40