1、CREATE TABLESPACE ts01 DATAFILE D:DataBaseOracle11goradataorcltest_db01.dbfSIZE 100MAUTOEXTEND ON NEXT 100M MAXSIZE 1024MDEFAULT STORAGE(INITIAL 10m NEXT 1M)PERMANENTONLINELOGGING;- 修改表空间ALTER TABLESPACE ts01NOLOGGING;- 表空间增加数据文件ALTER TABLESPACE ts01 ADD DATAFILE DataBaseOracle11goradataorcltest_db0
2、2.dbfSIZE 100M REUSEAUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED;- 删除表空间DROP TABLESPACE ts01;- 删除表空间同时删除数据文件DROP TABLESPACE ts01 INCLUDING CONTENTS AND DATAFILES;- 表空间中建表CREATE TABLE student(student_id VARCHAR2(10),student_name VARCHAR2(20)TABLESPACE ts01;- 查看表所属表空间SELECT TABLE_NAME, TABLESPACE_NAME FR
3、OM tabs WHERE TABLE_NAME = STUDENT;- 查看表结构DESCRIBE student;DESC student;- 增加表注释COMMENT ON TABLE student IS 学生信息表- 查看表注释SELECT * FROM USER_TAB_COMMENTS WHERE TABLE_NAME = SELECT * FROM ALL_TAB_COMMENTS WHERE TABLE_NAME = - 表字段增加注释COMMENT ON COLUMN STUDENT.STUDENT_ID IS 学生编号- 查看表字段注释SELECT * FROM USER
4、_COL_COMMENTS WHERE TABLE_NAME = SELECT * FROM ALL_COL_COMMENTS WHERE TABLE_NAME = - 查看用户所有表SELECT * FROM User_Tables;- 查看用户拥有的所有对象SELECT * FROM User_Objects;- 查看用户拥有的 表 试图 序列SELECT * FROM User_Catalog;- 表字段修改ALTER TABLE student MODIFY(student_id CHAR(15);- 表字段增加ALTER TABLE STUDENT ADD(AGE NUMBER(2)
5、;- 删除表字段ALTER TABLE STUDENT DROP COLUMN student_name;- 修改表名称RENAME STUDENT TO STU;- 删除表DROP TABLE STUDENT;s_id Varchar2(10),s_name varchar2(20),s_age Number(3),s_birthday DATE- 增加一条记录INSERT INTOstudent (s_id, s_name, s_age, s_birthday) VALUES (S000000001, Tarring01, 10, to_date(1982-10-06,yyyy-mm-dd
6、);S000000002Tarring02, 10, Sysdate);- 使用替代变量时,输入字符串字段时一样要写上引号VALUES (&s_id, &s_name, 10, Sysdate);- 修改记录UPDATE student SET s_name = 陶川, s_age = 20 WHERE s_id = - 删除记录DELETE FROM student WHERE s_id = - 截断表TRUNCATE TABLE student;- 事务处理COMMIT; - 提交事务INSERT INTO student (s_id, s_name) VALUES (S001tarrin
7、g1);ROLLBACK; - 回滚,回滚到上一次提交过后的点- 带恢复点的事务SAVEPOINT firstdate;S002tarring2SAVEPOINT seconddate;DELETE FROM student;ROLLBACK TO firstdate;SELECT * FROM student;- 约束条件 说明- UNIQUE 指定字段的值,必须是唯一的- PRIMARY KEY 主键,会为指定的字段作索引,并且也是唯一的值- NOT NULL 不可以是空值【 NULL】或0(零)- CHECK 检查,必须符合指定的条件- FOREIGN KEY 外键,用来创建一个参考表之
8、间的关系- 建表同时建立唯一约束s_birthday DATE,CONSTRAINT s_name_uk UNIQUE(s_name)- 查看唯一约束SELECT table_name, constraint_name, constraint_type FROM User_Constraints WHERE table_name = - 作业:数据字典【分类 常用】- 建表同时建立主键CONSTRAINT s_id_pk PRIMARY KEY (s_id)- 查看主键约束- 建表同时建立非空字段s_name varchar2(20) NOT NULL, NULL); - 插入一个null-
9、查看非空约束SELECT table_name, constraint_name, constraint_type, search_condition FROM User_Constraints WHERE table_name = - 建表同时建立检查CONSTRAINT s_age_ck CHECK (s_age BETWEEN 1 AND 100) - 端点值可以使用- 查看检查约束- 外键的使用CREATE TABLE team(t_id Varchar2(10),t_name Varchar2(20),CONSTRAINT t_id_pk PRIMARY KEY (t_id)team_id VARCHAR2(10),CONSTRAINT s_id_pk PRIMARY KEY (s_id),CONSTRAINT s_team_id_fk FOREIGN KEY (team_id) REFERENCES team(t_id)- 查看表的外键约束drop table team; - 被引用表是不能删除的insert into team (t_id, t_name) values (t001lanseneinsert into stu
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1