数据库sql语言第一节(数据库定义语言(DDL)针对 “表” 去操作)

##数据库SQL语言

一、数据库定义语言(DDL)针对 “表” 去操作

  • CREATE创建
create table tabname(
	id number,
    colname_1 varchar2(20),
    colname_2 数据类型,
    colname_3 数据类型,
    colname_4 数据类型,
    colname_5 数据类型
);
  • DROP 删除
DROP table tabname;
  • 数据类型

    数字类型:number 数字

    number(最大长度) 整数

    number(最大长度,小数位数) 浮点

    字符类型:varchar2(最大长度) 字符串

    布尔类型 : number(1) 0 , 1 假 和 真

    时间类型: date 年月日时分秒

  • 约束条件

    primary key 主键约束

    not null 非空约束

    unique 唯一约束

    create table student(
    	id number primary key,
        name varchar2(20),
        sex varchar2(2) not null,
        email varchar2(50) unique,
        mobile varchar2(20) unique
    );
  • 命名规则

    关键字都是 大写 CREATE TABLE DROP

    不加双引号,不区分大小写

    加双引号,区分大小写

    所有的表名,列名 都小写。 函数名…都大写

    标识符命名规则: 字母,数字,下划线_ ,美元符号$ , #符号。(数字不能为开头,不区分大小写)

  • ALTER 修改

    alter table 表名

1.添加列

alter table student add(class varchar2(20),adress varchar2(20));

2.删除列

alter table student drop(adress,class);

3.修改列名

alter table student rename column adress to '地址';

4.修改列数据类型

alter table student modify(class number(7,2));

5.添加约束条件

alter table student add unique(class);

6.删除约束

alter table student drop constraint SYS_C005661;

7.失效约束

alter table student disable constraint SYS_C005661 cascade;

8.生效约束

alter table student enable constraint SYS_C005661

注意:以上的操作需要保证数据为null。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值