系统设计与数据库系统 作业一 Basic SQL command LAB(上)

简介: 系统设计与数据库系统 作业一 Basic SQL command LAB(上)

1. Purpose of Experiment purpose and Requirements


Please show all work for these problems.

Just writing down the answer will not get full credit.

Note: create a Table EMP_your_StudentID and DEPT_your_studentID with all required constraints both Integrity and Referential Integrity Constraint.

EMP Table:


2f650387ee62455bacb873eca596e800.png07fc71f629d3423ebd8bf5f811ec7651.png


DEPT TABLE:


b9d5a43af7564b0faa95cb42ff266940.png


INSERT TUPLES FOR EMP TABLE:


0a3abf7c2d8844cfa8b74b8a3e32940c.pngb7d4e83252dd459e8e011dc4144e063c.png

INSERT TUPLES FOR DEPT TABLE

23a97265ca4c4c9389ce2b2e8c165dab.png


2. Methods and steps

FIRST: CREATE THE DATABASE

We can create the database by the following code:


CREATE DATABASE `dong2019284073` /*!40100 DEFAULT CHARACTER SET latin1 */


87e733270cfd49069405d4fbb0f75558.png


SECOND: CREAT THE TABLES


We can create the tables and then initialize each column by the following code:

①dept2019284073


CREATE TABLE `dept2019284073` (
  `DEPTNO` int(2) NOT NULL,
  `DNAME` char(10) DEFAULT NULL,
  `LOC` char(10) DEFAULT NULL,
  PRIMARY KEY (`DEPTNO`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


②emp2019284073

CREATE TABLE `emp2019284073` (
  `EMPNO` decimal(4,0) NOT NULL,
  `ENAME` varchar(10) DEFAULT NULL,
  `JOB` varchar(9) DEFAULT NULL,
  `MGR` decimal(4,0) DEFAULT NULL,
  `HIREDATE` date NOT NULL,
  `SAL` decimal(7,2) NOT NULL,
  `COMM` decimal(7,2) DEFAULT NULL,
  `DEPTNO` decimal(2,0) DEFAULT '10',
  PRIMARY KEY (`EMPNO`),
  KEY `fk_EMP_DEPT` (`DEPTNO`),
  KEY `fk_EMP_EMP1` (`MGR`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


THIRD:INSERT VALUES INTO TABLES


We can use the following code to insert values into tables. In addition, we must keep the data we type in corresponding order of columns of the tables.


INSERT INTO dept2019284073   
VALUES   
(10 , "ACCOUNTING",  "LONDON" ),
(30  ,"SALES" , "LIVERPOOL" ), 
(40 , "OPERATIONS" , "STAFFORD" ), 
(50 , "MARKETING" , "LUTON" ), 
(20 , "RESEARCH"  ,"PRESTON")

The structure can be shown in the following two pictures.


c01ed9bb25e3484886ce7ee2f697b0c3.png

981bf6b0d89747b5a39a4cd7cba4c7c5.png


FORTH: USE THE COMMAND TO QUERY AND EDIT THE TABLES


  1. List all information about the employees.


SELECT * FROM dong2019284073.emp2019284073;

7da611538ec44818be2564aa0a420469.png


  1. List all information about the departments


SELECT * FROM dong2019284073.dept2019284073;

0949aae7402d499cb7e01f6e936cc4df.png


  1. List only the following information from the EMP table ( Employee name, employee number, salary, department number)
SELECT ENAME,EMPNO,SAL,DEPTNO FROM emp2019284073;

d0fbd5365e544e0a9583b52a3f0a014e.png



  1. List details of employees in departments 10 and 30.


SELECT * FROM emp2019284073 WHERE DEPTNO = 10 OR DEPTNO = 30;


5b5bb02baf664cb191d37868d949af1f.png


  1. List all the jobs in the EMP table eliminating duplicates.


SELECT DISTINCT JOB FROM emp2019284073;


06cf5a5b771045d78de4ad3dd273071f.png


  1. What are the names of the employees who earn less than £20,000?


SELECT ENAME FROM emp2019284073 WHERE SAL < 20000


dcdb0f232ddb4b1fb0480705e53c7ac9.png


What is the name, job title and employee number of the person in department 20 who earns more than £25000?


SELECT ENAME,JOB,EMPNO FROM emp2019284073 WHERE DEPTNO=20 AND SAL > 25000;

8344c5b418aa4a6781da00f96f6444af.png


相关文章
|
SQL 机器学习/深度学习 人工智能
从“写SQL”到“聊数据”:NL2SQL如何用自然语言解锁数据库?
本文系统性地阐述了自然语言转SQL(NL2SQL) 技术如何让非技术背景的业务分析师实现数据自助查询,从而提升数据驱动决策的效率与准确性。
从“写SQL”到“聊数据”:NL2SQL如何用自然语言解锁数据库?
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
2090 152
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
1436 156
|
SQL 关系型数据库 MySQL
Go语言数据库编程:使用 `database/sql` 与 MySQL/PostgreSQL
Go语言通过`database/sql`标准库提供统一数据库操作接口,支持MySQL、PostgreSQL等多种数据库。本文介绍了驱动安装、连接数据库、基本增删改查操作、预处理语句、事务处理及错误管理等内容,涵盖实际开发中常用的技巧与注意事项,适合快速掌握Go语言数据库编程基础。
1884 213
|
SQL 人工智能 Linux
SQL Server 2025 RC1 发布 - 从本地到云端的 AI 就绪企业数据库
SQL Server 2025 RC1 发布 - 从本地到云端的 AI 就绪企业数据库
1031 5
SQL Server 2025 RC1 发布 - 从本地到云端的 AI 就绪企业数据库
|
SQL 存储 监控
SQL日志优化策略:提升数据库日志记录效率
通过以上方法结合起来运行调整方案, 可以显著地提升SQL环境下面向各种搜索引擎服务平台所需要满足标准条件下之数据库登记作业流程综合表现; 同时还能确保系统稳健运行并满越用户体验预期目标.
625 6
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。
|
SQL Oracle 关系型数据库
Oracle数据库创建表空间和索引的SQL语法示例
以上SQL语法提供了一种标准方式去组织Oracle数据库内部结构,并且通过合理使用可以显著改善查询速度及整体性能。需要注意,在实际应用过程当中应该根据具体业务需求、系统资源状况以及预期目标去合理规划并调整参数设置以达到最佳效果。
882 8
|
SQL 人工智能 Java
用 LangChain4j+Ollama 打造 Text-to-SQL AI Agent,数据库想问就问
本文介绍了如何利用AI技术简化SQL查询操作,让不懂技术的用户也能轻松从数据库中获取信息。通过本地部署PostgreSQL数据库和Ollama模型,结合Java代码,实现将自然语言问题自动转换为SQL查询,并将结果以易懂的方式呈现。整个流程简单直观,适合初学者动手实践,同时也展示了AI在数据查询中的潜力与局限。
1650 8
|
SQL 人工智能 Linux
SQL Server 2025 RC0 发布 - 从本地到云端的 AI 就绪企业数据库
SQL Server 2025 RC0 发布 - 从本地到云端的 AI 就绪企业数据库
638 5