20170802上课随笔

deptno int constraint emp_deptno_fk references dept(deptno))级联约束

    deptno int constraint emp_deptno_fk references dept(deptno) on delete set null)或者on delete cascade//级联删除

ALTER TABLE test_phone_tab disable constraint test_phone_pk; //禁用约束

ALTER TABLE test_phone_tab enable constraint test_phone_pk; //启用约束

序列:

SQL> create sequence test_seq increment by 1 start with 1 maxvalue 1000 nocycle cache 20;

SQL> create table t1(x int primary key, y int);

SQL> insert into t1 values (test_seq.nextval, 11);       反复执行

SQL> select * from t1;

 

索引:

主键和唯一性约束自动创建索引:

SQL> select constraint_name, constraint_type from user_constraints where table_name='EMPLOYEES';

SQL> select index_name, index_type from user_indexes where table_name='EMPLOYEES';

SQL> set autot on

SQL> select last_name from employees where employee_id=100;   走索引

SQL> select email from employees;                                               走索引

SQL> select last_name from employees where salary=2100;              全表扫描

SQL> create index emp_salary_ix on employees(salary);

SQL> select last_name from employees where salary=2100;              走索引

SQL> set autot off

原文地址:https://www.cnblogs.com/guoxf/p/7277805.html