Chinaunix首页 | 论坛 | 博客
  • 博客访问: 292162
  • 博文数量: 109
  • 博客积分: 5814
  • 博客等级: 大校
  • 技术积分: 1440
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-26 10:17
文章分类

全部博文(109)

文章存档

2010年(9)

2009年(36)

2008年(64)

我的朋友

分类: Mysql/postgreSQL

2008-03-01 17:24:53

语法 alter database
 ALTER {DATABASE | SCHEMA} [db_name]
    alter_specification [, alter_specification] ...

alter_specification:
    [DEFAULT] CHARACTER SET charset_name [DEFAULT] COLLATE collation_name
alter database更改数据库的全局属性,要得到必须要权限,root不限 ,其他用户用grant添加alter权限
alter table
语法
ALTER [IGNORE] TABLE tbl_name
    alter_specification [, alter_specification] ...

alter_specification:
    ADD [COLUMN] column_definition [FIRST | AFTER col_name ]
  | ADD [COLUMN] (column_definition,...)
  | ADD INDEX [index_name] [index_type] (index_col_name,...)
  | ADD [CONSTRAINT [symbol]]
        PRIMARY KEY [index_type] (index_col_name,...)
  | ADD [CONSTRAINT [symbol]]
        UNIQUE [index_name] [index_type] (index_col_name,...)
  | ADD [FULLTEXT|SPATIAL] [index_name] (index_col_name,...)
  | ADD [CONSTRAINT [symbol]]
        FOREIGN KEY [index_name] (index_col_name,...)
        [reference_definition]
  | ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
  | CHANGE [COLUMN] old_col_name column_definition
        [FIRST|AFTER col_name]
  | MODIFY [COLUMN] column_definition [FIRST | AFTER col_name]
  | DROP [COLUMN] col_name
  | DROP PRIMARY KEY
  | DROP INDEX index_name
  | DROP FOREIGN KEY fk_symbol
  | DISABLE KEYS
  | ENABLE KEYS
  | RENAME [TO] new_tbl_name
  | ORDER BY col_name
  | CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]
  | [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]
  | DISCARD TABLESPACE
  | IMPORT TABLESPACE
  | table_options
  | partition_options
  | ADD PARTITION partition_definition
  | DROP PARTITION partition_names
  | COALESCE PARTITION number
  | REORGANIZE PARTITION partition_names INTO (partition_definitions)
  | ANALYZE PARTITION partition_names
  | CHECK PARTITION partition_names
  | OPTIMIZE PARTITION partition_names
  | REBUILD PARTITION partition_names
  | REPAIR PARTITION partition_names
要使用ALTER TABLE,您需要获得表的ALTER, INSERTCREATE权限
CREATE TABLE t1 (
    id INT,
    year_col INT
)
PARTITION BY RANGE (year_col) (
    PARTITION p0 VALUES LESS THAN (1991),
    PARTITION p1 VALUES LESS THAN (1995),
    PARTITION p2 VALUES LESS THAN (1999)
);    
ALTER TABLE t1 ADD PARTITION p3 VALUES LESS THAN (2002);不能在没有分区的表上添加 新的分区
ALTER TABLE t2 ADD INDEX (d), ADD INDEX (a);添加索引
 
阅读(1279) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:php 安全设置

给主人留下些什么吧!~~