前端之家收集整理的这篇文章主要介绍了
【从零开始学习Oracle数据库】(5)约束视图与索引,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CREATE TABLE dept_dylan ( dept_id NUMBER (2) PRIMARY KEY,dept_name VARCHAR (20),dept_location VARCHAR (40) );
INSERT INTO dept_dylan VALUES (10,'developer','beijing');
INSERT INTO dept_dylan VALUES (10,'market','shenzhen');
CREATE TABLE dept_dylan2( dept_id NUMBER (2),dept_location VARCHAR (40),constraint dept_dylan2_pk PRIMARY KEY (dept_id) );
INSERT INTO dept_dylan2 VALUES (10,'beijing');
INSERT INTO dept_dylan2 VALUES (10,'shenzhen');
SELECT * FROM dept_dylan2;
CREATE TABLE student_dylan ( id NUMBER (4) PRIMARY KEY,NAME VARCHAR (10) NOT NULL,age NUMBER (3) );
INSERT INTO student_dylan VALUES (1,'zhangwei',20);
INSERT INTO student_dylan VALUES (2,19);
INSERT INTO student_dylan VALUES (3,NULL,19);
SELECT * FROM student_dylan;
DROP TABLE student_dylan;
CREATE TABLE student_dylan ( id NUMBER (4) PRIMARY KEY,name VARCHAR (10) constraint student_dylan_name_nn NOT NULL,age NUMBER (3) );
CREATE OR REPLACE VIEW v_emp_count AS SELECT dept_test_id,count(*) emp_num,sum(salary) sum_s,avg(IFNULL(salary,0)) avg_s,max(salary) max_s,min(salary) min_s FROM emp_test GROUP BY dept_test_id;
SELECT * FROM v_emp_count;
create table student_ning7( id INT(4),name char(20),email char(40),constraint stu_n7_id_pk primary key(id),constraint stu_n7_email_uk unique(email) ) create index idx_stu7_name on student_ning7(name) ;
select * from student_ning7 where name = 'zhangsan' ;