重命名表
重命名表的基本语法是:
代码如下 | 复制代码 |
ALTER TABLE table_name For example: ALTER TABLE suppliers |
这将重命名的供应商表供应商。
表中添加列(S)
语法#1
要添加到现有的表列,ALTER TABLE的语法是:
代码如下 | 复制代码 |
ALTER TABLE table_name For example: ALTER TABLE supplier |
这会增加供应商表中的列称为supplier_name。
语法#2
要添加到现有表的多个列,ALTER TABLE的语法是:
代码如下 | 复制代码 |
ALTER TABLE table_name For example: ALTER TABLE supplier |
这将增加两列(supplier_name市)的供应商表。
修改表中的列(S)
语法#1
要修改现有表列,ALTER TABLE的语法是:
代码如下 | 复制代码 |
ALTER TABLE table_name For example: ALTER TABLE supplier |
这将修改所谓supplier_name,是一个VARCHAR2数据类型(100),并迫使列不允许空值的列。
语法#2
要修改现有表中的多个列,ALTER TABLE的语法是:
代码如下 | 复制代码 |
ALTER TABLE table_name For example: ALTER TABLE supplier |
这将修改supplier_name和城市列。
(S)在一个表中删除列
语法#1
要删除一个现有的表列,ALTER TABLE的语法是:
代码如下 | 复制代码 |
ALTER TABLE table_name For example: ALTER TABLE supplier |
这将下降supplier_name名为供应商的表列。
在表重命名列(S)
(新在Oracle 9i第2版)
语法#1
在Oracle9i第2版开始,你现在可以重命名列。
要在现有的表重命名列,ALTER TABLE的语法是:
代码如下 | 复制代码 |
ALTER TABLE table_name For example: ALTER TABLE supplier |
This will rename the column called supplier_name to sname.
Acknowledgements: Thanks to Dave M., Craig A., and Susan W. for contributing to this solution!
Practice Exercise #1:
Based on the departments table below, rename the departments table to depts.
代码如下 | 复制代码 |
CREATE TABLE departments ( department_id number(10) not null, department_name varchar2(50) not null, CONSTRAINT departments_pk PRIMARY KEY (department_id) ); |
Solution:
The following ALTER TABLE statement would rename the departments table to depts:
代码如下 | 复制代码 |
ALTER TABLE departments |
Practice Exercise #2:
Based on the employees table below, add a column called salary that is a number(6) datatype.
代码如下 | 复制代码 |
CREATE TABLE employees |
Solution:
The following ALTER TABLE statement would add a salary column to the employees table:
代码如下 | 复制代码 |
ALTER TABLE employees |
Practice Exercise #3:
Based on the customers table below, add two columns - one column called contact_name that is a varchar2(50) datatype and one column called last_contacted that is a date datatype.
代码如下 | 复制代码 |
CREATE TABLE customers |
Solution:
The following ALTER TABLE statement would add the contact_name and last_contacted columns to the customers table:
代码如下 | 复制代码 |
ALTER TABLE customers |
Practice Exercise #4:
Based on the employees table below, change the employee_name column to a varchar2(75) datatype.
代码如下 | 复制代码 |
CREATE TABLE employees ( employee_number number(10) not null, employee_name varchar2(50) not null, department_id number(10), CONSTRAINT employees_pk PRIMARY KEY (employee_number) ); |
Solution:
The following ALTER TABLE statement would change the datatype for the employee_name column to varchar2(75):
代码如下 | 复制代码 |
ALTER TABLE employees |
Practice Exercise #5:
Based on the customers table below, change the customer_name column to NOT allow null values and change the state column to a varchar2(2) datatype.
代码如下 | 复制代码 |
CREATE TABLE customers |
Solution:
The following ALTER TABLE statement would modify the customer_name and state columns accordingly in the customers table:
代码如下 | 复制代码 |
ALTER TABLE customers |
Practice Exercise #6:
Based on the employees table below, drop the salary column.
代码如下 | 复制代码 |
CREATE TABLE employees |
Solution:
The following ALTER TABLE statement would drop the salary column from the employees table:
代码如下 | 复制代码 |
ALTER TABLE employees |
Practice Exercise #7:
Based on the departments table below, rename the department_name column to dept_name.
代码如下 | 复制代码 |
CREATE TABLE departments |
解决方案:
下面的ALTER TABLE语句将重新命名department_name列dept_name部门表:
代码如下 | 复制代码 |
ALTER TABLE departments |
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级