Oracle入门指南_3
select sysdate from dual;/*dual为临时表,为了凑够select语句而设,后面还会多次使用到*/
?
创建表:/*创建t_student表,没有设置主键*/create table t_student( stuid number(10) not null, stuname nvarchar2(20) not null, age number(2) not null, address nvarchar2(200), codenum nvarchar2(18));/*创建t_score表,主键为scoreid*/create table t_score( scoreid number(10) primary key, score number(3,1) not null, stuid number(10));
alter table t_student add constraint pk_t_student primary key(stuid);/*pk_t_student是主键约束的名称*/
alter table t_student add constraint ck_t_student_age check(age>=18 and age<=25);--给student表中的age字段添加检查约束,年龄必须在18-25之间,否则存不进去,修改不成功
alter table t_student modify (address nvarchar2(200) default 'China');--把address字段重新定义了
alter table t_student add constraint un_t_student_codenum unique(codenum);--un_t_student_codenum是约束的名字,在这个表中这一项是唯一的,即没有重复的
alter table t_score add constraint fk_t_score_t_student foreign key(stuid) references t_student(stuid);--t_score表中的stuid是外键,连接着t_student表
alter table t_score drop constraint fk_t_score_t_student;--删除刚才给t_score表中建立的外键修改表:添加列
alter table t_student add(sex nvarchar2(2));--给t_student表添加一列:sex?修改列
alter table t_student modify (codenum nvarchar2(20));--修改codenum的长度为20字节
alter table t_student rename column sex to xingbie;--将sex重命名为xingbie
alter table t_student drop column xingbie;--删除xingbie列
rename t_student to xuesheng;--重命名t_student为xuesheng表?删除表
drop table t_student;--删除t_student表,记得先把xuesheng表的名称改过来总结:Oracle中SQL语句的组成Oracle中数据类型,数值型统一为Number表的创建,表中的约束的添加及删除对表进行修改,删除