oracle简单学习-表管理与表数据管理

    DDL:数据定义语言

    DML:数据操纵语言

    DCL:数据控制语言

    COMMIT提交;ROLLBACK回滚

                                      关于ddl语句创建表与管理表

一>查询数据字典

查看用户定义的表:

    Select table_name from user_tables;

查看用户定义的各种数据库对象:

    Select distinct object_type from user_objects;

查看用户定义的表,视图,同义词和序列:

    Select * from user_catalog;

二>创建表:

Create table 表名(列名 数据类型(尺寸));

三>复制表:

    Create table text1 as select * from employees;

    Create table text2 as select * from employees where 1=2;--创建的text2是空表。

Alter table语句:

  • 追加新的列 add
    alter table table1 add (tage number(3));
  • 修改列的数据类型,尺寸和默认值 modify
    alter table table1 modify (tage number(5));
  • 为新追加的列定义默认值 default
    alter table table1 modify (tid number(5) default 0);
  • 删除一个列 drop column 列名
    alter table table1 drop column tsex;
  • 重命名表的一个列名 rename column 列名 to
    alter table table1 rename column tname to name;

rename执行rename语句可以改变表,视图,序列,或同义词的名称;

四>删除表:

Drop table 表名:删除表数据与表结构è删除整张表,

所有正在运行的相关事务被提交,

所有相关索引被删除,

Drop table语句不能回滚

五>清空表:

Truncate table表名:清空表数据,truncate语句不能回滚

                                  可以使用delete语句删除数据,可以回滚

 

                                      关于dml语句处理表数据

一>插入数据:

Insert into:向表中插入数据;

在表中插入空的数据值(前提是该列可为空):

a.省略该列列名,

    insert into table1(id,sex,age,tall) 
    values(1,'男',19,1.75)

b.在values子句中指定空值(如果不写列名,有多少列就要定义多少个值,给需要为空的定义null即可)

    insert into table1 
    values(3,'大象','女',null,1.65);

从其他表中拷贝数据(需要两张表列名,数据类型,尺寸一一对应):

    insert into table2 select * from table1;

二>更新数据:

Update 表名 set:更新数据;

    update table1 set id=4 where name='大喵';

更改前:

更改后:

三>删除表数据:

Delete from 表名:可回滚;

猜你喜欢

转载自blog.csdn.net/qq_44551864/article/details/88600976