Relational database jobs

Common difference MySQL three storage engines (InnoDB, MyISAM, MEMORY) of the (at least 5:00)?

Here Insert Picture Description

	1)InnoDB的优势在于提供了良好的事务处理、崩溃修复能力和并发控制。缺点是读写效率较差,占用的数据空间相对较大。(磁盘表,支持事务处理,InnoDB还支持外键)
	2)MyISAM是MySQL中常见的存储引擎,曾经是MySQL的默认存储引擎。MyISAM的表存储成3个文件。文件的名字与表名相同。拓展名为frm、MYD、MYI。(MyISAM:磁盘表,不支持事务,支持表级锁,B+Tree索引)
	3) MEMORY是MySQL中一类特殊的存储引擎。它使用存储在内存中的内容来创建表,而且数据全部放在内存中。每个基于MEMORY存储引擎的表实际对应一个磁盘文件。该文件的文件名与表名相同,类型为frm类型。该文件中只存储表的结构。而其数据文件,都是存储在内存中,因为它是把数据存到内存中,如果内存出现异常就会影响数据。如果重启或者关机,所有数据都会消失。因此,基于MEMORY的表的生命周期很短,一般是一次性的。(MEMORY内存表,不支持事务,表级锁,Hash索引)

Here Insert Picture Description

Four characteristics of database transactions and meanings

1, atomicity (Atomicity): all operations in a transaction is an integral database, either completed or not executed.
2. Consistency (Consistency): several concurrent transaction execution, the results of which must be consistent with certain order of serial execution.
3, isolation (Isolation): executing a transaction without interference from other transactions, the intermediate result of the transaction to other transaction execution to be transparent.
4, persistent (Durability): For any committed transaction, the transaction system must ensure that the change to the database is not lost, even if the database fails.

note: isolation level needs to be based on concurrency settings, be designed as a single-threaded database, it can prevent all of the thread-safety issues, naturally ensure that the isolated issue, but if so, then the efficiency will be very low. If two threads concurrently modify, will make trouble with each other, then you must use a lock mechanism to prevent concurrent modification of multiple threads. If two threads of concurrent queries, no thread safety issues.

Here Insert Picture Description
Here Insert Picture Description

What database three paradigms?

对于设计数据库提出了一些规范,这些规范被称为范式:
	 第一范式(1NF):列不可拆分 , 即无重复的域。 
		 指数据库表的每一列都是不可分割的基本数据项。
		 符合第一范式的特点就有:有主关键字、主键不能为空、主键不能重复,字段不可以再分。
	 第二范式(2NF):唯一标识 ,即拥有实体的唯一标识(eg: 身份证、id号等)。
		 指每个表必须有且仅有一个数据元素为主关键字(Primary key),其他数据元素与主关 键字一一对应。这种关系为函数依赖。
		 符合第二范式的特点就有:满足第一范式的前提下,消除部分函数依赖。
	第三范式(3NF):引用主键 ,即每列数据都与主键直接相关。
		 符合第三范式的特点就有:不存在非主属性对码的传递性依赖以及部分性依赖 
	note:三大范式只是一般设计数据库的基本理念,可以建立冗余较小、结构合理的数据库。(需求>性能>表结构)

Common database supports the SQL data types are there?

Here Insert Picture Description

The difference between SQL data type of varchar, and char?

	1)char是指固定长度的变量类型,char类型在查询时比varchar更有效率
	2)varchar是长度不固定的变量类型,varchar储存数据时不会浪费空间

SQL What are the constraints and explain the meaning (eg: NOT NULL, UNIQUE, etc.)?

Here Insert Picture Description

Even the table, even the table left and right even within the database table What is the difference?

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

How to implement paging in SQL statements to query?

SELECT * FROM TABLE_NAME LIMIT START, COUNT

What is SQL injection?

用户提交带有恶意的数据与SQL语句进行字符串方式的拼接,从而影响了SQL语句的语义,最终产生数据泄露的现象
	
	如何防止SQL注入?
	SQL语句参数化(使用%s占位符来传递参数)

How to optimize the database query efficiency (refer to the explanation)?

	1). 储存引擎选择:如果数据表需要事务处理,应该考虑使用 InnoDB,因为它完全符合 ACID 特性。如果不需要事务处理,使用默认存储引擎 MyISAM 是比较明智的
	2). 对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引
	3). 应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描
	4). 应尽量避免在 where 子句中使用 != 或 <> 操作符,否则将引擎放弃使用索引而进行全表扫描
	5). 应尽量避免在 where 子句中使用 or 来连接条件,如果一个字段有索引,一个字段没有索引,将导致引擎放弃使用索引而进行全表扫描6). Update 语句,如果只更改 1、2 个字段,不要 Update 全部字段,否则频繁调用会引起明显的性能消耗,同时带来大量日志7). 对于多张大数据量(这里几百条就算大了)的表 JOIN,要先分页再 JOIN,否则逻辑读会很高,性能很差。

SQL query statement

Here Insert Picture Description

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Update Takasaki date of birth as 1996-12-12.

Here Insert Picture Description

Statistics Total number of employees

Here Insert Picture Description

Statistical entry time over two years, employee name

Here Insert Picture Description

Find all the information at the latest recruits

Here Insert Picture Description

All information query earliest recruits

Here Insert Picture Description

Query results in the student's name between 85-90 minutes, course names and grades (between and / inner join)
Advanced query highest math scores of students and student name (max)
Query Jun elective courses name (distinct)
Released seven original articles · won praise 0 · Views 82

Guess you like

Origin blog.csdn.net/qq_43210924/article/details/103983410