数据定义语言:(DDL)

建表语句:

CREATE TABLE [IF NOT EXISTS] table_name
[(col_name data_type [COMMENT col_comment], ...)] // 设置表的字段,给字段添加注释
[COMMENT table_comment] //给建的表添加注释
[PARTITIONED BY (col_name data_type [COMMENT col_comment], ...)] //添加分区,目前分区标只能是string类型的;
[LIFECYCLE days] //设置表的生命周期
[AS select_statement] //也可以用as方式建表,但是as和第一个的col方式是不能并存的

删表:

drop table [if exists] table_name;

修改表名:

alter table table_name rename to new_table_name;

分区操作:

添加分区:

alter table table_name add [if not exists] partition(partition_col1 = partition_col_value1, partition_col2 = partiton_col_value2, ...);

删除分区:

alter table table_name drop [if exists] partition(partition_col1 = partition_col_value1, partition_col2 = partiton_col_value2, ...);

修改属性:

添加列:

ALTER TABLE table_name ADD COLUMNS (col_name1 type1,col_name2 type2...);

修改列名:

ALTER TABLE table_name CHANGE COLUMN old_col_name RENAME TO new_col_name;

修改表注释:

alter table table_name set comment 'tb1 comment' 

修改列/分区注释:

ALTER TABLE table_name CHANGE COLUMN col_name COMMENT comment_string;

DDL数据定义语言案例演示:

创建/删除普通表:

odps@ sdrtest>create table t_people (id bigint , name string);  //创建普通表

odps@ sdrtest>desc t_people;  //查看普通表的表结构

+------------------------------------------------------------------------------------+
| Owner: ALIYUN$1399438812@qq.com | Project: sdrtest |
| TableComment: |
+------------------------------------------------------------------------------------+
| CreateTime: 2019-04-13 09:02:41 |
| LastDDLTime: 2019-04-13 09:02:41 |
| LastModifiedTime: 2019-04-13 09:02:41 |
+------------------------------------------------------------------------------------+
| InternalTable: YES | Size: 0 |
+------------------------------------------------------------------------------------+
| Native Columns: |
+------------------------------------------------------------------------------------+
| Field | Type | Label | Comment |
+------------------------------------------------------------------------------------+
| id | bigint | | |
| name | string | | |
+------------------------------------------------------------------------------------+ OK
odps@ sdrtest>drop table t_people_p; //删除普通表

创建分区表:

odps@ sdrtest>create table t_people_p (id bigint,name string) partitioned by (gender string);  //创建分区表

odps@ sdrtest>desc t_people_p; //查看表结构

+------------------------------------------------------------------------------------+
| Owner: ALIYUN$1399438812@qq.com | Project: sdrtest |
| TableComment: |
+------------------------------------------------------------------------------------+
| CreateTime: 2019-04-13 09:08:53 |
| LastDDLTime: 2019-04-13 09:08:53 |
| LastModifiedTime: 2019-04-13 09:08:53 |
+------------------------------------------------------------------------------------+
| InternalTable: YES | Size: 0 |
+------------------------------------------------------------------------------------+
| Native Columns: |
+------------------------------------------------------------------------------------+
| Field | Type | Label | Comment |
+------------------------------------------------------------------------------------+
| id | bigint | | |
| name | string | | |
+------------------------------------------------------------------------------------+
| Partition Columns: |
+------------------------------------------------------------------------------------+
| gender | string | |
+------------------------------------------------------------------------------------+ OK

增加/删除分区表中的分区: 

odps@ sdrtest>alter table t_people_p add partition (gender = 'male');  //增加分区
odps@ sdrtest>alter table t_people_p drop if exists partition (gender = 'male'); //删除已有分区  

修改表属性:

odps@ sdrtest>alter table t_people set lifecycle 7;  //修改表的lifecycle属性为7天;

查看表结构验证:
odps@ sdrtest>desc t_people; +------------------------------------------------------------------------------------+
| Owner: ALIYUN$1399438812@qq.com | Project: sdrtest |
| TableComment: |
+------------------------------------------------------------------------------------+
| CreateTime: 2019-04-13 09:02:41 |
| LastDDLTime: 2019-04-13 09:02:41 |
| LastModifiedTime: 2019-04-13 09:02:41 |
| Lifecycle: 7 | //验证为lifecycle里面的属性确定被修改为了7天;
+------------------------------------------------------------------------------------+
| InternalTable: YES | Size: 0 |
+------------------------------------------------------------------------------------+
| Native Columns: |
+------------------------------------------------------------------------------------+
| Field | Type | Label | Comment |
+------------------------------------------------------------------------------------+
| id | bigint | | |
| name | string | | |
+------------------------------------------------------------------------------------+ OK
给表格新增一列:
odps@ sdrtest>alter table t_people add columns (age bigint); odps@ sdrtest>desc t_people; +------------------------------------------------------------------------------------+
| Owner: ALIYUN$1399438812@qq.com | Project: sdrtest |
| TableComment: |
+------------------------------------------------------------------------------------+
| CreateTime: 2019-04-13 09:02:41 |
| LastDDLTime: 2019-04-13 09:20:09 |
| LastModifiedTime: 2019-04-13 09:02:41 |
| Lifecycle: 7 |
+------------------------------------------------------------------------------------+
| InternalTable: YES | Size: 0 |
+------------------------------------------------------------------------------------+
| Native Columns: |
+------------------------------------------------------------------------------------+
| Field | Type | Label | Comment |
+------------------------------------------------------------------------------------+
| id | bigint | | |
| name | string | | |
| age | bigint | | |
+------------------------------------------------------------------------------------+ OK
修改表名:
odps@ sdrtest>alter table t_people rename to t_women;
查看修改结果:
odps@ sdrtest>list tables;
ALIYUN$1399438812@qq.com:t_women
更新列名:
odps@ sdrtest>ALTER TABLE t_women CHANGE COLUMN age RENAME TO age1; //将age列名更新为age1 odps@ sdrtest>desc t_women; +------------------------------------------------------------------------------------+
| Owner: ALIYUN$1399438812@qq.com | Project: sdrtest |
| TableComment: |
+------------------------------------------------------------------------------------+
| CreateTime: 2019-04-13 09:02:41 |
| LastDDLTime: 2019-04-13 09:28:02 |
| LastModifiedTime: 2019-04-13 09:02:41 |
| Lifecycle: 7 |
+------------------------------------------------------------------------------------+
| InternalTable: YES | Size: 0 |
+------------------------------------------------------------------------------------+
| Native Columns: |
+------------------------------------------------------------------------------------+
| Field | Type | Label | Comment |
+------------------------------------------------------------------------------------+
| id | bigint | | |
| name | string | | |
| age1 | bigint | | | //验证列名已经更新;
+------------------------------------------------------------------------------------+ OK

  

 

  

  

