Home Database Mysql Tutorial Oracle做学生信息系统的脚本

Oracle做学生信息系统的脚本

Jun 07, 2016 pm 02:56 PM
oracle information student Script

Oracle做学生信息系统的脚本 无 要求的约束条件有: 主键是学号;入学日期必须大于出生日期;总分必须在0到700之间;学号和姓名不能为空create table student (sid number not null primary key,name nvarchar2(10) not null,birthday date,sdate date,addres

Oracle做学生信息系统的脚本
    要求的约束条件有:
  主键是学号;入学日期必须大于出生日期;总分必须在0到700之间;学号和姓名不能为空


create table student (
	sid number not null primary key,
	name nvarchar2(10) not null,
	birthday date,
	sdate date,
	address nvarchar2(20),
	mark number,
	constraint ck_sdate check(sdate>birthday),
	constraint ck_mark check(mark>=0 and mark<=700))tablespace users;

 insert into student values(1001,'张三','1-1月-1981','1-1月-1999','上海',600);


  用OEM再创建以上表student2,添加约束,并在数据输入窗口输入以下记录:

  表字段名(英文部分)及部分数据如下:
  sid(学号)name(姓名)birthday(出生日期)sdate(入学日期)address(家庭地址 ) mark(入学总分)
  1001     张三名         1981-1-1           1999-1-1       张三名的家庭地址       600
  1002     李三名         1982-2-2           2000-1-1       李三名的家庭地址       620
  1003     张四名         1983-3-3           2001-1-1       张四名的家庭地址       580
  1004     李四名         1984-4-4           2002-1-1       李四名的家庭地址       592
Copy after login
  计算出学生总数;
	select count(1) as 学生总数 from student;

  查询出姓名中第二个字符为“三”而且不姓张的学生;
	select * from student where name like '_三%' and name not like '张%';


  查询出在1982-1-1和1984-1-1之间出生的学生的姓名;
	select name,birthday from student where birthday between to_date('1982-1-1','yyyy-MM-dd') and to_date('1984-1-1','yyyy-MM-dd');


  查询出年龄最小的学生;
	select * from student where birthday in (select max(birthday) from student);

  查询出在学校待的时间最长的学生;
	select * from student where sdate in (select min(sdate) from student);

  计算出所有学生总分的平均分;
	select avg(mark) as 平均分 from student;

  显示总分最高的学生的总分和姓名;
	select name,mark from student where mark in (select max(mark) from student);

  删除总分在600以下的学生,然后进行回滚;
	delete from student where mark<600 ;rollback;

  为表添加两列,一列是sex(性别),一列是speciality(专业),
  	其中,专业部分的默认值是“外语”;且有一个名为CK_SEX的约束条件:性别只能是“男”或“女;
  修改专业的默认值为“计算机”;
	alter table student add(sex nvarchar2(4) check (sex='男' or sex='女'), speciality nvarchar2(10) default '外语');
	alter table student modify(speciality default '计算机');
Copy after login
id(编号)  sid(学生编号)  testtype(考试类型) score(分数)
   1	    	1001	       期中             580
   2	   	1001	       期末		590
   3	    	1002           期中             570
   4        	1002           期末	        595
   5       	1003           期中	        570
   6        	1003           期末	        565
	
create table score
(
	id number not null,
	sid number not null,
	testtype nvarchar2(10),
	score number	
);
Copy after login
用OEM界面给score创建一个外键,对应student的主键,然后在sql*plus中用sql语句删除此外键,再用sql语句为score创建一个外键;
	alter table score drop constraint SCORE_FK21245050242859;
	alter table score add (constraint fk_sid foreign key(sid) references student(sid));
Copy after login
	select sid,name,address from student  where mark>610 and sid in
		(select sid from score where testtype='期末' and score>=590);
Copy after login
update score set score=score+10 where testtype='期末' and sid in (select sid from student where mark>=600);
Copy after login
select * from student where sid not in (select sid from score);
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How long will Oracle database logs be kept? How long will Oracle database logs be kept? May 10, 2024 am 03:27 AM

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

Function to calculate the number of days between two dates in oracle Function to calculate the number of days between two dates in oracle May 08, 2024 pm 07:45 PM

The function in Oracle to calculate the number of days between two dates is DATEDIFF(). The specific usage is as follows: Specify the time interval unit: interval (such as day, month, year) Specify two date values: date1 and date2DATEDIFF(interval, date1, date2) Return the difference in days

The order of the oracle database startup steps is The order of the oracle database startup steps is May 10, 2024 am 01:48 AM

The Oracle database startup sequence is: 1. Check the preconditions; 2. Start the listener; 3. Start the database instance; 4. Wait for the database to open; 5. Connect to the database; 6. Verify the database status; 7. Enable the service (if necessary ); 8. Test the connection.

How to use interval in oracle How to use interval in oracle May 08, 2024 pm 07:54 PM

The INTERVAL data type in Oracle is used to represent time intervals. The syntax is INTERVAL <precision> <unit>. You can use addition, subtraction, multiplication and division operations to operate INTERVAL, which is suitable for scenarios such as storing time data and calculating date differences.

How to see the number of occurrences of a certain character in Oracle How to see the number of occurrences of a certain character in Oracle May 09, 2024 pm 09:33 PM

To find the number of occurrences of a character in Oracle, perform the following steps: Get the total length of a string; Get the length of the substring in which a character occurs; Count the number of occurrences of a character by subtracting the substring length from the total length.

Oracle database server hardware configuration requirements Oracle database server hardware configuration requirements May 10, 2024 am 04:00 AM

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

How much memory does oracle require? How much memory does oracle require? May 10, 2024 am 04:12 AM

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

How to replace string in oracle How to replace string in oracle May 08, 2024 pm 07:24 PM

The method of replacing strings in Oracle is to use the REPLACE function. The syntax of this function is: REPLACE(string, search_string, replace_string). Usage steps: 1. Identify the substring to be replaced; 2. Determine the new string to replace the substring; 3. Use the REPLACE function to replace. Advanced usage includes: multiple replacements, case sensitivity, special character replacement, etc.

See all articles