美文网首页
Database 面试题

Database 面试题

作者: Zihowe | 来源:发表于2017-09-07 06:10 被阅读142次

Database

mySQL:

设计场景

Foreign key:

A FOREIGN KEY is a key used to link two tables together
A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY KEY in another table.
比如我有个parent表,里面是parent的信息,还有个children表,里面是children信息。
这个parent表里面有个field,叫做children id,这个id是children表里的primary key,那这个id也是parent的表中的foreign key。因为children id 是其它表里的primary key。

fk 可以防止invalid data 插入到数据库中, 因为fk必须是一个其它表中的pk。

Left Join

The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match.

  • left join就是join两个表的内容,按照pk来join
  • 存在于left和right表的record如果有相同的pk,就join成一个新的record。
  • 如果left表的pk不存在于right表中,那么新的record就只存left表的record。
  • 如果right表的pk不存在于left表中,那么就忽略这条数据。

Inner Join

The INNER JOIN keyword selects records that have matching values in both tables.
inner join只会join两个表中具有相同pk的record

ETL (Extract, Transform, and Load)process

多对多的关系怎么设计(比如好友关系)

SQL 与NoSQL的区别

什么是Transaction

什么是ACID

什么是index

a database index is an auxiliary data structure which allows for faster retrieval of data stored in the database. They are keyed off of a specific column so that queries like "Give me all people with a last name of "Obama" are fast.

Postgres will automatically generate the indices for the primary key.

hash index
比如上面查询名字的例子,key是name field,values 是 pointers to database row。 但是hash 有个缺点是只能处理相等问题equality, 比如告诉我所有年龄小于45岁的人

B-tree index or B+ tree
In a B tree search keys and data stored in internal or leaf nodes. But in B+-tree data store only leaf nodes.
最常用的数据结构是B-trees, logarithmic time selections, insertions, deletions
For example, if we have an index on an age column, the value in the B-tree might be something like (34, 0x875900). 34 is the age and 0x875900 is a reference to the location of the data, rather than the data itself.

How and why are database indexes good and/or bad?

index 可以提高读取速度,但是会降低写入速度 因为每次插入新的数据,都要更新index的表。 另外index会产生额外的内存消耗。

database normalization

a process of organizing the columns (attributes) and tables (relations) of a relational database to reduce data redundancy and improve data integrity.
数据库规范化,就是整理数组库的表,减少数据重复,提高一致性的方法。

image.png

References:

http://noican.blog.51cto.com/4081966/1355316

相关文章

  • mybatis流程及工作原理

    mybatis面试题 http://www.2cto.com/database/201508/439359.htm...

  • Database 面试题

    Database mySQL: 设计场景 Foreign key: A FOREIGN KEY is a key ...

  • Database

    1 Insert 2 Delete 3 Update 4 Select 一个小项目

  • database

    存储过程高级篇 讲解了一些存储过程的高级特性,包括 cursor、schema、控制语句、事务等。数据库索引与事务...

  • database

    深入mysql: mysql与nosql: 关系型数据库和nosql数据库场景说明:关系型数据库把所有的数据都通过...

  • database

    1.查看所有databaseshow databases;+--------------------+| Data...

  • MySQL

    默认端口号3306 CREATE DATABASE ALTER DATABASE DROP DATABASE TI...

  • SQLite(简介)

    +++Categories = ["Database",]Tags = ["Database","SQLite",...

  • SQL

    A relational database is a database that organizes inform...

  • PG+PostGIS 使用笔记2

    1、创建、删除数据库create database database_name;drop database...

网友评论

      本文标题:Database 面试题

      本文链接:https://www.haomeiwen.com/subject/adubjxtx.html