others:...

ODPS SQL <for 数据定义语言 DDL>的更多相关文章

  1. MySQL之数据定义语言(DDL)

    写在前面 本文中 [ 内容 ] 代表啊可选项,即可写可不写. SQL语言的基本功能介绍 SQL是一种结构化查询语言,主要有如下几个功能: 数据定义语言(DDL):全称Data Definition L ...

  2. <MySQL>入门三 数据定义语言 DDL

    -- DDL 数据定义语言 /* 库和表的管理 一.库的管理:创建.修改.删除 二.表的管理:创建.修改.删除 创建:create 修改:alter 删除:drop */ 1.库的管理 -- 库的管理 ...

  3. 30441数据定义语言DDL

    数据定义:指对数据库对象的定义.删除和修改操作. 数据库对象主要包括数据表.视图.索引等. 数据定义功能通过CREATE.ALTER.DROP语句来完成. 按照操作对象分类来介绍数据定义的SQL语法. ...

  4. SQL语句整理(二) 数据定义语言DDL

    前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...

  5. oracle 数据定义语言(DDL)语法

    DDL语言包括数据库对象的创建(create).删除(drop)和修改(alter)的操作 1.创建表语法 create table table_name( column_name datatype  ...

  6. 【MySQL笔记】数据定义语言DDL

    1.创建基本表   create table <表名> (<列名><数据类型>[列级完整性约束条件]                                 ...

  7. SQLite基础-4.数据定义语言(DDL)

    目录 一.创建数据库 1. 创建方式 2. 数据库命名规范 二. 创建表 1. 基本用法 2. 数据表命名规范 3. 字段命名规范 三. 删除表 一.创建数据库 1. 创建方式 在第二章中我们讲了如何 ...

  8. ODPS SQL <for 数据操作语言DML>

    基本操作: 查询: SELECT [ALL | DISTINCT] select_expr, select_expr, ... FROM table_reference [WHERE where_co ...

  9. MySQL SQL DLL (数据定义语言)

    CREATE CREATE DATABASE CREATE DATABASE 用于创建数据库 CREATE DATABASE new_database_name; CREATE TABLE CREAT ...

随机推荐

  1. VS Code 工具配置和格式化

    { "onSave": true, "javascript": { "indent_size": 2, "indent_char& ...

  2. Logging常用handlers的使用

    一.StreamHandler 流handler——包含在logging模块中的三个handler之一. 能够将日志信息输出到sys.stdout, sys.stderr 或者类文件对象(更确切点,就 ...

  3. Windows下用PIP安装scipy出现no lapack/blas resources found

    Windows下升级了pandas,但是发现scipy包随后引用出错,后来确认需重新安装scipy, 在用PIP安装scipy出现no lapack/blas resources found的错误,具 ...

  4. 通过父元素的hover控制子元素的显示

    .searbar_content_box:hover .searchBar_checked_detail_box{ display:block}

  5. js··事件捕捉

    给一个元素绑定事件,普通写法是 obj.onclick=function(){} 这就相当于给obj的onclick属性赋值是一个道理. obj.onclick=function(){} 这种写法有一 ...

  6. 编译安装和apt安装Nginx1.14.0

    安装依赖 yum -y install gcc gcc-c++yum -y install zlib zlib-devel openssl openssl-devel pcre-devel 在Ubun ...

  7. lucas 模板 洛古模板题

    #include<bits/stdc++.h> #define int long long using namespace std; ; int a[maxn]; int quick(in ...

  8. 664. Strange Printer

    class Solution { public: int dp[100][100]; int dfs(const string &s, int i,int j) { if(i>j)ret ...

  9. Socket基础之-启动异步服务侦听

    Socket网络编程第一篇: 本文主要是以代码为主. .NET技术交流群 199281001 .欢迎加入 1 //负责监听的套接字 private Socket socketServer; //通知一 ...

  10. Python变量以及类型

    变量的定义 在程序中,有时我们需要对2个数据进行求和,那么该怎样做呢? 大家类比一下现实生活中,比如去超市买东西,往往咱们需要一个菜篮子,用来进行存储物品,等到所有的物品都购买完成后,在收银台进行结账 ...