--create table
create table emp1(
empno number(12) unique,
ename varchar2(20) default null,
sal varchar2(20)
);
--Create table: Create from the original table
create table emp2 as select * from Fasp_t_Causer;
--create table
create table emp3 (
epton number(3)constraint pk_emp3 primary key,
id number(10) not null,
firstname varchar2(22) unique,
waiempno number(12) ,
date2 date default sysdate
);
--Add foreign key emp1 in empno needs to be of unique type.
alter talbe emp3 add constraint fk_emp3 foreign key(waiempno) references emp1(empno) on delete set null;
--add index
create index ind_id on emp3(id);
-- delete table
drop table emp;
--modify table
alter table emp add aaa char(10);---oracle can only add columns one by one.
alter table emp drop column sss;-- delete rows.
alter table emp modify aadd NUMBER(6);--modify the column length.
alter table EMP1 modify sal not null;
alter table emp set unused(sss);--Set to useless state.
--View table structure
select column_name,data_length,data_type from user_tab_cols where table_name='MEMBER';
--View all tables under the current user.
select * from tab;
--Create partition table.
--check is used to limit the range of values in the column.
create table t_test(
guid number(20) not null ,
indexid varchar2(20),
pk_id number(30) not null,
add_date_time Date,
sex varchar2(20),
mid varchar2(10),
constraint pk_t_test primary key (pk_id),
constraint ck_sex check (sex in('男','女')),
constraint fk_mid foreign key(mid) references menber(mid)on delete cascade --// on delete set null
)
--partition by list(add_date_time)
partition by range (add_date_time)(
partition t_Test_2013 values less than (to_date('2017-11-15 00:00:00','yyyy-mm-dd hh24:mi:ss')) tablespace efmis
);
--index
create index ind_t_testid on t_test (indexid) tablespace efmis;
-- sub-authority
grant select on t_test to sys;
--mid as the foreign key of another table, needs to be the primary key of this table.
create table menber(
mid varchar2(10),
constraint pk_mid primary key(mid)
);
-- Force drop the parent table. Remove primary and foreign key relationships
drop table menber cascade constraint;
--View all constraint names, types, and table names corresponding to constraint settings
select constraint_name,constraint_type,table_name from user_constraints where table_name='T_TEST';
-- Lookup table information.
select * from user_cons_columns;
--Add constraints to the table.
alter table member add constraint pk_mid primary key(mid);
alter table member add constratint ck_age check (age between 0 and 200);
alter table member modify (name varchar2(30) not null);