数据定义语言:(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. FCC JS基础算法题(9):Mutations(比较字符串)

    题目描述: 如果数组第一个字符串元素包含了第二个字符串元素的所有字符,函数返回true.举例,["hello", "Hello"]应该返回true,因为在忽略大 ...

  2. activity select problem(greedy algorithms)

    many activities will use the same place, every activity ai has its'  start time si and finish time f ...

  3. 网络编程 多线程/socketserver模块/ threading.local

    线程:进程中负责程序执行的执行单元. 多线程:在1个进程中存在多个线程. 进程只是用来把资源集中在一起,而线程才是cpu上的执行单位. 每个进程都会默认有一个控制线程也叫作主线程. 进程之间是竞争关系 ...

  4. 【软件安装与环境配置】TX2刷机过程

    前言 使用TX2板子之前需要进行刷机,一般都是按照官网教程的步骤刷机,无奈买不起的宝宝只有TX2核心板,其他外设自己搭建,所以只能重新制作镜像,使用该镜像进行刷机. 系统需求 1.Host Platf ...

  5. linux日常命令之一

    zcat Linux中,cat命令可查看文本内容: 对于压缩包内的文本,可使用zcat命令,在不解压的情况下查看文本内容: iconv file -i 可查看文件字符集: iconv为字符集转换命令, ...

  6. Unreal Engine 4 C++ UCLASS构造函数易出错分析

    Unreal Engine 4 C UCLASS构造函数易出错分析 GENERATED_BODY GENERATED_UCLASS_BODY 在Unreal Engine 4的任意类中通常会见到两个宏 ...

  7. 支持Oracle的模糊查询和精准查询

    相信所有的软件开发者都做过页面上的查询功能,而且很多都需要既支持模糊查询的,也需要支持精准查询的,而且不需要增加多余的功能,只需要在文本框中输入包含类似*之类的符号即可. 下面的方法就是通过*来判断到 ...

  8. 【SpringBoot】SpringBoot2.0响应式编程

    ========================15.高级篇幅之SpringBoot2.0响应式编程 ================================ 1.SprinBoot2.x响应 ...

  9. GoStudy——Go语言入门第一个事例程序:HelloWorld.go

    package main import ( ​ "fmt" ) func main() { ​ fmt.Println("Hello,world!!!--2019年4月1 ...

  10. python中list列表的方法len()

    作用:返回列表中元素的个数. 用法: len(list)