本段 701 题 | 来源:fullstack + general + design | 知识点:数据库
1. 如何避免SQL注入(SQL Injection)?
- 知识点: 数据库 / 安全 / 编程语言基础 (主题: sql, security, java, jdbc;标签: SQL Injection, PreparedStatement, Input Validation)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6965ea17fa809e6d3887b423 | 官方: 是 | 付费: 否
答案:
答案1.PreparedStatement(预处理语句,简单又有效的方法)
2.使用正则表达式(Regular Expression)过滤传入的参数
3.字符串过滤(String Filtering)
4.JSP(Java Server Pages)中调用该函数检查是否包函非法字符
5.JSP(Java Server Pages)页面判断代码
2. Business Analyst(业务分析师,BA)需要会编程吗?通常学哪些语言?
- 知识点: 数据库 / 编程语言基础 / 行为与软技能 (主题: python, r, sql, databases, business-analysis;标签: business-analyst, programming, python, sql)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6967574efa809e6d38a7e7d0 | 官方: 是 | 付费: 否
答案:
答案不一定要像工程师那样深,但会写代码能显著提升数据处理与验证效率。常见语言包括Python(蟒蛇语言)/R(统计语言),用于清洗、分析与自动化;同时建议掌握SQL(结构化查询语言)进行数据库查询与数据抽取,必要时了解常见数据库(如MySQL、Oracle、MongoDB)。
3. 为什么BA(业务分析师)需要掌握数据库与SQL(结构化查询语言)?
- 知识点: 数据库 / 行为与软技能 (主题: sql, databases, business-analysis;标签: business-analyst, database, sql)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6967574efa809e6d38a7e7e5 | 官方: 是 | 付费: 否
答案:
答案很多关键业务数据存储在数据库中,BA(业务分析师)需要用SQL(结构化查询语言)快速获取、验证与追踪指标口径,支持需求分析与假设检验。掌握基本查询、聚合、更新等能力,有助于独立完成数据核对、定位数据异常,并与工程/数据团队更高效沟通。
4. 缓解过拟合(Overfitting)的方法?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: deep-learning, overfitting, dropout, regularization, batch-normalization, bagging;标签: Overfitting, Regularization, Dropout, BatchNorm)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69688dcfbc0b9904d6b6bb49 | 官方: 是 | 付费: 否
答案:
答案① Dropout(随机丢弃);② 加L1/L2正则化(Regularization);③ BatchNormalization(批量归一化,Batch Normalization);④ 网络bagging(袋装法)
5. CNN(卷积神经网络,Convolutional Neural Network)是什么?关键是那些?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: deep-learning, cnn, convolution, pooling, batch-normalization, data-augmentation;标签: CNN, Convolution, Pooling, BatchNorm)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69688dcfbc0b9904d6b6bb50 | 官方: 是 | 付费: 否
答案:
答案CNN(Convolutional Neural Network)是什么,网上一大堆解释,其关键层有:① 输入层(Input Layer),对数据去均值,做data augmentation(数据增强)等工作。② 卷积层(Convolutional Layer),局部关联抽取feature(特征)。③ 激活层(Activation Layer),非线性变化。④ 池化层(Pooling Layer),下采样。⑤ 全连接层(Fully Connected Layer),增加模型的非线性,⑥ 高速通道(Highway),快速连接。⑦ BN层(Batch Normalization Layer),缓解梯度弥散。
6. 写出 SQL(Structured Query Language):向 leaderboards 表插入一条玩家得分记录。
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, database, system-design;标签: SQL, insert, leaderboard)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696dd4b8e6ae93548e947d84 | 官方: 是 | 付费: 否
答案:
答案原文给出的示例:INSERT INTO leaderboards (leaderboard_id, score, created_at, game_id, player_id) VALUES ("apex_legends", 1, "2050-08-22", "1", "42");
7. 写出 SQL(Structured Query Language):更新某个玩家的分数(在原分数基础上 +1)。
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, database;标签: SQL, update, leaderboard)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696dd4b8e6ae93548e947d88 | 官方: 是 | 付费: 否
答案:
答案原文给出的示例:UPDATE leaderboards SET score = score + 1 WHERE player_id = '42';
8. SQL(Structured Query Language)中 INNER JOIN(内连接)与 OUTER JOIN(外连接)的区别是什么?
- 知识点: 数据库 (主题: sql;标签: join)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d26 | 官方: 是 | 付费: 否
答案:
答案- INNER JOIN(内连接):只返回两表满足 join 条件的匹配行。
- OUTER JOIN:除了匹配行外,还会保留某一侧未匹配的行,并用 NULL 补齐另一侧字段。常见有 LEFT/RIGHT/FULL OUTER JOIN。
9. SQL(Structured Query Language)中 UNION 与 UNION ALL 的区别是什么?
- 知识点: 数据库 (主题: sql;标签: set-operators)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d29 | 官方: 是 | 付费: 否
答案:
答案- UNION:合并结果并去重(通常会有额外排序/去重开销)。
- UNION ALL:直接合并结果,不去重,通常更快。
10. 什么是主键(primary key)?
- 知识点: 数据库 (主题: sql;标签: keys, constraints)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d2d | 官方: 是 | 付费: 否
答案:
答案主键(primary key)是一列或多列的组合,用于唯一标识表中的每一行:
- 必须唯一且通常不允许为 NULL。
- 常被其他表用作外键引用,建立关系。
- 数据库会为主键建立索引(实现依数据库而定)。
11. 什么是子查询(subquery)?
- 知识点: 数据库 (主题: sql;标签: subquery)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d30 | 官方: 是 | 付费: 否
答案:
答案子查询(subquery)是嵌套在另一个 SQL(Structured Query Language)语句内部的查询,可用于:
- 在 WHERE/HAVING 中做过滤(如 IN、比较运算)。
- 在 SELECT 中生成派生列(标量子查询)。
- 在 FROM 中作为派生表(inline view)。
12. SQL(Structured Query Language)中视图(view)与表(table)的区别是什么?
- 知识点: 数据库 (主题: sql;标签: view)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d33 | 官方: 是 | 付费: 否
答案:
答案- 表(table):物理存储数据的结构,数据持久化在磁盘/存储引擎中。
- 视图:由查询定义的“虚拟表”,通常不存储数据本体(少数数据库支持物化视图)。优点是封装复杂查询、简化权限与复用。
13. 写一个 SQL(Structured Query Language)示例:根据条件过滤记录。
- 知识点: 数据库 (主题: sql;标签: where, filter)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d3e | 官方: 是 | 付费: 否
答案:
答案使用 WHERE(WHERE)子句过滤行。示例:查询工资大于 10,000 的员工。
SELECT *
SELECT *
FROM employees
FROM employees
WHERE salary > 10000;
WHERE salary > 10000;
14. 写一个 SQL(SQL)示例:按升序/降序排序记录。
- 知识点: 数据库 (主题: sql;标签: order-by, sort)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d4f | 官方: 是 | 付费: 否
答案:
答案使用 ORDER BY(ORDER BY):默认升序 ASC(ASC),降序用 DESC(DESC)。
-- 升序
SELECT * FROM employees ORDER BY salary ASC;
SELECT * FROM employees ORDER BY salary ASC;
-- 降序
SELECT * FROM employees ORDER BY salary DESC;
SELECT * FROM employees ORDER BY salary DESC;
15. 写一个 SQL(SQL)示例:对列做聚合(sum/avg/count 等)。
- 知识点: 数据库 (主题: sql;标签: aggregation, group-by)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d52 | 官方: 是 | 付费: 否
答案:
答案聚合函数(Aggregate Function)常与 GROUP BY(GROUP BY)搭配。示例:统计每个部门的平均工资与人数。
SELECT department_id,
SELECT department_id,
AVG(salary) AS avg_salary,
AVG(salary) AS avg_salary,
COUNT(*) AS headcount
COUNT(*) AS headcount
FROM employees
FROM employees
GROUP BY department_id;
GROUP BY department_id;
16. 写一个 SQL(SQL)示例:根据共同列连接两张表。
- 知识点: 数据库 (主题: sql;标签: join)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d5f | 官方: 是 | 付费: 否
答案:
答案示例:员工表通过 department_id(department_id)关联部门表。
SELECT e.employee_id, e.name, d.department_name
SELECT e.employee_id, e.name, d.department_name
FROM employees e
FROM employees e
JOIN departments d
JOIN departments d
ON e.department_id = d.department_id;
ON e.department_id = d.department_id;
17. 写一个 SQL(SQL)示例:用逻辑运算符(Logical Operator)按多个条件筛选记录。
- 知识点: 数据库 (主题: sql;标签: and-or-not, filter)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f2501120fcc1591184d6d | 官方: 是 | 付费: 否
答案:
答案使用 AND/OR/NOT(AND/OR/NOT)组合条件,必要时加括号明确优先级。
SELECT *
SELECT *
FROM employees
FROM employees
WHERE department_id = 10
WHERE department_id = 10
AND salary >= 8000
AND salary >= 8000
AND status != 'inactive';
AND status != 'inactive';
18. 什么是 SQL(SQL)?它主要用来做什么?
- 知识点: 数据库 (主题: sql;标签: SQL, RDBMS)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f345a120fcc15911a6e36 | 官方: 是 | 付费: 否
答案:
答案SQL(Structured Query Language)是用于与关系型数据库(Relational Database)交互的语言,主要用于:查询(SELECT)、新增/修改/删除(INSERT/UPDATE/DELETE)、定义结构(建表/索引)、以及权限与事务相关操作。面试中可以补一句:熟悉 join(JOIN)、group by(GROUP BY)、having(HAVING)、窗口函数(Window Function)(如果会)。
19. 为什么需要使用 DBMS(DBMS)?它的主要优势有哪些?
- 知识点: 数据库 (主题: dbms, database;标签: DBMS, Basics)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f35a4120fcc15911a940a | 官方: 是 | 付费: 否
答案:
答案DBMS(Database Management System)的优势包括:通过认证/访问控制/加密提升数据安全;利用索引(Index)与优化策略实现更快的数据访问;提供更友好的管理方式;通过约束(Constraint)与事务(Transaction)支持保证一致性与完整性;支持并发访问(Concurrent Access)便于协作;并提供备份与恢复机制减少数据丢失风险,从而提升决策与运营效率。
20. SQL(SQL)中 UNION(UNION)和 UNION ALL(UNION ALL)有什么区别?性能上有什么影响?
- 知识点: 数据库 (主题: sql;标签: UNION, UNION ALL, Performance)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f35a4120fcc15911a940f | 官方: 是 | 付费: 否
答案:
答案UNION(并集) 会在合并结果集后去重,而 UNION ALL(全并集) 会保留所有行不去重。两者要求参与合并的 SELECT 语句列数与数据类型匹配。由于 UNION 通常需要额外的去重处理(常伴随排序/哈希等操作),性能开销往往高于 UNION ALL;而 UNION ALL 只是拼接结果,通常更快。
21. 什么是数据独立性(Data Independence)?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: dbms, data-modeling;标签: 数据独立性, 三层架构, 解耦)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cda120fcc15911c6a29 | 官方: 是 | 付费: 否
答案:
答案数据独立性指数据库的结构(模式/存储方式)变化时,尽量不影响上层应用程序。它体现了“数据库三层架构(物理/逻辑/视图)”(Three-Schema Architecture)的解耦思想,使得数据库可以在不改应用的情况下进行结构优化或存储调整,从而提升系统可维护性与演进能力。
22. DBMS 中的 ER(实体-关系)(Entity-Relationship)模型是什么?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: dbms, data-modeling;标签: ER模型, 概念建模, 主外键)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d33 | 官方: 是 | 付费: 否
答案:
答案ER模型用于数据库概念建模,用“实体(Entity)”“属性(Attribute)”“关系(Relationship)”表达业务对象及其联系,并用基数约束(Cardinality Constraint)描述一对一/一对多/多对多关系。它常用于需求到表结构设计的过渡:先画ER图(ER Diagram)澄清业务,再映射为关系表、主键/外键(Primary Key/Foreign Key)与约束。
23. DBMS 中的事务(Transaction)是什么?
- 知识点: 数据库 (主题: dbms, transactions;标签: 事务, 回滚, 一致性)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d37 | 官方: 是 | 付费: 否
答案:
答案事务是一组作为整体执行的数据库操作单元(如插入、更新、删除),要么全部成功提交(Commit),要么失败回滚(Rollback),确保数据一致性与可靠性。事务通常通过 ACID(原子性、一致性、隔离性、持久性)(Atomicity, Consistency, Isolation, Durability)来描述其正确性保证。
24. DBMS 中什么是标量函数(Scalar Function)?
- 知识点: 数据库 (主题: dbms, sql;标签: 标量函数, SQL函数, 逐行计算)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d4c | 官方: 是 | 付费: 否
答案:
答案标量函数对“单个值”进行计算并返回“单个结果”,通常在每一行上逐行生效。常见类型包括数学函数(ABS、ROUND)、字符串函数(CONCAT、SUBSTRING)、日期函数(NOW、DATEADD)。与聚合函数(Aggregate Function)不同,聚合函数对多行汇总后返回一个结果(如SUM/COUNT)。
25. 什么是数据库规范化(Normalization)?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: dbms, data-modeling;标签: Normalization, 数据冗余, 异常避免)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d59 | 官方: 是 | 付费: 否
答案:
答案规范化是把数据表按规则拆分与组织,减少冗余、避免插入/更新/删除异常,并提升数据一致性与可维护性。它通过一系列范式(Normal Form)(1NF/2NF/3NF等)约束表结构与依赖关系。面试可补充:规范化提升一致性,但过度拆分可能增加JOIN(连接)成本,需要与性能、查询模式权衡。
26. DBMS 中 UNIQUE 和 DISTINCT 有什么区别?
- 知识点: 数据库 (主题: dbms, sql;标签: UNIQUE, DISTINCT, 去重)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d61 | 官方: 是 | 付费: 否
答案:
答案UNIQUE 通常作为“约束(Constraint)”用于表结构层面,保证某列(或列组合)在全表中不重复,违反会报错;DISTINCT 用于查询层面,在SELECT结果中去重返回唯一值。简单说:UNIQUE 约束数据写入,DISTINCT 影响查询结果。
27. DBMS 的数据抽象层次有哪些?
- 知识点: 数据库 / 系统设计/架构 (主题: dbms, architecture;标签: 数据抽象, 三层架构, 视图)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d72 | 官方: 是 | 付费: 否
答案:
答案三层:①物理层(Physical)——数据如何在磁盘/存储上组织与访问(文件结构、索引等);②逻辑层(Logical)——数据库整体逻辑结构与关系模型(表、关系、约束);③视图/外部层(View/External)——不同用户或应用看到的定制化视图与子集。抽象的目的就是隐藏复杂细节、隔离变化、提升安全与可维护性。
28. DBMS 中如何创建对象(如表、视图、索引等)?
- 知识点: 数据库 (主题: dbms, sql;标签: DDL, CREATE, 表/视图/索引)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d7c | 官方: 是 | 付费: 否
答案:
答案通过DDL(Data Definition Language)语句创建数据库对象(Database Object):CREATE TABLE(创建表) 创建表并定义列、主键/外键(Primary Key/Foreign Key)与约束(Constraint);CREATE VIEW(创建视图) 创建视图(View);CREATE INDEX(创建索引) 创建索引(Index);还可创建存储过程(Stored Procedure)/触发器(Trigger)等。面试回答可强调:创建表时要考虑数据类型(Data Type)、约束、索引与访问模式(Access Pattern);对象变更通常用 ALTER;删除对象用 DROP。
29. DBMS(Database Management System) 中什么是聚合函数(Aggregate Function)?
- 知识点: 数据库 (主题: dbms, sql;标签: 聚合函数, GROUP BY, 统计分析)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d8b | 官方: 是 | 付费: 否
答案:
答案聚合函数(Aggregate Function)对一组行进行汇总并返回单个结果,常与 GROUP BY(分组)搭配用于统计分析。常见聚合函数包括 COUNT、SUM、AVG、MIN、MAX。面试可补充:聚合函数会改变结果粒度;与标量函数(Scalar Function)区别在于标量函数逐行计算不聚合。
30. 什么是 SQL(Structured Query Language)?
- 知识点: 数据库 (主题: sql;标签: SQL, RDBMS, ANSI)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69718df9120fcc159151281d | 官方: 是 | 付费: 否
答案:
答案SQL 是 “Structured Query Language(结构化查询语言)” 的缩写,用于与数据库进行通信。按照 ANSI(American National Standards Institute)的定义,SQL 是关系型数据库管理系统(RDBMS)的标准查询语言,用于维护数据库,并对不同类型的数据执行各种数据操作(data manipulation)。从本质上说,它是一种数据库语言,可用于创建和删除数据库,也可以用于获取和修改表中的行,以及完成许多其他操作。
31. 你如何理解字符处理函数(Character Manipulation function)?
- 知识点: 数据库 / 算法与数据结构 (主题: sql;标签: string-functions, sql-basics)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6971d9241f88a3acd7144f31 | 官方: 是 | 付费: 否
答案:
答案字符处理函数(Character Manipulation function)用于对字符数据类型(Character Data Type)进行操作。
一些字符处理函数(Character Manipulation function)包括:
UPPER:将字符串转换为大写。
语法(Syntax):
UPPER('string')示例:
SELECT UPPER('demo string') from String;输出:
DEMO STRINGLOWER:将字符串转换为小写。
语法(Syntax):
LOWER('STRING')示例:
SELECT LOWER ('DEMO STRING') from String输出:
demo stringINITCAP(Initial Capitalization):将字符串(String)的首字母转换为大写,其余字符保持小写。
语法(Syntax):
Initcap('STRING')示例(Example):
SELECT Initcap('DATASET') from String输出(Output):
DatasetCONCAT(Concatenation):用于连接两个字符串(String)。
语法(Syntax):
CONCAT('str1','str2')示例(Example):
SELECT CONCAT('Data','Science') from String输出(Output):
Data ScienceLENGTH(Length):用于获取字符串(String)的长度。
语法(Syntax):
LENGTH('String')示例(Example):
SELECT LENGTH('Hello World') from String输出(Output):
11
32. 什么是 AUTO_INCREMENT(Auto Increment)?
- 知识点: 数据库 (主题: sql;标签: constraints, auto-increment)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6971d9241f88a3acd7144f35 | 官方: 是 | 付费: 否
答案:
答案AUTO_INCREMENT(Auto Increment) 在 SQL(Structured Query Language)中用于在向表中插入新记录时自动生成一个唯一编号(Unique Number)。
由于主键(Primary Key)对每条记录都是唯一的,我们将该主字段设置为 AUTO_INCREMENT(Auto Increment) 字段,使其在插入新记录时自动递增。
AUTO-INCREMENT(Auto Increment) 的值默认从 1 开始,每插入一条新记录就递增 1。
语法(Syntax):
CREATE TABLE Employee(
CREATE TABLE Employee(
Employee_id int NOT NULL AUTO-INCREMENT,
Employee_id int NOT NULL AUTO-INCREMENT,
Employee_name varchar(255) NOT NULL,
Employee_name varchar(255) NOT NULL,
Employee_designation varchar(255),
Employee_designation varchar(255),
Age int,
Age int,
PRIMARY KEY (Employee_id)
PRIMARY KEY (Employee_id)
)
33. 什么是 COALESCE 函数(COALESCE function)?
- 知识点: 数据库 (主题: sql;标签: functions, null-handling, coalesce)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6971d9241f88a3acd7144f3d | 官方: 是 | 付费: 否
答案:
答案COALESCE 函数(COALESCE function)接收一组输入,并返回第一个非 NULL 的值。
语法(Syntax):
COALESCE(val1,val2,val3,....,nth val)示例:
SELECT COALESCE(NULL, 1, 2, 'MYSQL')输出:
1
34. SQL 中的 DDL 和 DML 命令是什么?它们有何不同?
- 知识点: 数据库 (主题: sql, database;标签: DDL, DML, SQL)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977264ba39c9c5c3a89f65f | 官方: 是 | 付费: 否
答案:
答案DDL(Data Definition Language)用于定义/修改数据库结构(database structure),如 CREATE、ALTER、DROP、TRUNCATE、RENAME;DML(Data Manipulation Language)用于操作数据(data manipulation),如 INSERT、UPDATE、DELETE。常见区别是 DDL 更偏结构层、影响对象定义;DML 更偏数据层,常配合 WHERE 精确定位受影响记录,并与事务控制(transaction control)密切相关。
35. SQL 中索引(index)的目的是什么?为什么有用?
- 知识点: 数据库 (主题: sql, indexing;标签: Index, Query Performance)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977264ba39c9c5c3a89f678 | 官方: 是 | 付费: 否
答案:
答案索引是一种加速数据检索的数据结构(data structure),常用于提升 WHERE 过滤、JOIN 关联、ORDER BY 排序等操作效率,减少全表扫描(full table scan)。它通过额外存储键值与行定位信息来换取查询性能,但也会带来写入成本(INSERT/UPDATE/DELETE 需要维护索引)与额外存储开销,因此需要在读写比例与查询模式间做权衡。
36. SQL 中 Left Outer Join 和 Right Outer Join 是什么?
- 知识点: 数据库 (主题: sql, joins;标签: LEFT JOIN, RIGHT JOIN, Outer Join)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977264ba39c9c5c3a89f67c | 官方: 是 | 付费: 否
答案:
答案外连接(outer join)用于返回一侧表的全部行,并匹配另一侧表的相关行;不匹配部分用 NULL 填充。LEFT OUTER JOIN(左外连接)返回左表全部行 + 右表匹配行;RIGHT OUTER JOIN(右外连接)返回右表全部行 + 左表匹配行。实际开发中常用 LEFT JOIN,通过调整表顺序即可表达大多数需求。
37. 什么是数据库 Schema(架构)?它是如何工作的?
- 知识点: 数据库 (主题: database, schema;标签: Schema, DDL, Constraints)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977264ba39c9c5c3a89f681 | 官方: 是 | 付费: 否
答案:
答案数据库 Schema(数据库架构)是数据库的逻辑蓝图,定义表、字段、关系、约束、视图等结构与组织方式。它由 DBMS 通过 DDL 创建与维护,帮助开发者按业务需求建模数据,并通过约束与关系保证数据一致性、完整性与可维护性。对 Schema 的变更通常通过 ALTER 等 DDL 操作完成。
38. 什么是存储过程(Stored Procedure)?
- 知识点: 数据库 / 安全 (主题: sql, database;标签: Stored Procedure, Performance, Security)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977264fa39c9c5c3a89fa31 | 官方: 是 | 付费: 否
答案:
答案存储过程(Stored Procedure)是保存在数据库中的可复用程序单元,通常由一组预编译的 SQL 与控制逻辑组成,可接收参数并返回结果。它的优势包括减少网络往返、提高执行效率、集中封装业务规则、通过权限控制提升安全性,并便于复用与统一维护;但也可能带来数据库层耦合与版本管理复杂度。
39. SQL 中的大小写操作函数(Case Conversion Functions)是什么意思?常见类型有哪些?
- 知识点: 数据库 (主题: sql;标签: SQL Functions, UPPER, LOWER, INITCAP)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69772680a39c9c5c3a8a1261 | 官方: 是 | 付费: 否
答案:
答案大小写操作函数用于把字符串转换为大写/小写/首字母大写等,便于格式化输出与不区分大小写的匹配。常见函数:UPPER() 转大写、LOWER() 转小写;部分数据库支持 INITCAP() 或等价函数把每个单词首字母大写,其余小写。实际使用时需结合具体数据库方言(Database Dialect)(Oracle/PostgreSQL/MySQL 等)确认函数名与行为。
40. 解释 SQL 的字符操作函数(Character Manipulation Functions),并列举常见类型。
- 知识点: 数据库 / 算法与数据结构 (主题: sql;标签: SQL Functions, String, Data Cleaning)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69772680a39c9c5c3a8a1278 | 官方: 是 | 付费: 否
答案:
答案字符操作函数用于拼接、截取、查找与替换字符串等,常用于清洗与格式化数据。常见函数包括:CONCAT()/||(拼接 Concatenation)、SUBSTR()/SUBSTRING()(截取子串)、LENGTH()/LEN()(长度)、INSTR()/CHARINDEX()(查找位置)、TRIM()/LTRIM()/RTRIM()(去除空格或指定字符)、REPLACE()(替换)、LPAD()/RPAD()(补齐 Padding)。不同数据库函数名略有差异,但语义相近。
41. 什么是数据库 Schema(数据库架构)?
- 知识点: 数据库 (主题: databases, sql;标签: Schema, DDL, Constraints)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 697729f6a39c9c5c3a8ab1fd | 官方: 是 | 付费: 否
答案:
答案数据库 Schema(架构)是数据库的逻辑蓝图,定义了数据如何被组织与约束,包括表/视图、字段类型、主外键关系、索引(Index)、约束(Constraint)(NOT NULL/UNIQUE/CHECK)等。Schema 帮助团队统一数据结构并保证一致性与可维护性;当业务变化时,可通过 DDL(Data Definition Language)(如 CREATE/ALTER)对 Schema 演进,但需要配合迁移策略以降低对线上业务的影响。
42. 数据库索引(Index)如何提高查询性能?
- 知识点: 数据库 (主题: databases, sql, indexing;标签: Index, B-Tree, Performance)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69772f73a39c9c5c3a8b97c3 | 官方: 是 | 付费: 否
答案:
答案索引是额外的数据结构(如 B-Tree/Hash),为某些列建立有序或可快速定位的“目录”,从而减少全表扫描(Full Table Scan)与磁盘 I/O(Input/Output)。它对 WHERE 过滤、JOIN、ORDER BY、GROUP BY 常有显著收益。代价是写入更慢(INSERT/UPDATE/DELETE 需维护索引)与占用更多存储,因此要对高选择性、常查询列建索引,并避免滥用。
43. 关系数据库(Relational Database)和 NoSQL 数据库有什么区别?
- 知识点: 数据库 / 系统设计/架构 / 编程语言基础 (主题: databases, sql, nosql;标签: RDBMS, NoSQL, ACID, Scalability)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69772f97a39c9c5c3a8bc029 | 官方: 是 | 付费: 否
答案:
答案关系型数据库使用表与固定 Schema,支持 SQL 与强一致事务(ACID Transaction),适合复杂关系与强约束的数据模型;NoSQL(Not Only SQL)通常采用文档/键值/列式/图等模型,Schema 更灵活,强调水平扩展与高吞吐,很多场景用最终一致性(Eventual Consistency)换性能与可用性。选型看需求:强事务与复杂查询偏关系型;海量数据、灵活结构、低延迟与高扩展偏 NoSQL。
44. 解释数据库事务中 ACID 属性的概念。
- 知识点: 数据库 (主题: databases, transactions;标签: ACID, Transaction, Isolation Level)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69772f97a39c9c5c3a8bc03e | 官方: 是 | 付费: 否
答案:
答案ACID 指事务的四个关键保证:Atomicity 原子性(要么全部成功要么全部回滚);Consistency 一致性(事务前后都满足约束与规则);Isolation 隔离性(并发事务互不干扰,表现像串行执行,隔离级别决定强弱);Durability 持久性(提交后的结果在故障后仍可恢复)。它们共同确保事务可靠,但通常会带来性能与并发成本。
45. 数据库中的索引(Index)是什么,它们如何提高查询性能?
- 知识点: 数据库 (主题: databases, indexing;标签: Index, Composite Index, Covering Index)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69772fa3a39c9c5c3a8bceba | 官方: 是 | 付费: 否
答案:
答案索引是为列建立的快速查找结构,帮助数据库更快定位行并减少全表扫描。典型 B-Tree 索引适合范围查询与排序,Hash 索引适合等值查询。索引能加速过滤、连接与排序,但会增加写入成本与存储占用,因此应根据查询模式(WHERE/JOIN/ORDER BY)与选择性来设计复合索引(Composite Index),并关注覆盖索引(Covering Index)与回表开销。
46. 解释数据库中主键(Primary Key)和外键(Foreign Key)之间的区别。
- 知识点: 数据库 (主题: databases, sql;标签: Primary Key, Foreign Key, Referential Integrity)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69772fa9a39c9c5c3a8bd5b4 | 官方: 是 | 付费: 否
答案:
答案主键唯一标识表中每条记录,必须唯一且通常不可为空,用于高效定位行;外键引用另一张表的主键(或唯一键)来建立表间关系并保证引用完整性(Referential Integrity)。一个表通常只有一个主键(可由多列组成复合主键 Composite Primary Key),但可以有多个外键。外键约束能防止“孤儿记录”,并可定义级联更新/删除规则。
47. 你能解释一下数据库事务(Transaction)中的 ACID 属性吗?
- 知识点: 数据库 / 系统设计/架构 (主题: databases, transactions;标签: ACID, Isolation, Consistency)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69773021a39c9c5c3a8c6a3a | 官方: 是 | 付费: 否
答案:
答案ACID 分别是原子性(Atomicity)(全成全败)、一致性(Consistency)(遵守约束与规则)、隔离性(Isolation)(并发互不干扰,隔离级别控制脏读/不可重复读/幻读)、持久性(Durability)(提交后可恢复)。在分布式或高吞吐场景下,部分系统会在一致性、可用性与性能之间做权衡,因此需要根据业务选择合适的事务模型(Transaction Model)与一致性级别(Consistency Level)。
48. 什么是 DBMS?
- 知识点: 数据库 / 安全 (主题: databases, fundamentals;标签: DBMS, Transactions, Security)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977327aa39c9c5c3a8d61ad | 官方: 是 | 付费: 否
答案:
答案DBMS(Database Management System)是用于创建、存储、查询与管理数据库的软件系统,提供数据定义(Schema Definition)、数据操作(CRUD)、索引与查询优化、事务(Transaction)与并发控制(Concurrency Control)、安全与权限、备份恢复等能力。它让应用以更可靠一致的方式访问数据,常见关系型 DBMS 有 MySQL、PostgreSQL、Oracle 等。
49. 主键和外键有什么区别?
- 知识点: 数据库 (主题: databases, sql;标签: Primary Key, Foreign Key, Referential Integrity)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69773280a39c9c5c3a8d6926 | 官方: 是 | 付费: 否
答案:
答案主键(Primary Key)用于唯一标识表中的每条记录,必须唯一且通常不可为空;外键(Foreign Key)引用另一张表的主键(或唯一键)来建立表间关系并保证引用完整性(Referential Integrity)。一个表通常只有一个主键(可为复合主键),但可以有多个外键。外键约束可防止产生孤儿记录,并可配置级联更新/删除。
50. 什么是 Schema(模式)?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: databases, data-modeling;标签: Schema, Constraints, Migration)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69773296a39c9c5c3a8d83b8 | 官方: 是 | 付费: 否
答案:
答案Schema 是数据库的逻辑结构定义,描述有哪些表、列、数据类型、约束(主键/外键/唯一/非空)、索引以及表之间关系等,相当于数据库的“蓝图”。它帮助 DBMS 保证数据一致性与可维护性,也为查询优化与权限管理提供基础。实际变更 Schema 通常需要迁移策略与版本管理,避免影响线上业务。
51. 外连接(outer join)和内连接(inner join)有什么区别?
- 知识点: 数据库 (主题: sql, databases;标签: Inner Join, Outer Join, NULL)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977336ca39c9c5c3a8da6da | 官方: 是 | 付费: 否
答案:
答案INNER JOIN 只返回两表在连接条件上“匹配”的行(交集);OUTER JOIN 除了匹配行,还会保留一侧或两侧“不匹配”的行,并用 NULL 补齐缺失列。常见外连接:LEFT OUTER JOIN 保留左表全部行,RIGHT OUTER JOIN 保留右表全部行,FULL OUTER JOIN 两边都保留。选择原则:只要匹配用 inner;需要保留未匹配记录用 outer。
52. 什么是数据库管理系统(DBMS)?
- 知识点: 数据库 / 安全 (主题: databases, fundamentals;标签: DBMS, Transactions, Security)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977336da39c9c5c3a8da6e8 | 官方: 是 | 付费: 否
答案:
答案DBMS 是用于创建、存储、查询与管理数据库的软件系统,提供数据定义(Schema Definition)、数据操作(CRUD)、索引与查询优化、事务(Transaction)与并发控制(Concurrency Control)、安全与权限、备份恢复等能力。它为用户和应用提供统一的数据访问平台,常见产品包括 MySQL、PostgreSQL、Oracle 等;根据组织方式可分集中式、分布式、关系型、面向对象等类型。
53. 解释 SQL 中的主键(primary key)和外键(foreign key)。
- 知识点: 数据库 (主题: sql, databases;标签: Primary Key, Foreign Key, Referential Integrity)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 6977336da39c9c5c3a8da6f4 | 官方: 是 | 付费: 否
答案:
答案主键(Primary Key)用于唯一标识表中的每条记录,必须唯一且通常不可为 NULL;外键(Foreign Key)用于引用另一张表的主键(或唯一键)来建立表间关系并保证引用完整性(Referential Integrity)。包含主键的表常称父表(Parent Table),包含外键的表称子表(Child Table)。外键约束可防止孤儿记录,并可配置级联更新/删除,确保跨表数据一致。
54. DCL 语言有什么用途?
- 知识点: 数据库 / 安全 (主题: sql, security;标签: dcl, grant, revoke)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 697825c0a39c9c5c3ab58c69 | 官方: 是 | 付费: 否
答案:
答案DCL(Data Control Language)用于数据库权限与访问控制管理,典型命令包括 GRANT 与 REVOKE,用来授予或收回用户/角色对表、视图、过程等对象的权限(如 SELECT/INSERT/UPDATE/DELETE)。它保障数据安全与最小权限原则。
55. 数据库中的属性(Attribute)是什么?
- 知识点: 数据库 (主题: databases;标签: attribute, entity)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 697825cca39c9c5c3ab59928 | 官方: 是 | 付费: 否
答案:
答案在数据库中,属性(Attribute)通常指实体的特征,对应关系表中的一列(column)。每个属性有名称与数据类型(data type),用于描述实体的某个维度;一行(row/tuple)表示某个实体实例在各属性上的具体取值。
56. DBMS 有哪些优势?
- 知识点: 数据库 (主题: dbms, databases;标签: dbms, advantages)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 697825d1a39c9c5c3ab59e2a | 官方: 是 | 付费: 否
答案:
答案DBMS 的优势在于统一管理数据与权限,并提供可靠的数据一致性与恢复能力。常见优点包括:减少冗余、提升一致性、支持并发访问、权限控制、备份与恢复、以及通过约束(主键(primary key)/外键(foreign key)/检查约束(check constraint))保障数据质量。
- 多用户并发与事务管理
- 冗余控制与一致性保障
- 权限控制与审计
- 备份与恢复
- 完整性约束与数据共享
57. SQL 注释有哪些写法?
- 知识点: 数据库 (主题: sql;标签: sql, comments)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 697825d6a39c9c5c3ab5a2f6 | 官方: 是 | 付费: 否
答案:
答案SQL 注释用于在脚本中添加说明,不影响执行。常见两类:单行注释使用 --(部分数据库也支持 #),多行注释使用 / ... /。不同数据库对注释细节可能略有差异,但这两种最通用。
- 单行:-- 这是注释
- 多行:/ 这是多行注释 /
58. 请解释 SQL 中 LEFT JOIN 和 INNER JOIN 的区别,并举例说明各自适用场景。
- 知识点: 数据库 (主题: sql;标签: join, left-join, inner-join)
- 类型: technical | 难度: easy | 子类型:
- 分类: fullstack
- id: 69782c80a39c9c5c3ab877af | 官方: 是 | 付费: 否
答案:
答案核心区别
LEFT JOIN 会返回左表的所有记录,并把右表能匹配上的记录拼接上;若右表无匹配,右表字段为 NULL。INNER JOIN 只返回两边都能匹配上的记录。场景上,LEFT JOIN 常用于“要保留全量主体并找出缺失关系”(如所有客户及其订单,包含无订单客户);INNER JOIN 常用于“只关心有关联的有效组合”(如只看下过单的客户)。
- LEFT JOIN:保留左表全量;用于发现缺失或做覆盖分析
- INNER JOIN:仅保留匹配行;用于统计有效关联样本
- 注意:JOIN 前先确认 join key 唯一性,避免行数意外膨胀
59. Afterpay 的 Data Analyst 面试通常包含哪些环节?你该如何准备?
- 知识点: 数据库 / 数据工程与数据科学/AI / 行为与软技能 (主题: interview, case-study, sql, statistics;标签: case-study, preparation)
- 类型: behavioral | 难度: easy | 子类型:
- 分类: fullstack
- id: 69782c9ba39c9c5c3ab89273 | 官方: 是 | 付费: 否
答案:
答案准备清单
常见会包含 HR 面、用人经理面,以及案例分析(Case Study)展示(可能多轮)。准备上:先梳理项目经历并用 STAR 表达;技术侧强化 SQL(join、窗口函数(window function)、聚合、去重)、统计与实验(假设检验、A/B 测试)、以及指标体系;案例侧练习从问题定义→数据准备→分析→结论→建议→风险与下一步的完整叙事,并能用清晰可视化讲给非技术听。
- 结构:HR → Hiring Manager → Case Study/Presentation(可能多轮)
- 技术:SQL + 统计/实验 + 指标体系 + 数据质量
- 表达:STAR + 数据叙事 + 面向不同受众的讲解
- 实战:练习 case,准备提问(团队、数据栈、挑战)
60. What is normalization in the database?
什么是数据库中的规范化?
- 知识点: 数据库 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791b58d557c902b97386 | 官方: 否 | 付费: 否
答案:
- Normalization(data normalization or database normalization) is the technique of data organization in the database to minimize data redundancy and improve data integrity. Through database normalization, we can organize the data in tables and columns, and also we can define a relationship between these tables or columns.
Below are the commonly used normalization forms:
First Normal Form(1NF)第一范式(1NF)
Second Normal Form(2NF)
第二范式(2NF)
Third Normal Form(3NF)
第三范式(3NF)
Boyce-Codd Normal Form(BCNF)
博伊斯-科德范式(BCNF)
Fourth Normal Form(4NF)
第四范式(4NF)
Fifth Normal Form(5NF)
第五范式(5NF)
61. Can you give differences for the Primary key and Unique key in SQL?
你能给出 SQL 中主键和唯一键的区别吗?
- 知识点: 数据库 (标签: interviewbit, accenture, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accenture
- id: 69b3791b58d557c902b97389 | 官方: 否 | 付费: 否
答案:
| Primary key 主键 | Unique Key 唯一键 |
|---|---|
| It is a unique identifier for each row of a table. 它是表中每一行的唯一标识符。 | It is a unique identifier for table rows in the absence of a Primary key. 在没有主键的情况下,它是表行的唯一标识符。 |
| A single Primary key is allowed in a table. 一个表中只允许有一个主键。 | More than one Unique Key is allowed in a table. 一个表中允许多个唯一键。 |
| NULL value or duplicate value is not permitted. 不允许 NULL 值或重复值。 | It can have a single NULL value but a duplicate value is not permitted. 可以有单个 NULL 值,但不允许重复值。 |
| When we define a Primary key, a clustered index is automatically created if it does not already exist on the table. 当我们定义主键时,如果表上尚未存在聚集索引,则会自动创建一个聚集索引。 | When we define a Unique key, a non-clustered index is created by default to enforce a UNIQUE constraint. 当我们定义唯一键时,默认会创建一个非聚集索引以强制执行 UNIQUE 约束。 |
62. What do you understand about normalization in the context of Database Management Systems (DBMS)? What is the need for normalization?
在数据库管理系统(DBMS)的背景下,你对规范化有何理解?为什么需要规范化?
- 知识点: 数据库 (标签: interviewbit, accolite, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accolite Digital
- id: 69b3791b58d557c902b973c5 | 官方: 否 | 付费: 否
答案:
The process of organising data in a database is known as normalisation. This includes generating tables and defining relationships between them according to rules aimed to secure data while also allowing the database to be more flexible by removing redundancy and inconsistent dependencies. Normalization aims at avoiding undesired characteristics such as Insertion, Update, and Deletion Anomalies. A normal form is a procedure that compares each relation to a set of criteria and eliminates multivalued, joins, functional, and trivial dependencies. Any data that is updated, deleted, or entered has no effect on database tables and helps to improve the integrity and performance of relational databases.
在数据库中组织数据的过程称为规范化。这包括根据旨在保护数据的规则生成表并定义它们之间的关系,同时通过消除冗余和不一致的依赖关系使数据库更加灵活。规范化旨在避免插入、更新和删除异常等不良特征。范式是一种将每个关系与一组标准进行比较并消除多值、连接、函数和平凡依赖关系的过程。任何被更新、删除或输入的数据都不会对数据库表产生影响,并有助于提高关系数据库的完整性和性能。
The following points illustrate the need for normalization in DBMS :
以下几点说明了在 DBMS 中需要规范化的原因:
- It is used to clean up the relational table by removing duplicate data and database oddities.
- By assessing new data types utilized in the table, normalization helps to decrease redundancy and complexity.
- It's a good idea to break down a huge database table into smaller tables and use relationships to connect them.
- It prevents duplicate data from being entered into a database, as well as no recurring groups.
- It lowers the likelihood of anomalies in a database.
63. What are the advantages of Database Management Systems over File Systems?
数据库管理系统相比文件系统有哪些优势?
- 知识点: 数据库 (标签: interviewbit, accolite, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accolite Digital
- id: 69b3791b58d557c902b973d1 | 官方: 否 | 付费: 否
答案:
The following are the advantages of Database Management Systems (DBMS) over File Systems:
以下是数据库管理系统(DBMS)相比文件系统的优势:
- Data redundancy and inconsistency - Redundancy refers to the concept of data repetition, which means that any data item may have multiple copies. The file system cannot regulate the redundancy of data as each user defines and maintains the needed files for a given application to execute. It's possible that two users are sharing the same files and data for different programs. As a result, changes performed by one user do not appear in files utilized by other users, resulting in data inconsistency. DBMS, on the other hand, manages redundancy by keeping a single data repository that is defined once and accessed by multiple users. As there is no or less redundancy, data remains consistent.
- Data sharing - The file system does not allow data sharing because it is too complicated. Due to the centralized structure in DBMS, data may be simply shared.
- Data Storage technique - In a File System, data is stored in files, which are then sorted into folders, which are then structured into a hierarchy of directories and subdirectories. In a DBMS, data is stored in a structured and organized manner. Depending on the type of DBMS, it may be stored either in form of tables(if the DBMS is a Relational DBMS) or in the form of nodes (if the DBMS is a Graph DBMS) and so on. This leads to faster retrieval of data based on search queries.
- Concurrent access to data - When more than one user accesses the same data at the same time, this is referred to as data concurrency. Anomalies occur when one user's edits are overwritten by changes made by another user. There is no method in the file system to prevent abnormalities. A locking system is provided by DBMS to prevent abnormalities from occurring.
- Data searching - Each file system search activity necessitates the creation of a separate application program. DBMS, on the other hand, has built-in searching capabilities. To access data from the database, the user merely needs to submit a short query.
- Data integrity - Before putting data into a database, some constraints may need to be applied to the data. There is no process in the file system to check these constraints automatically. DBMS, on the other hand, ensures data integrity by enforcing user-defined restrictions on data.
- System crashes - Systems may crash for a variety of reasons in some circumstances. It's a problem with file systems since there's no way to recover the data that's been lost if the system crashes. A DBMS will have the recovery manager which retrieves the data offering it another advantage over file systems.
- Data security - A file system can safeguard a database using a password, but how long can the password be protected? That is something that no one can promise. In the case of DBMS, this does not occur. A database management system (DBMS) contains particular capabilities that assist in protecting data.
64. What do you understand about indexing in the context of Database Management Systems (DBMS)? What are the different types of indexing?
在数据库管理系统(DBMS)的背景下,你对索引有何理解?索引有哪些不同类型?
- 知识点: 数据库 (标签: interviewbit, accolite, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accolite Digital
- id: 69b3791b58d557c902b973db | 官方: 否 | 付费: 否
答案:
Indexing is a data structure approach for retrieving records fast from a database file. A short table with only two columns is called an index. A duplicate of a table's primary or candidate key appears in the first column. The second column of the table comprises a series of pointers that carry the address of the disk block where that particular key value is stored. An index takes a search key as input and returns a collection of matching records. In the real world, we can compare indexing with that of the index page of a page. To access the content of a book, we go through its index to know what content lies on which pages. This makes our retrieval faster. In a similar manner, Database Management Systems maintain indexes so as to make retrieval faster from the database.
索引是一种从数据库文件中快速检索记录的数据结构方法。一个只有两列的短表称为索引。表的主键或候选键的副本出现在第一列中。表的第二列包含一系列指针,这些指针携带存储该特定键值的磁盘块的地址。索引将搜索键作为输入,并返回一组匹配的记录。在现实世界中,我们可以将索引与书的索引页进行比较。要访问一本书的内容,我们会查看其索引以了解哪些内容位于哪些页面上。这使我们的检索更快。以类似的方式,数据库管理系统维护索引以使从数据库中检索更快。
The following are the different types of indexing in DBMS:
以下是 DBMS 中索引的不同类型:
- Primary Indexing: A primary index is a two-field, ordered file with a defined length. The first field is the same as the primary key, while the second field points to the data block of concern. There is always a one-to-one relationship between the elements in the index table in the primary index. The primary indexing in a database management system is also divided into two types:
- Dense Index: For each search key value in the database, a record is created in a dense index. This allows you to search more quickly, but it requires more storage space for index information.
- Sparse Index: It's an index record that only appears for a subset of the file's values. Sparse indexes assist you in resolving DBMS dense indexing challenges. This indexing approach keeps the same data block address in a series of index columns, and when data is needed, the block address is retrieved. It takes up less space and has a smaller maintenance overhead for insertions and deletions, but it is slower to locate records than a dense index.
- Secondary Indexing: In a database management system, a secondary index can be constructed by a field that has a unique value for each record and should be a candidate key. A non-clustering index is another name for it.
- Clustering Indexing: The records themselves, not references, are stored in a clustered index. Non-primary key columns are sometimes used to build indexes, and they may not be unique for each record. In this case, you can aggregate two or more columns to generate unique values and create a clustered index. This also aids in the faster identification of the record.
65. What are the advantages of indexing in DBMS?
在DBMS中建立索引有哪些优势?
- 知识点: 数据库 (标签: interviewbit, accolite, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accolite Digital
- id: 69b3791b58d557c902b973de | 官方: 否 | 付费: 否
答案:
The following are the advantages of indexing in DBMS: - It allows you to reduce the total number of I/O operations required to retrieve that data by eliminating the necessity to access a database entry through an index structure.
在DBMS中建立索引的优势如下:- 它通过消除必须通过索引结构访问数据库条目的必要性,来减少检索该数据所需的总I/O操作次数。
- Users may search and retrieve info more quickly.
You can save tablespace by indexing because you don't need to connect to a row in a table because the ROWID isn't stored in the index. As a result, you will be able to save table space.
The following are the disadvantages of indexing in the context of DBMS: - Partitioning an index-organized table is not permitted.在DBMS的背景下,索引的缺点如下:- 不允许对索引组织表进行分区。
- Indexing in SQL reduces the speed of INSERT, DELETE, and UPDATE queries.
66. Given a table in a database having two attributes employee name and their salary in it, find and print the employee having the Nth highest salary amongst them using Structured Query Language (SQL).
给定一个数据库中的表,其中包含员工姓名和他们的薪水两个属性,使用结构化查询语言(SQL)查找并打印其中拥有第N高薪水的员工。
- 知识点: 数据库 (标签: interviewbit, accolite, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Accolite Digital
- id: 69b3791b58d557c902b973e4 | 官方: 否 | 付费: 否
答案:
Example: Consider the following table:
示例:考虑以下表:
| ename | sal |
|---|---|
| P | 100 |
| Q | 200 |
| R | 300 |
| S | 500 |
| T | 400 |
| U | 100 |
| ename | sal |
|---|---|
| P | 100 |
| Q | 200 |
| R | 300 |
| S | 500 |
| T | 400 |
| U | 100 |
Here, if n = 2, then the output should be
这里,如果n = 2,那么输出应为
| ename | sal |
|---|---|
| T | 400 |
| ename | sal |
|---|---|
| T | 400 |
Approach 1: We use the concept of dense_rank() to compute the Nth highest salary. The function DENSE_RANK() returns the rank of a row in an ordered collection of rows as a NUMBER. The ranks are in ascending order, starting with 1. This function takes any numeric data type as an argument and returns NUMBER. Based on the values of the value_exprs in the order_by_clause, DENSE RANK computes the rank of each row returned from a query in relation to the other rows as an analytic function.
方法1:我们使用dense_rank()的概念来计算第N高薪水。函数DENSE_RANK()以NUMBER形式返回行在有序行集合中的排名。排名按升序排列,从1开始。该函数接受任何数值数据类型作为参数并返回NUMBER。基于order_by_clause中value_exprs的值,DENSE RANK作为分析函数计算查询返回的每一行相对于其他行的排名。
SQL Query:
SQL查询:
select * from(
select * from(
select ename, sal, dense_rank()
select ename, sal, dense_rank()
over(order by sal desc)rnk from Employee)
over(order by sal desc)rnk from Employee)
where rnk=&n;
where rnk=&n;
Approach 2: In this approach, we first find the employees who have the highest N different wages. The Nth highest salary can then be determined by finding the lowest salary among the salaries returned by the above query.
方法2:在此方法中,我们首先找出拥有最高的N个不同工资的员工。然后可以通过查找上述查询返回的工资中的最低工资来确定第N高薪水。
SQL Query:
SQL查询:
SELECT * FROM Employee WHERE sal =
SELECT * FROM Employee WHERE sal =
(
SELECT MIN(sal) FROM Employee
SELECT MIN(sal) FROM Employee
WHERE sal IN (
WHERE sal IN (
SELECT DISTINCT TOP N
SELECT DISTINCT TOP N
sal FROM Employee
sal FROM Employee
ORDER BY sal DESC
ORDER BY sal DESC
)
);
Approach 3: In this approach, we will create two aliases of the Employee table and then compare each salary with the other salaries present in the table to check if the current salary under consideration is greater than N-1 other salaries.
方法3:在这种方法中,我们将创建Employee表的两个别名,然后逐一比较每个薪水与表中的其他薪水,以检查当前考虑的薪水是否大于其他N-1个薪水。
SQL Query:
SQL查询:
SELECT ename,sal from Employee e1 where
SELECT ename,sal from Employee e1 where
N-1 = (SELECT COUNT(DISTINCT sal)from Employee e2 where e2.sal > e1.sal)
N-1 = (SELECT COUNT(DISTINCT sal)from Employee e2 where e2.sal > e1.sal)
67. What makes a DBMS an RDBMS?
什么使DBMS成为RDBMS?
- 知识点: 数据库 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Amdocs
- id: 69b3792d58d557c902b98470 | 官方: 否 | 付费: 否
答案:
The Database Management System (DBMS) creates and maintains databases, allowing controlled access to the data. RDBMS stands for Relational Database Management System, an advanced version of a DBMS. While DBMS stores data in a file, RDBMS stores data in tabular format.
数据库管理系统(DBMS)创建和维护数据库,允许对数据进行受控访问。RDBMS代表关系数据库管理系统,是DBMS的高级版本。DBMS将数据存储在文件中,而RDBMS以表格格式存储数据。
68. Write a query that lists the employees who joined in the month of March based on an employee table in a database?
基于数据库中的员工表,编写一个查询,列出在3月份入职的员工?
- 知识点: 数据库 (标签: interviewbit, amdocs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Amdocs
- id: 69b3792d58d557c902b9847f | 官方: 否 | 付费: 否
答案:
Look at the “employees” table below.
请查看下面的"employees"表。
| Job_ID | Employee_Name | HireDate | Position |
|---|---|---|---|
| 01 | Sonal | 2020-06-22 | Content Writer |
| 02 | Shivam | 2022-03-01 | Senior SDE |
| 03 | Rohit | 2018-03-14 | Associate SDE |
| 04 | Raghav | 2015-12-04 | Manager |
| Job_ID | Employee_Name | HireDate | Position |
|---|---|---|---|
| 01 | Sonal | 2020-06-22 | Content Writer |
| 02 | Shivam | 2022-03-01 | Senior SDE |
| 03 | Rohit | 2018-03-14 | Associate SDE |
| 04 | Raghav | 2015-12-04 | Manager |
If you want to see all the employees who joined in the month of March, then run the following SQL query:
如果你想查看所有在3月份入职的员工,请运行以下SQL查询:
SELECT * FROM employees WHERE to_char(hire_date,'MON') ='MAR';
SELECT * FROM employees WHERE to_char(hire_date,'MON') ='MAR';
OR
或者
SELECT * FROM employees WHERE to_char(hire_date,'MON') IN ('MAR');
SELECT * FROM employees WHERE to_char(hire_date,'MON') IN ('MAR');
OR
或者
SELECT * FROM employees WHERE to_char(hire_date,'MON') LIKE 'MAR%';
SELECT * FROM employees WHERE to_char(hire_date,'MON') LIKE 'MAR%';
Output:
输出:
| Job_ID | Employee_Name | HireDate | Position |
|---|---|---|---|
| 02 | Shivam | 2022-03-01 | Senior SDE |
| 03 | Rohit | 2018-03-14 | Associate SDE |
| Job_ID | Employee_Name | HireDate | Position |
|---|---|---|---|
| 02 | Shivam | 2022-03-01 | Senior SDE |
| 03 | Rohit | 2018-03-14 | Associate SDE |
69. List a few of the benefits of using a database management system.
列出使用数据库管理系统的一些好处。
- 知识点: 数据库 (标签: interviewbit, apisero, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Apisero
- id: 69b3793b58d557c902b9919f | 官方: 否 | 付费: 否
答案:
The following are some of the benefits of a database management system:
以下是数据库管理系统的一些好处:
- It aids in the management of database redundancy.
- Ensures that data is consistent.
- Easily accessible.
- Backup and recovery services are available.
- Integrity limitations are enforced.
- It puts a stop to unauthorized access.
- Multiple user interfaces are available.
- Due to the usage of queries, data extraction and processing are simple.
70. State your understanding of Distributed Database Management Systems with Transparency or Transparent Distributed Database Management Systems?
阐述你对具有透明性或透明分布式数据库管理系统的分布式数据库管理系统的理解?
- 知识点: 数据库 (标签: interviewbit, apisero, company-specific)
- 类型: technical | 难度: easy | 子类型: system-design
- 分类: general
- 公司: Apisero
- id: 69b3793b58d557c902b991a2 | 官方: 否 | 付费: 否
答案:
The transparent Distributed Database Management System is a type of database management system that hides the physical structure of the database from users. Physical structure, also known as physical storage structure, refers to the memory manager of a database management system and describes how data is saved on a disk. There is less abstraction as a result of this. In Distributed Database Management Systems (or DDBMS), there are four forms of transparency: - Transparency in transactions
透明分布式数据库管理系统是一种对用户隐藏数据库物理结构的数据库管理系统。物理结构,也称为物理存储结构,指的是数据库管理系统的内存管理器,并描述数据如何保存在磁盘上。因此,抽象程度较低。在分布式数据库管理系统(或DDBMS)中,有四种透明形式:- 事务透明度
- Transparency in distribution
- Transparency in performance
- Transparency in relational databases.
71. What are the differences between RDBMS (Relational Database Management Systems) and DBMS (Database Management Systems)?
RDBMS(关系数据库管理系统)和DBMS(数据库管理系统)之间有什么区别?
- 知识点: 数据库 (标签: interviewbit, apisero, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Apisero
- id: 69b3793b58d557c902b991a9 | 官方: 否 | 付费: 否
答案:
The key differences between Relational Database Management Systems (RDBMS) and Database Management Systems (DBMS) are as follows:
关系数据库管理系统(RDBMS)和数据库管理系统(DBMS)之间的主要区别如下:
| RDBMS | DBMS |
|---|---|
| They store data in the form of tables of rows and columns 它们以行和列的表形式存储数据 | They store data in the form of files. 它们以文件形式存储数据。 |
| Related data are stored in a single table. 相关数据存储在单个表中。 | There is no relationship between the data stored in a single file of DBMS. DBMS的单个文件中存储的数据之间没有关系。 |
| Many data items can be fetched simultaneously using mechanisms like grouping, etc. 可以使用分组等机制同时获取多个数据项。 | Only a single data item can be fetched at a particular point of time. 在特定时间点只能获取单个数据项。 |
| Relational tables can be normalized due to which Data Redundancy can be reduced. 关系表可以进行规范化,从而减少数据冗余。 | No concept of Normalization and hence Data Redundancy is prevalent. 没有规范化的概念,因此数据冗余普遍存在。 |
| Distributed databases are supported by RDBMS. RDBMS支持分布式数据库。 | DBMS does not support distributed databases. DBMS不支持分布式数据库。 |
| It can support multiple users at the same time (concurrent access is possible). 它可以同时支持多个用户(并发访问是可能的)。 | Only one user can use the DBMS at a particular time. 在特定时间只能有一个用户使用DBMS。 |
| Faster data fetching due to the relational approach. 由于关系方法,数据获取更快。 | Data fetching is normally very slow since there is no relation between data in a file. 由于文件中的数据之间没有关系,数据获取通常非常缓慢。 |
| It has a lot of hardware and software needs. 它有大量硬件和软件需求。 | Very few hardware and software needs are there in it. 它的硬件和软件需求很少。 |
| Data is more secure in RDBMS than in DBMS as various security mechanisms are implemented at various levels in it. RDBMS中的数据比DBMS中的数据更安全,因为它在各个级别实现了各种安全机制。 | Data is highly insecure in DBMS. DBMS中的数据非常不安全。 |
| Examples of RDBMS include Oracle, MySQL, Postgre, etc. RDBMS的例子包括Oracle、MySQL、Postgre等。 | Examples of DBMS include XML, Window Registry, etc. DBMS的例子包括XML、Windows注册表等。 |
72. State your understanding of Distributed Database Management Systems with Transparency?
阐述你对具有透明性的分布式数据库管理系统的理解?
- 知识点: 数据库 (标签: interviewbit, arcesium, company-specific)
- 类型: technical | 难度: easy | 子类型: system-design
- 分类: general
- 公司: Arcesium
- id: 69b3793d58d557c902b993e1 | 官方: 否 | 付费: 否
答案:
The transparent Distributed Database Management System is a type of database management system that hides the physical structure of the database from users. Physical structure, also known as physical storage structure, refers to the memory manager of a database management system and describes how data is saved on a disk. There is less abstraction as a result of this. In Distributed Database Management Systems (or DDBMS), there are four forms of transparency:
透明分布式数据库管理系统是一种对用户隐藏数据库物理结构的数据库管理系统。物理结构,也称为物理存储结构,指的是数据库管理系统的内存管理器,并描述数据如何保存在磁盘上。因此,抽象程度较低。在分布式数据库管理系统(或DDBMS)中,有四种透明形式:
- Transparency in transactions
- Transparency in performance
- Transparency in relational databases
- Transparency in distribution
73. 描述数据库索引(Index) 的工作原理,以及如何优化查询性能。
- 知识点: 数据库 (主题: database, sql;标签: atlassian, generated)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: design
- 公司: Atlassian
- id: 69b3794b58d557c902b99e7e | 官方: 是 | 付费: 是
答案:
思路分析从 B+ 树(B+ Tree) 索引结构、索引类型、查询计划(Query Plan) 分析等方面回答。
参考答案B+ 树(B+ Tree) 是最常用的索引结构。主键索引(聚簇(Clustered)索引) vs 二级索引(非聚簇(Non-Clustered)索引)。覆盖索引(Covering Index) 避免回表(Table Lookup)。EXPLAIN(执行计划分析工具) 分析查询计划。复合索引(Composite Index) 和最左前缀原则(Leftmost Prefix Principle)。
评分要点- 索引结构理解
- 索引选择和设计能力
- 查询优化实战经验
常见追问- 什么时候不应该建索引? - 如何处理慢查询?
74. What are the SQL Constraints?
什么是 SQL 约束?
- 知识点: 数据库 (标签: interviewbit, axis-bank, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Axis Bank
- id: 69b3795c58d557c902b9ac54 | 官方: 否 | 付费: 否
答案:
In SQL, constraints specify the rules for table data. To limit the type of data that can be entered into a table, constraints are used. This ensures that the table's data is accurate and reliable. Data actions are aborted when a constraint is violated. Constraints may be defined at the column or table level. As the name implies, a column-level constraint is applied to a particular column, whereas a table-level constraint is applied to the entire table. Constraints can be specified when creating the table, or afterward using the ALTER TABLE statement.
在 SQL 中,约束规定了表数据的规则。为了限制可以输入到表中的数据类型,使用了约束。这确保了表数据的准确性和可靠性。当违反约束时,数据操作将被中止。约束可以在列级或表级定义。顾名思义,列级约束应用于特定列,而表级约束应用于整个表。创建表时可以指定约束,或者之后使用 ALTER TABLE 语句指定。
Syntax:
语法:
CREATE TABLE table_name
CREATE TABLE table_name
(
col1 datatype(size) constraint_name,
col1 datatype(size) constraint_name,
col2 datatype(size) constraint_name,
col2 datatype(size) constraint_name,
col3 datatype(size) constraint_name,
col3 datatype(size) constraint_name,
....
);
Constraints available in SQL - NOT NULL: This constraint prevents us from storing null values in a column. If a column is set to NOT NULL, then the null value can no longer be stored in the given column.
SQL 中可用的约束 - NOT NULL:此约束防止我们在列中存储空值。如果某列设置为 NOT NULL,则给定列中不能再存储空值。
- UNIQUE: If a column is set to UNIQUE, then every value in the column must be unique. This means that no value should be repeated in the column.
- PRIMARY KEY: A primary key of a table is a field that uniquely identifies each row within the table. This constraint specifies a field as a primary key in a table.
- FOREIGN KEY: A foreign key of a table is a field that uniquely identifies each row of another table. This constraint specifies a field as a foreign key in a table.
- CHECK: Using this constraint, the values of a column can be validated to meet a specific condition. This ensures that the value stored within a column meets a particular condition.
- DEFAULT: This constraint sets a default value for the column when no user value is specified.
75. What do you mean by DELETE and TRUNCATE statements in SQL?
在SQL中,DELETE和TRUNCATE语句是什么意思?
- 知识点: 数据库 (标签: interviewbit, axis-bank, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Axis Bank
- id: 69b3795c58d557c902b9ac57 | 官方: 否 | 付费: 否
答案:
Both TRUNCATE and DELETE statements are part of the SQL delete query. Both are used to get rid of unwanted records or rows in a table.
TRUNCATE和DELETE语句都是SQL删除查询的一部分。两者都用于删除表中的不需要的记录或行。
| DELETE | TRUNCATE |
|---|---|
| You can delete all records from a table or only certain records matching your criteria with the SQL Delete command. 使用SQL Delete命令,您可以删除表中的所有记录,或仅删除符合您条件的特定记录。 | The Truncate command in SQL deletes all rows or tuples from a table. SQL中的Truncate命令删除表中的所有行或元组。 |
| It is a DML (Data Manipulation Language) command 这是一个DML(数据操作语言)命令。 | It is a DDL (Data Definition Language) command. 这是一个DDL(数据定义语言)命令。 |
| A WHERE clause can be used with the DELETE command. WHERE clauses are used with DELETE commands to remove or delete only the rows that satisfy a condition, otherwise all rows are removed by default. DELETE命令可以使用WHERE子句。WHERE子句与DELETE命令一起使用,以仅删除满足条件的行,否则默认删除所有行。 | TRUNCATE commands that do not contain a WHERE clause, unlike DELETE commands. TRUNCATE命令与DELETE命令不同,不包含WHERE子句。 |
| Tuples are locked before being removed with the DELETE command. 使用DELETE命令删除元组前,元组会被锁定。 | A data page must be locked prior to removing table data using TRUNCATE. 使用TRUNCATE删除表数据前,必须锁定数据页。 |
| Since the DELETE command maintains the transaction log for each deleted record, it is slower than TRUNCATE. 由于DELETE命令为每条删除的记录维护事务日志,因此比TRUNCATE慢。 | TRUNCATE is faster since it does not scan each record before removing it; rather, it removes entire data blocks at once. TRUNCATE更快,因为它在删除前不会扫描每条记录;相反,它一次性删除整个数据块。 |
| Transaction logs are maintained for each deleted record, allowing us to roll back the change. Using the ROLLBACK or COMMIT statements, we can restore deleted data. 为每条删除的记录维护事务日志,允许我们回滚更改。使用ROLLBACK或COMMIT语句,我们可以恢复删除的数据。 | There are no transaction logs for each deleted row, so we cannot roll back the changes. Once the command has been executed, we cannot revert the changes. 没有为每个删除的行维护事务日志,因此我们无法回滚更改。一旦命令执行,我们无法恢复更改。 |
| Because it keeps a log for each deleted row, it consumes more transaction space than truncate. 因为它为每个删除的行保留日志,所以比TRUNCATE占用更多的事务空间。 | Since a transaction log is maintained for the entire page instead of for each row, it occupies less space than the DELETE command. 由于为整个页面而不是每行维护事务日志,因此比DELETE命令占用更少的空间。 |
| Syntax: DELETE FROM TableName WHERE condition; 语法:DELETE FROM 表名 WHERE 条件; | Syntax: TRUNCATE TABLE TableName; 语法:TRUNCATE TABLE 表名; |
76. Why is it suggested to utilise a database management system (DBMS)? List some of its primary advantages to explain.
为什么建议使用数据库管理系统(DBMS)?列举一些其主要优点来解释。
- 知识点: 数据库 (标签: interviewbit, capgemini, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Capgemini
- id: 69b379f058d557c902ba16be | 官方: 否 | 付费: 否
答案:
Following are some advantages of using DBMS: - Minimizing Data Redundancy: DBMS supports a system to eliminate data redundancy within the database by integrating all data into a single database, and because data is stored in only one location, there is no duplication of data.
以下是使用DBMS的一些优点: - 最小化数据冗余:DBMS支持通过将所有数据集成到单个数据库中来消除数据库中的数据冗余,并且由于数据只存储在一个位置,因此不会重复数据。
- Data Sharing: In a DBMS, data can be shared among several users at the same time because the same database is shared across all users and by various applications.
- Data Integrity: This refers to the database's data being consistent and accurate at all times. It is critical because a database management system (DBMS) contains numerous databases, each of which contains data that is visible to multiple users. As a result, it's critical to guarantee that data is accurate and consistent across all databases and for all users.
- Data Security: Only approved users should be allowed access to the database, and their identities should be authenticated using a legitimate login and password. Under no circumstances should unauthorized users be allowed to access the database, as this would break the integrity limitations.
77. Why is normalization needed in a database?
为什么数据库中需要规范化?
- 知识点: 数据库 (标签: interviewbit, capgemini, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Capgemini
- id: 69b379f058d557c902ba16c1 | 官方: 否 | 付费: 否
答案:
The term "normalization" refers to the process of analyzing relation schemas based on their functional dependencies. Normalization is the technique of splitting up data into numerous tables to reduce redundancy.
术语“规范化”指基于功能依赖分析关系模式的过程。规范化是将数据拆分成多个表以减少冗余的技术。
The advantages of normalization are: - Standardization eliminates the copy information, allowing a smaller database to be maintained. As a result, the size of the database is reduced in general.
规范化的优点是: - 标准化消除复制信息,允许维护更小的数据库。因此,数据库的大小总体上减小了。
- Better execution is assured, which is related to the previous point. As the size of information bases shrinks, the time it takes to process it becomes shorter and more constrained, enhancing reaction time and speed.
- Narrower tables may be possible as standardized tables are altered and feature fewer segments, allowing for more data items per page.
- With fewer files per table, support assignments are completed faster (file modifies).
78. What do you understand about Proactive, Retroactive and Simultaneous Update in the context of DBMS?
在DBMS的上下文中,你对主动更新、追溯更新和同步更新有何理解?
- 知识点: 数据库 (标签: interviewbit, cognizant, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Cognizant
- id: 69b37a3158d557c902ba3ff6 | 官方: 否 | 付费: 否
答案:
- Proactive Updates: These changes are made to the database before it is put into use in the real-world environment.
- Retroactive Updates: These updates are applied to a database after it has been operational in the real-world environment.
- Simultaneous Updates: These updates are applied to the database at the same moment as they become functional in the real-world environment.
79. What is the fill factor in SQL? What is its default value?
SQL中的填充因子是什么?其默认值是多少?
- 知识点: 数据库 (标签: interviewbit, cognizant, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Cognizant
- id: 69b37a3158d557c902ba3ffc | 官方: 否 | 付费: 否
答案:
The fill factor is the percentage of space on each leaf-level page that will be filled with data. The smallest unit in SQL Server is a page, which is made up of 8K pages. Depending on the size of the row, each page can store one or more rows. The Fill Factor's default value is 100, which is the same as the value 0. The SQL Server will fill the leaf-level pages of an index with the highest number of rows it can fit if the Fill Factor is set to 100 or 0. When the fill factor is 100, the page will have no or very little vacant space.
填充因子是每个叶级页面上将填充数据的空间百分比。SQL Server中最小的单元是页面,由8K页面组成。根据行的大小,每个页面可以存储一行或多行。填充因子的默认值为100,这与值0相同。如果填充因子设置为100或0,SQL Server将以能容纳的最大行数填充索引的叶级页面。当填充因子为100时,页面将没有或很少有空白空间。
80. Explain the following terminologies in the context of Commvault: IRM CommCell, CommServe, CommServe Database, CommCell Console, MediaAgent, IRM Clients.
在Commvault的上下文中,解释以下术语:IRM CommCell、CommServe、CommServe数据库、CommCell控制台、MediaAgent、IRM客户端。
- 知识点: 数据库 (标签: interviewbit, commvault, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Commvault
- id: 69b37a4d58d557c902ba50e0 | 官方: 否 | 付费: 否
答案:
- IRM CommCell: The IRM CommCell, which is based on the Microsoft Windows platform and Microsoft's SQL Server Express, consolidates all task management functions, metadata, scheduling, and reporting into a single console. The CommServe application and the MediaAgent are two standard components in this IRM CommCell. These two components share a single operating area known as a CommCell.
- CommServe: CommServe is the master server in charge of CommCell's configuration and operations. It runs on a Windows host server and includes an embedded version of Microsoft SQL Express, which serves as IRM's top-level database. Each CommCell has one CommServe, which must be available to run operations. The CommServe handles only job control and metadata. The MediaAgent specified in the CommCell is used to perform indexing and snapshot management.
- CommServe Database: The CommServe Database is built on Microsoft SQL Express Edition and contains all of the CommServe's history and usage. Information such as work history, client settings, media type, and so on are all maintained in the database, and every item of data that is retrieved, saved, or deleted is recorded in the CommServe database.
- CommCell Console: It is the console that contains all of the CommCell environment's administration features and capabilities in a single pane. The console is java-based and may be launched as a local console instance or accessible through a browser from anywhere. In this console, all policies, operations, scheduling, alerting, and reporting are integrated and displayed to users depending on their security permissions and roles.
- MediaAgent: The MediaAgent is a data mover and indexing resource in a data management environment's data movement workflow. This component plays a variety of roles in the creation/mounting of snapshots and the cataloguing of client-relevant material. The MediaAgent will also act as the disc library's media library manager, storing index data. Those indexes are stored in the Archive file format, so they can't be mounted or used directly; instead, you'll need to do a restore to get a native recovery copy of the data.
- IRM Clients: In IRM, clients are servers and systems that use snapshot integration with production storage arrays. Each server will have a base File System iDataAgent installed to facilitate essential connectivity with the CommServe. You can then load more iDataAgents for application integration or VMware integration, depending on the information or data you want to safeguard. These agents provide the appropriate level of integration for File Systems, Databases, Exchange, SQL, and VMware guests to guarantee that the necessary data is secured at the appropriate level.These agents will also ensure that VSS writers are properly called to ensure that the data in the snapshot at the point-in-time is consistent, that "ESEUtil" commands can be used to check Exchange Database consistency, and that VMware calls the appropriate software quiescing mechanisms to create consistent VMs.
81. What do you know about the Deduplication Database in the context of Commvault?
在Commvault的上下文中,你对去重数据库有何了解?
- 知识点: 数据库 (标签: interviewbit, commvault, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Commvault
- id: 69b37a4d58d557c902ba50ec | 官方: 否 | 付费: 否
答案:
In Commvault, whenever a storage policy with deduplication is implemented, signatures are generated for data blocks during backups, compared, and then stored in the deduplication database (DDB). The DDB backup subclient automatically protects DDBs. All active DDBs controlled by the MediaAgent that hosts the DDB are backed up by this subclient. You can set up a reconstruction task for an automatic or on-demand restore of the DDB from the DDB backup in the event of DDB failure. The storage metadata can then be used to rebuild missing records.
在Commvault中,每当实施带去重的存储策略时,备份期间会为数据块生成签名,进行比较,然后存储在去重数据库(DDB)中。DDB备份子客户端自动保护DDB。此子客户端备份由托管DDB的MediaAgent控制的所有活动DDB。您可以设置重建任务,以便在DDB失败时从DDB备份中自动或按需恢复DDB。然后可以使用存储元数据重建缺失的记录。
82. What is Database Testing?
什么是数据库测试?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba609e | 官方: 否 | 付费: 否
答案:
Database testing is a procedure of validating data stored in a database and its related functionality and objects controlling database entities like tables, stored procedures, views, triggers and functions. This testing is widely used in applications that use databases. With modern technologies and advancements in software development, databases are widely used to store data which is why checking the correctness and quality of data matters. It is divided into 4 categories such as: - Data Validity Testing: In this testing, testers need to know SQL queries to retrieve data from the database and validate it.
数据库测试是验证数据库中存储的数据及其相关功能和控制数据库实体(如表、存储过程、视图、触发器和函数)的对象的过程。这种测试广泛应用于使用数据库的应用程序中。随着现代技术和软件开发的发展,数据库被广泛用于存储数据,因此检查数据的正确性和质量至关重要。它分为4类,例如:- 数据有效性测试:在这种测试中,测试人员需要了解SQL查询以从数据库中检索数据并对其进行验证。
- Data Integrity Testing: Here, the testers need to validate data against various constraints and referential integrity in the database.
- Database Performance Testing: Here, the testers need to validate the performance of various triggers, indices, procedures to see how effectively the operations occur. The system also needs to execute database transactions efficiently. Good knowledge of database structures needs to be there while doing this.
- Testing triggers, functions and procedures present in the database to validate the logic associated with them.
83. What do you understand by data-driven testing?
你对数据驱动测试有何理解?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba60a1 | 官方: 否 | 付费: 否
答案:
Data-driven testing is an automation testing framework that involves testing data stored in a spreadsheet or a table and using that stored data as input values to the test scripts. This is done to avoid writing individual test cases of the same functionalities with different inputs. The inputs to the test scripts can be stored in XML, CSV, XLS and other data formats.
数据驱动测试是一种自动化测试框架,涉及测试存储在电子表格或表中的数据,并将该存储数据作为测试脚本的输入值。这样做是为了避免为具有不同输入的相同功能编写单独的测试用例。测试脚本的输入可以存储在XML、CSV、XLS和其他数据格式中。
There are 4 main types of data-driven testing based on the source of test data inputs: - Key-driven: Here, dynamic data is provided as inputs to the test cases by employing a keyboard to retest the application and validate the business logic.
基于测试数据输入来源,数据驱动测试主要有4种类型: - 键驱动:这里,通过使用键盘为测试用例提供动态数据,以重新测试应用程序并验证业务逻辑。
- Flat files: Application retesting is done by taking input data stored in flat files like .doc or .txt.
- Front-end object: The test scripts use data from front-end objects like list, table, menu, data window etc.
- Spreadsheet/Excel: Here, the test data is taken from data stored in excel sheets or spreadsheets.
84. What do you understand about Trigger Testing?
你对触发器测试有什么理解?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba60aa | 官方: 否 | 付费: 否
答案:
Trigger testing involves testing the database triggers that answers the following questions:
触发器测试涉及测试数据库触发器,回答以下问题:
Are the coding conventions followed while defining and coding the triggers? 2. Are the triggers executing the DML transactions successfully by satisfying all conditions? 3. Are the triggers updating the data correctly post the execution of queries? 4. Is the application functionality working fine post the data updation, insertion or deletion?
- 在定义和编码触发器时是否遵循了编码规范? 2. 触发器是否在满足所有条件的情况下成功执行DML事务? 3. 触发器在查询执行后是否正确更新数据? 4. 在数据更新、插入或删除后,应用程序功能是否正常工作?
85. What is Database Stress Testing?
什么是数据库压力测试?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba60af | 官方: 否 | 付费: 否
答案:
Database Stress Testing is one of the methods used for gauging the database performance by subjecting it to the heavy load that would potentially cause the system to fail at some point. This is used for identifying the breakdown points of the database application. Before performing this testing, proper planning needs to be done for avoiding the wastage of resources. This testing is also known as fatigue testing. It uses tools like LoadRunner and JMeter for accomplishing this.
数据库压力测试是一种通过施加可能导致系统在某个点失效的重负载来评估数据库性能的方法。它用于识别数据库应用程序的故障点。在执行此测试前,需要进行适当规划以避免资源浪费。此测试也称为疲劳测试。它使用LoadRunner和JMeter等工具来完成。
86. What do you understand by database transactions?
你对数据库事务有什么理解?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba60b2 | 官方: 否 | 付费: 否
答案:
A database transaction is defined as a task sequence that is to be performed on the database to achieve the required results logically. The task can include creating, deleting, updating the records in the database tables. The tasks upon successful completion affect the records in the database. A transaction provides 4 controls as listed below: - COMMIT: This is used for saving all changes done utilizing the transaction. We generally use this post INSERT, UPDATE, DELETE statements.
数据库事务定义为要在数据库上执行以实现所需逻辑结果的任务序列。任务可以包括在数据库表中创建、删除、更新记录。成功完成后,任务会影响数据库中的记录。事务提供4个控制,如下所列: - COMMIT:用于保存利用事务完成的所有更改。我们通常在INSERT、UPDATE、DELETE语句后使用它。
- ROLLBACK: This is used for rolling back the transaction to the previous state before it was operated. We generally use this post INSERT, UPDATE, DELETE statements.
- SAVEPOINT: This is used for setting the point where the transaction is supposed to roll back.
- SET TRANSACTION: This is used for setting the name of the transaction.
- Data Science
- All Events
- My Events
87. What do you understand by Keys and indexes Testing?
你对键和索引测试有什么理解?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba60b5 | 官方: 否 | 付费: 否
答案:
The keys and indexes testing in a database is a form of database testing which answers the below questions: - Have the required primary keys and foreign keys constraints been created on the targetted tables?
数据库中的键和索引测试是一种数据库测试形式,回答以下问题: - 是否已在目标表上创建所需的主键和外键约束?
- Are the foreign key references valid?
- Is the data type of the primary key of one table and the corresponding foreign key in the other table the same?
- Are the naming conventions being followed for all indexes and keys?
- Are the lengths and sizes of the required indexes and fields expected?
- Are the indexes clustered or non-clustered working as expected and is according to the business requirements?
88. What do you understand by Non-functional testing in terms of database testing?
就数据库测试而言,你对非功能测试有什么理解?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37a6058d557c902ba60b8 | 官方: 否 | 付费: 否
答案:
Non-functional testing in terms of testing databases involves various testing methods like stress testing, load testing, usability testing, security testing, etc that tests and validate the non-functional business requirements. It helps in the quantification of risks with regards to the database system in terms of how the system performs under heavy load. It addresses the following questions which help to mitigate the risks if detected earlier: - Does the system break?
就测试数据库而言,非功能测试涉及各种测试方法,如压力测试、负载测试、可用性测试、安全测试等,用于测试和验证非功能性业务需求。它有助于量化与数据库系统相关的风险,涉及系统在重负载下的表现。它解决以下问题,如果在早期检测到则有助于缓解风险: - 系统会崩溃吗?
- Does the system slow down?
- Are there any risks to the system as the load or stress on the system increases?
Is the system scalable and usable whenever new business requirements come in?
Non-functional testing also helps in identifying what are the minimum system requirements to run effectively without any limitations on hardware or software.非功能测试还有助于确定在硬件或软件无任何限制的情况下有效运行所需的最低系统要求。
89. What would be the SQL statements used for managing and manipulating the test tables?
用于管理和操作测试表的SQL语句会是什么?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba60bb | 官方: 否 | 付费: 否
答案:
We can use the statements like INSERT, UPDATE, SELECT, DELETE for manipulating the table content. Statements like ALTER TABLE, DELETE TABLE, CREATE TABLE are used for creating and managing the tables.
我们可以使用INSERT、UPDATE、SELECT、DELETE等语句来操作表内容。ALTER TABLE、DELETE TABLE、CREATE TABLE等语句用于创建和管理表。
90. What do you understand by validation of ACID properties in database testing?
在数据库测试中,你对ACID属性的验证有什么理解?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba60be | 官方: 否 | 付费: 否
答案:
ACID stands for Atomicity, Consistency, Isolation and Durability. Everything refers to a property of database transactions. - Atomicity – This refers to that the transactions are atomic which means that the result of the transaction can either be a success or a failure and nothing in between.
ACID代表原子性、一致性、隔离性和持久性。所有这些都指数据库事务的属性。- 原子性——这指的是事务是原子的,意味着事务的结果只能是成功或失败,不存在中间状态。
- Consistency – This property implies that the state of the database has to remain valid after the completion of the transactions.
- Isolation – This implies that the presence of multiple transactions does not hinder each other as well as the state of the database.
- Durability – This states that post-commit of a transaction, the data should not be lost even if there is a power failure.
91. What do you understand by retesting and how is it different from data-driven testing?
你对重测试(retesting)的理解是什么?它与数据驱动测试有何不同?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6058d557c902ba60c1 | 官方: 否 | 付费: 否
答案:
Retesting refers to the method of executing the same test script using different input data every time. It helps in finding faults in the system when subjected to different inputs. The faults can be fixed and once again the system can be subjected to testing using the same scripts with the same or different inputs to check if it works fine.
重测试是指每次使用不同输入数据执行相同测试脚本的方法。它有助于在系统面对不同输入时发现其中存在的缺陷。缺陷可以被修复,然后系统可以再次使用相同脚本,并采用相同或不同的输入进行测试,以检查其是否正常运行。
Retesting is different from data-driven testing. This is because retesting is mostly a manual process that involves using a whole new data input set. Data-driven testing is an automated testing framework that has the test data and the scripts take the data and run it automatically.
重测试与数据驱动测试不同。这是因为重测试主要是一个手动过程,涉及使用一套全新的数据输入集。而数据驱动测试是一种自动化测试框架,其中包含测试数据,脚本会获取数据并自动运行。
92. Explain with an example how you can test the database manually?
举例说明如何手动测试数据库?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60c4 | 官方: 否 | 付费: 否
答案:
Database testing can be done manually as well. This requires human effort in observing the behaviour of the application when subjected to different manual test cases drafted by the testers. This can also involve observation of the behaviour in front-end applications when the backend database has changed. We can also manually check whether the record has been created, updated or deleted in the database tables post the execution of the queries.
数据库测试也可以手动进行。这需要人工努力去观察应用程序在应用测试人员编写的不同手动测试用例时的行为。这还可以涉及当后端数据库发生更改时,观察前端应用程序的行为。我们还可以在执行查询后,手动检查数据库表中的记录是否已被创建、更新或删除。
Consider an example of a database system that keeps track of student details. The operations run on the Student tables database can be validated manually by looking at the state of the records post query execution or can be validated in how the front end interface looks like.
考虑一个记录学生详细信息的数据系统示例。可以对Student表数据库运行的操作,通过查看查询执行后的记录状态进行手动验证,也可以通过前端界面的显示方式来验证。
93. How do you validate whether the database table has been updated after you enter data from the front-end application?
你如何验证在从前端应用程序输入数据后,数据库表是否已更新?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60c7 | 官方: 否 | 付费: 否
答案:
This depends on the front-end application’s interface which is being used. We can test by using the following ways: - Check for the updated data in the front-end application’s view. The view should be updated with the new value post successful insertion. This kind of testing constitutes black box testing.
这取决于所使用的前端应用程序的界面。我们可以通过以下方式进行测试:- 在前端应用程序的视图中检查更新后的数据。成功插入后,视图应使用新值进行更新。这种类型的测试构成黑盒测试。
- If there is no view available, then we can go to the database system, run the select query and check for the data manually.
- We can also use the WinRunner or QTP for checking the database update.
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
94. How is stored procedure testing done?
存储过程测试是如何进行的?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60ca | 官方: 否 | 付费: 否
答案:
Stored Procedures are similar to user-defined functions that are invoked using Cal Procedure or Execute Procedure statements. The output of these procedures is generally in the form of result sets. The stored procedures are stored in RDBMS and are readily available for the applications. These can be tested using the following techniques: - White box testing: Here, the stubs are used for invoking stored procedures and the results of those are validated against our expected results.
存储过程类似于用户自定义函数,可通过Call Procedure或Execute Procedure语句调用。这些过程的输出通常以结果集的形式呈现。存储过程存储在RDBMS中,并且可供应用程序随时使用。这些可以通过以下技术进行测试:- 白盒测试:在这里,使用桩(stubs)来调用存储过程,并将其结果与我们的预期结果进行验证。
- Black box testing: We perform operations on the front-end view of our application in a way that the stored procedures are invoked and we validate the result by observing the changes in the view.
95. How will you know if a trigger is fired or not at the time of database testing?
在数据库测试时,如何知道触发器是否被触发?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60cd | 官方: 否 | 付费: 否
答案:
To know if a trigger is fired, we will have to enable the audit logs of the table. You can refer to the steps to access logs here .
要知晓触发器是否被触发,我们必须启用表的审计日志。您可以在此处参考访问日志的步骤。
96. What are the different SQL statements that can be used for database testing?
有哪些不同的SQL语句可用于数据库测试?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60d0 | 官方: 否 | 付费: 否
答案:
Following are the SQL statements categories that can be used in database testing: - DDL – Data Definition Language:
以下是可用于数据库测试的SQL语句类别:- DDL——数据定义语言:
CREATE: Used for creating databases and their objects like tables, views etc. ALTER: Used for altering the properties of database objects. DROP: Used for dropping the database and objects of the database. TRUNCATE: Used for removing all records from a table without touching its structure. RENAME: Used for renaming the database objects. - DML – Data Manipulation Language:
CREATE:用于创建数据库及其对象,如表、视图等。ALTER:用于更改数据库对象的属性。DROP:用于删除数据库及数据库对象。TRUNCATE:用于删除表中的所有记录而不影响其结构。RENAME:用于重命名数据库对象。- DML——数据操作语言:
SELECT: Used for selecting specific records or data from the database objects. INSERT: Used for inserting new data or records into the database tables. UPDATE: Used for updating existing records. DELETE: Used for deleting existing records. - DQL – Data Query Language:SELECT queries come under data query language to query the data based on any given conditions.
SELECT:用于从数据库对象中选择特定记录或数据。INSERT:用于向数据库表中插入新数据或记录。UPDATE:用于更新现有记录。DELETE:用于删除现有记录。- DQL – 数据查询语言:SELECT查询属于数据查询语言,用于根据任何给定条件查询数据。
DCL – Data Control Language:Used for creating roles, granting permissions and controlling accesses to the database and the objects of the database. The commands that fall under DCL are:
GRANT: Used for providing the user access permissions. DENY: Used for denying the user permissions. REVOKE: Used for removing the user access. - TCL – Transaction Control Language:GRANT:用于向用户提供访问权限。DENY:用于拒绝用户权限。REVOKE:用于移除用户访问权限。- TCL – 事务控制语言:
COMMIT: Used for writing and storing changes to the database. ROLLBACK: Used for restoring the changes to the database to the last commit.
COMMIT:用于将更改写入并存储到数据库。ROLLBACK:用于将数据库更改恢复到上次提交状态。
97. What is DBMS and what is its utility? Explain RDBMS with examples.
什么是DBMS及其用途是什么?请举例解释RDBMS。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba66fd | 官方: 否 | 付费: 否
答案:
DBMS stands for Database Management System , is a set of applications or programs that enable users to create and maintain a database. DBMS provides a tool or an interface for performing various operations such as inserting, deleting, updating, etc. into a database. It is software that enables the storage of data more compactly and securely as compared to a file-based system. A DBMS system helps a user to overcome problems like data inconsistency, data redundancy, etc. in a database and makes it more convenient and organized to use it. Check this DBMS Tutorial by Scaler Topics .
DBMS代表数据库管理系统,是一组应用程序或程序,使用户能够创建和维护数据库。DBMS提供工具或接口,用于执行插入、删除、更新等操作。与基于文件的系统相比,它是一种能够更紧凑和安全地存储数据的软件。DBMS系统帮助用户克服数据库中的数据不一致、数据冗余等问题,并使其使用更方便和有条理。查看Scaler Topics提供的此DBMS教程。
Examples of popular DBMS systems are file systems, XML, Windows Registry, etc.
流行的DBMS系统示例包括文件系统、XML、Windows注册表等。
RDBMS stands for Relational Database Management System and was introduced in the 1970s to access and store data more efficiently than DBMS. RDBMS stores data in the form of tables as compared to DBMS which stores data as files. Storing data as rows and columns makes it easier to locate specific values in the database and makes it more efficient as compared to DBMS.
RDBMS代表关系数据库管理系统,于1970年代引入,以比DBMS更高效地访问和存储数据。与DBMS以文件形式存储数据相比,RDBMS以表格形式存储数据。将数据存储为行和列使得在数据库中更容易定位特定值,并且比DBMS更高效。
Examples of popular RDBMS systems are MySQL, Oracle DB, etc.
流行的RDBMS系统示例包括MySQL、Oracle DB等。
Learn More
了解更多
98. What is a Database?
什么是数据库?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6700 | 官方: 否 | 付费: 否
答案:
A Database is an organized, consistent, and logical collection of data that can easily be updated, accessed, and managed. Database mostly contains sets of tables or objects (anything created using create command is a database object) which consist of records and fields. A tuple or a row represents a single entry in a table. An attribute or a column represents the basic units of data storage, which contain information about a particular aspect of the table. DBMS extracts data from a database in the form of queries given by the user.
数据库是一个有组织、一致且逻辑性强的数据集合,可以轻松更新、访问和管理。数据库主要包含表或对象(任何使用create命令创建的都是数据库对象)的集合,这些由记录和字段组成。元组或行表示表中的单个条目。属性或列表示数据存储的基本单位,包含表特定方面的信息。DBMS以用户查询的形式从数据库中提取数据。
99. Mention the issues with traditional file-based systems that make DBMS a better choice?
提到传统基于文件的系统的问题,使DBMS成为更好的选择?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6703 | 官方: 否 | 付费: 否
答案:
The absence of indexing in a traditional file-based system leaves us with the only option of scanning the full page and hence making the access of content tedious and super slow. The other issue is redundancy and inconsistency as files have many duplicate and redundant data and changing one of them makes all of them inconsistent. Accessing data is harder in traditional file-based systems because data is unorganized in them.
传统基于文件的系统中缺少索引,使得我们只能选择扫描整个页面,从而使内容访问变得繁琐且极慢。另一个问题是冗余和不一致性,因为文件中有许多重复和冗余的数据,更改其中一个会使所有数据不一致。传统基于文件系统中访问数据更难,因为数据在其中未组织。
Another issue is the lack of concurrency control, which leads to one operation locking the entire page, as compared to DBMS where multiple operations can work on a single file simultaneously.
另一个问题是缺乏并发控制,导致一个操作锁定整个页面,而DBMS中多个操作可以同时处理单个文件。
Integrity check, data isolation, atomicity, security, etc. are some other issues with traditional file-based systems for which DBMSs have provided some good solutions.
完整性检查、数据隔离、原子性、安全性等是传统基于文件系统的其他一些问题,而DBMS为其提供了良好的解决方案。
100. Explain a few advantages of a DBMS.
解释DBMS的几点优势。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6706 | 官方: 否 | 付费: 否
答案:
Following are the few advantages of using a DBMS .
以下是使用 DBMS 的几个优点。
- Data Sharing: Data from a single database can be simultaneously shared by multiple users. Such sharing also enables end-users to react to changes quickly in the database environment.
- Integrity constraints: The existence of such constraints allows storing of data in an organized and refined manner.
- Controlling redundancy in a database: Eliminates redundancy in a database by providing a mechanism that integrates all the data in a single database.
- Data Independence: This allows changing the data structure without altering the composition of any of the executing application programs.
- Provides backup and recovery facility: It can be configured to automatically create the backup of the data and restore the data in the database whenever required.
- Data Security: DBMS provides the necessary tools to make the storage and transfer of data more reliable and secure. Authentication (the process of giving restricted access to a user) and encryption (encrypting sensitive data such as OTP, credit card information, etc.) are some popular tools used to secure data in a DBMS.
101. Explain different languages present in DBMS.
解释 DBMS 中存在的不同语言。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6709 | 官方: 否 | 付费: 否
答案:
Following are various languages present in DBMS: - DDL(Data Definition Language): It contains commands which are required to define the database.E.g., CREATE, ALTER, DROP, TRUNCATE, RENAME, etc.
以下是 DBMS 中存在的各种语言:- DDL(数据定义语言):它包含定义数据库所需的命令。例如,CREATE、ALTER、DROP、TRUNCATE、RENAME 等。
- DML(Data Manipulation Language): It contains commands which are required to manipulate the data present in the database.E.g., SELECT, UPDATE, INSERT, DELETE, etc.
- DCL(Data Control Language): It contains commands which are required to deal with the user permissions and controls of the database system.E.g., GRANT and REVOKE.
- TCL(Transaction Control Language): It contains commands which are required to deal with the transaction of the database.E.g., COMMIT, ROLLBACK, and SAVEPOINT.
102. What is meant by ACID properties in DBMS?
在 DBMS 中,ACID 属性是什么意思?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba670c | 官方: 否 | 付费: 否
答案:
ACID stands for Atomicity, Consistency, Isolation, and Durability in a DBMS these are those properties that ensure a safe and secure way of sharing data among multiple users.
ACID 代表原子性、一致性、隔离性和持久性,在 DBMS 中,这些属性确保在多用户之间安全可靠地共享数据。
- Atomicity: This property reflects the concept of either executing the whole query or executing nothing at all, which implies that if an update occurs in a database then that update should either be reflected in the whole database or should not be reflected at all.
- Consistency: This property ensures that the data remains consistent before and after a transaction in a database.
- Isolation: This property ensures that each transaction is occurring independently of the others. This implies that the state of an ongoing transaction doesn’t affect the state of another ongoing transaction.
- Durability: This property ensures that the data is not lost in cases of a system failure or restart and is present in the same state as it was before the system failure or restart.
103. Are NULL values in a database the same as that of blank space or zero?
数据库中的 NULL 值与空白或零相同吗?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6713 | 官方: 否 | 付费: 否
答案:
No, a NULL value is very different from that of zero and blank space as it represents a value that is assigned, unknown, unavailable, or not applicable as compared to blank space which represents a character and zero represents a number.
不,NULL 值与零和空白完全不同,因为它代表一个未赋值、未知、不可用或不适用的值,而空白代表一个字符,零代表一个数字。
Example: NULL value in “number_of_courses” taken by a student represents that its value is unknown whereas 0 in it means that the student hasn’t taken any courses.
示例:学生所修课程的“number_of_courses”中的 NULL 值表示其值未知,而其中的 0 表示学生尚未修任何课程。
104. State some of the uses of normalization?
列举规范化的某些用途?
- 知识点: 数据库 (标签: interviewbit, delhivery, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Delhivery
- id: 69b37a6e58d557c902ba6924 | 官方: 否 | 付费: 否
答案:
- When we are dealing with a large amount of data the chances of redundancy increase therefore normalization helps in decreasing redundancy.
- In order to decrease complexity, normalization looks at the new data types added to the table.
- A big database table can be broken up into smaller tables and linked with relationships.
- Anomalies are less likely to appear in a database with the help of normalization.
105. Differentiate between hierarchical database models and network in DBMS.
区分DBMS中的层次数据库模型和网络模型。
- 知识点: 数据库 (标签: interviewbit, deloitte, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 德勤
- id: 69b37a6f58d557c902ba69bb | 官方: 否 | 付费: 否
答案:
Data are grouped into nodes in a tree-like structure in a hierarchical database model. A node can only have one parent node above it. As a result, the data nodes in this model have one-to-many relationships. The Document Object Model (DOM), which is often used in web browsers, is an example of this model.
在层次数据库模型中,数据以树状结构分组到节点中。一个节点上方只能有一个父节点。因此,该模型中的数据节点具有一对多关系。Web 浏览器中常用的文档对象模型(DOM)就是这种模型的一个例子。
The network database model is a more sophisticated variation of the hierarchical database architecture. Data is organised in a graph-like structure here as well. One child node, on the other hand, can be connected to several parent nodes. A many-to-many relationship between data nodes is an outcome of this. Network databases include IDMS (Integrated Database Management System) and IDS (Integrated Data Store).
网状数据库模型是层次数据库架构的一种更复杂的变体。这里的数据同样以类似图的结构组织。另一方面,一个子节点可以连接到多个父节点。这导致了数据节点之间的多对多关系。网状数据库包括 IDMS(集成数据库管理系统)和 IDS(集成数据存储)。
| Hierarchical model 层次模型 | Network model 网状模型 |
|---|---|
| The relationship among the records is of the parent-child form. 记录之间的关系是父子形式。 | The relationship among the records is in the form of pointers or links 记录之间的关系以指针或链接的形式存在 |
| Inconsistencies in data may occur during the update and delete actions. 在更新和删除操作期间可能会发生数据不一致。 | Data inconsistencies do not occur. 不会发生数据不一致。 |
| It does not support many to many relationships between the data nodes. 它不支持数据节点之间的多对多关系。 | It does support many to many relationships between data nodes. 它确实支持数据节点之间的多对多关系。 |
| It generates a tree structure, and data traversal is a little complicated. 它生成树结构,数据遍历有点复杂。 | It generates a graph structure in which data traversal is simple because each node may be accessed in both directions, i.e. parent-child and vice versa. 它生成图结构,其中数据遍历很简单,因为每个节点都可以双向访问,即父到子和子到父。 |
106. What are the differences between stored procedure and triggers in SQL?
SQL 中存储过程和触发器有什么区别?
- 知识点: 数据库 (标签: interviewbit, deloitte, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 德勤
- id: 69b37a6f58d557c902ba69be | 官方: 否 | 付费: 否
答案:
Stored procedures are small pieces of PL/SQL code that perform a specific task. The user can call stored procedures directly. It's similar to a program in that it can take some input as a parameter, process it, and return values.
存储过程是执行特定任务的小段 PL/SQL 代码。用户可以直接调用存储过程。它类似于程序,可以接受一些输入作为参数,进行处理,并返回数值。
Trigger, on the other hand, is a stored process that executes automatically when certain events occur (eg update, insert, delete in a database). Triggers are similar to event handlers in that they operate in response to a specified event. Triggers are unable to accept input or return values.
另一方面,触发器是一种存储过程,在发生某些事件(例如数据库中的更新、插入、删除)时自动执行。触发器类似于事件处理程序,它们响应指定的事件而运行。触发器无法接受输入或返回值。
| Triggers 触发器 | Stored procedures 存储过程 |
|---|---|
| A trigger is a stored procedure that executes automatically in response to certain events (such as updates, inserts, and deletions). 触发器是一种存储过程,响应某些事件(如更新、插入和删除)自动执行。 | Stored procedures are sections of PL/SQL code that perform a specified operation. 存储过程是执行指定操作的 PL/SQL 代码段。 |
| It has the ability to run automatically in response to events. 它能够响应事件自动运行。 | It can be called by the user explicitly. 它可以由用户显式调用。 |
| It is unable to accept input as a parameter. 它无法接受输入作为参数。 | It has the ability to accept input as a parameter. 它能够接受输入作为参数。 |
| Transaction statements aren't allowed inside a trigger. 触发器内部不允许使用事务语句。 | Within a stored procedure, we can use transaction statements like begin transaction, commit transaction, and rollback. 在存储过程中,我们可以使用诸如 begin transaction、commit transaction 和 rollback 之类的事务语句。 |
| Triggers do not have the ability to return values. 触发器不具备返回值的能力。 | Values can be returned by stored procedures. 存储过程可以返回值。 |
107. Explain transaction atomicity in context to OS.
结合操作系统解释事务原子性。
- 知识点: 数据库 (标签: interviewbit, deloitte, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 德勤
- id: 69b37a6f58d557c902ba69e2 | 官方: 否 | 付费: 否
答案:
The transaction process can be thought of as a series of read and write activities on data, followed by a commit operation. Transaction atomicity means that if a transaction fails to finish successfully, the transaction must be aborted, and all modifications made during execution must be rolled back. It indicates that a transaction must seem like a single, non-divisible process. This guarantees that the integrity of the data being updated is preserved. If the concept of atomicity is not applied in transactions, every transaction that is cancelled in the middle may result in data inconsistency because two transactions may be sharing the same data value.
事务过程可以看作是对数据的一系列读写活动,随后是一个提交操作。事务原子性意味着,如果事务未能成功完成,则必须中止该事务,并且执行期间所做的所有修改都必须回滚。这表明事务必须看起来像是一个单一的、不可分割的过程。这保证了被更新数据的完整性得以保持。如果事务中未应用原子性概念,那么每一个中途取消的事务都可能导致数据不一致,因为两个事务可能共享同一个数据值。
108. What are some of the benefits of using Views in a Database Management System?
在数据库管理系统中使用视图有哪些好处?
- 知识点: 数据库 (标签: interviewbit, dxc, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: DXC Technology
- id: 69b37ab758d557c902ba94cc | 官方: 否 | 付费: 否
答案:
The following are some of the advantages of employing views in a database management system: - A view can represent a subset of a table's data. As a result, a view can limit the extent to which the underlying tables are visible to the outside world: for example, a user may be able to query the view but not the entire base database.
在数据库管理系统中使用视图有以下一些优点:- 视图可以表示表数据的子集。因此,视图可以限制底层表对外部世界的可见范围:例如,用户可能能够查询视图,但不能查询整个基础数据库。
- Views are aggregated tables in which the database engine aggregates data (sum, average, and so on) and shows the resulting results alongside the data.
- Using views, we may merge and simplify several tables into a single virtual table.
- Views take up very little storage space; the database just stores the view's specification, not a copy of all the data it displays.
- The complexity of data can be obscured by views.
- Views can provide additional protection depending on the SQL engine being used.
- Data Science
- All Events
- My Events
109. What do you mean by the term ‘type’ in ElasticSearch?
在 ElasticSearch 中,术语“type”是什么意思?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9828 | 官方: 否 | 付费: 否
答案:
Types are logical categories or parts of an index whose semantics are determined by the user. Elasticsearch clusters can consist of multiple Indices (databases), each of which contains several Types (tables). A type holds multiple Documents (rows), and every document has some Properties (columns). By using types, multiple data types can be stored in the same index, thus reducing the total number of indices.
类型是索引的逻辑类别或部分,其语义由用户确定。Elasticsearch 集群可以由多个索引(数据库)组成,每个索引包含多个类型(表)。一个类型包含多个文档(行),每个文档拥有一些属性(列)。通过使用类型,可以在同一索引中存储多种数据类型,从而减少索引的总数。
Example:
示例:
Suppose, in your car manufacturing scenario, you had a Tatafactory index. There are three types (tables) in this index as follows: - Cars
假设,在你的汽车制造场景中,你有一个 Tatafactory 索引。该索引中有三种类型(表),如下所示:- 汽车
- People
Spare_Parts
Every type then contains documents relevant to that type (e.g. a Tata Innova document is housed in the Cars type). In this document, you can find all the information about the particular car.每种类型随后包含与该类型相关的文档(例如,Tata Innova 文档存放在 Cars 类型中)。在此文档中,你可以找到关于该特定汽车的所有信息。
110. What do you mean by NRT (Near Real-Time Search) in ElasticSearch?
在 ElasticSearch 中,NRT(近实时搜索)是什么意思?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba982b | 官方: 否 | 付费: 否
答案:
Elasticsearch provides near real-time search functionality. It means that there is a slight delay (approximately one second) between the time you index a document and the moment it becomes searchable.
Elasticsearch 提供近实时搜索功能。这意味着,从索引文档到它变得可搜索之间存在轻微延迟(大约一秒)。
111. What are the advantages of ElasticSearch?
ElasticSearch 有哪些优点?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba982e | 官方: 否 | 付费: 否
答案:
ElasticSearch's advantages can be listed or summarized as follows: - Elasticsearch is a fast search engine: Since Elasticsearch is built on top of Apache Lucene, it provides a full-text search. The latency between the time a document is indexed and the moment it can be searched is extremely short with ElasticSearch - typically one second. This makes Elasticsearch a good choice for time-sensitive use cases such as infrastructure monitoring and security analytics.
ElasticSearch 的优点可以列出或总结如下:- Elasticsearch 是一个快速搜索引擎:由于 Elasticsearch 构建在 Apache Lucene 之上,它提供全文搜索。通过 ElasticSearch,从文档被索引到它可被搜索的时间延迟极短——通常为一秒。这使得 Elasticsearch 成为对时间敏感用例(如基础设施监控和安全分析)的良好选择。
- Elasticsearch is a distributed search engine: Elasticsearch stores or distributes documents across several containers called shards, which are duplicated to provide redundant copies of the data in the event of a hardware or system failure. Due to Elasticsearch's distributed nature, it can scale up to thousands of servers and can handle petabytes of data. You can use ElasticSearch as a replacement for document stores such as RavenDB and MongoDB.
- Elasticsearch provides a wide range of features: Aside from being scalable, fast, and resilient, Elasticsearch offers numerous built-in features like data roll-ups and index lifecycle management that make storing and searching data easier and more efficient.
- Data ingestion, visualization, and reporting are simplified with the Elastic Stack or BELEK: Data can be collected and processed easily using Beats and Logstash before being indexed in Elasticsearch. Besides providing real-time visualization of Elasticsearch data, Kibana provides UIs for quick access to log files, application performance monitoring (APM), and infrastructure metrics data.
112. How to add a mapping to an index?
如何向索引添加映射?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9831 | 官方: 否 | 付费: 否
答案:
Elasticsearch lets you add the mapping to an index based on the data provided by the user in the request body. The following syntax can be used to add a mapping to an index:
Elasticsearch 允许你根据用户在请求体中提供的数据向索引添加映射。可以使用以下语法向索引添加映射:
Syntax:
语法:
POST /_<index_name>/_type/_id
POST /_<index_name>/_type/_id
113. What is the process of deleting an index in Elasticsearch?
在 Elasticsearch 中删除索引的过程是什么?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9834 | 官方: 否 | 付费: 否
答案:
Deleting an index removes all of its shards, documents, and metadata. Use the following command to delete an index in Elasticsearch:
删除索引会移除其所有分片、文档和元数据。使用以下命令在 Elasticsearch 中删除索引:
Syntax:
语法:
DELETE /<index_name>
DELETE /<index_name>
Example: To delete an index named my-index-321, we use the following command.
示例:要删除名为 my-index-321 的索引,我们使用以下命令。
DELETE /my-index-321
DELETE /my-index-321
114. Define the terms Shard and Replica in ElasticSearch.
在 ElasticSearch 中定义术语“分片”和“副本”。
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9837 | 官方: 否 | 付费: 否
答案:
Shard: Elasticsearch crashes are often caused by large indexes. Due to the unlimited number of documents that can be stored on each index, an index may consume more disk space than the hosting server can provide. Indexing will begin to fail as soon as the index reaches this limit. As a solution to this problem, it is possible to divide or segment indexes horizontally into multiple pieces, also called shards. For an index, you can easily specify how many shards you want. As a result, every shard is its own, fully functional, and independent "index", which can run on any node in a cluster.
分片:Elasticsearch 的崩溃通常是由大型索引引起的。由于每个索引可以存储的文档数量不限,索引可能会消耗超过宿主服务器所能提供的磁盘空间。一旦索引达到此限制,索引操作将开始失败。作为此问题的解决方案,可以将索引水平划分或分割成多个部分,也称为分片。对于索引,你可以轻松指定所需的分片数量。因此,每个分片都是其自身、功能完整且独立的“索引”,可以在集群中的任何节点上运行。
Replica: As the name implies, replicas are Elasticsearch fail-safe mechanisms, and are essentially copies of an index's shards. As a backup, this could come in handy when a node crashes. Furthermore, replicas can serve read requests, which is useful for increasing search performance. To ensure high availability, replicas must not be placed on the same node as the original shard (called the "primary shared") from which they were replicated.
副本:顾名思义,副本是 Elasticsearch 的故障安全机制,本质上是索引分片的副本。作为备份,这在节点崩溃时会派上用场。此外,副本可以处理读取请求,这对于提高搜索性能很有用。为确保高可用性,副本不能放置在与原始分片(称为“主分片”)相同的节点上,该分片是它们复制来源。
115. What is an index in ElasticSearch?
在 ElasticSearch 中什么是索引?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba983a | 官方: 否 | 付费: 否
答案:
An index is a collection of documents that are somewhat similar in nature. As an example, you could have an index of customer data, another one of product catalogs, and another one of order data. The name of an index (which must be all lowercase) serves as an identifier for the index when indexing, searching, updating, and deleting documents contained within it. An index (plural: indices) can have one or more than one shards and replicas.
索引是性质上有所相似的文档集合。例如,你可以有一个客户数据的索引、另一个产品目录的索引,以及另一个订单数据的索引。索引的名称(必须全为小写)在索引、搜索、更新和删除其中包含的文档时用作索引的标识符。一个索引(复数形式为 indices)可以有一个或多个分片和副本。
116. Which operations can you perform on a document?
可以对文档执行哪些操作?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba983d | 官方: 否 | 付费: 否
答案:
Elasticsearch allows the following operations to be performed over documents: - Indexing a document
Elasticsearch 允许对文档执行以下操作: - 索引文档
- Fetching documents
- Updating documents
- Deleting documents
117. Explain what is a document in ElasticSearch.
解释在 ElasticSearch 中什么是文档。
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9840 | 官方: 否 | 付费: 否
答案:
The term "document" refers to a unit of information that can be indexed. Each index within Elasticsearch contains multiple documents. For instance, you could have a document for every customer, another for every order, etc. These documents are written in JavaScript Object Notation (JSON), which is a widely used format for internet data exchange. Documents are composed of fields, and each field has its own type of data. In a particular index, you can store as many documents as you wish.
“文档”一词指的是可以被索引的信息单元。Elasticsearch中的每个索引都包含多个文档。例如,你可以为每位客户、每笔订单等都有一个文档。这些文档以JavaScript对象表示法(JSON)编写,这是一种广泛用于互联网数据交换的格式。文档由字段组成,每个字段有自己的数据类型。在特定索引中,你可以存储任意数量的文档。
118. Explain a node in Elastic Search.
解释Elastic Search中的节点。
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9843 | 官方: 否 | 付费: 否
答案:
You can think of a node as a single server that forms part of your cluster. Nodes are assigned roles that describe their responsibilities and operations. By default, every cluster node can handle HTTP and transport traffic. Communication between nodes is carried out via the transport layer, while REST clients utilize the HTTP layer. Nodes in a cluster are aware of each other and can forward client requests to the right node.
你可以将节点视为形成集群一部分的单个服务器。节点被分配角色,这些角色描述了它们的职责和操作。默认情况下,每个集群节点都可以处理HTTP和传输流量。节点之间的通信通过传输层进行,而REST客户端使用HTTP层。集群中的节点彼此了解,并且可以将客户端请求转发到正确的节点。
119. What is cluster in ElasticSearch?
ElasticSearch中的集群是什么?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9846 | 官方: 否 | 付费: 否
答案:
A cluster is a collection of connected nodes. If you run only one instance or node of Elasticsearch, then you have a single-node cluster or a cluster of one node. Clusters automatically reorganize themselves when nodes join or leave so the data is distributed evenly among all the nodes. Despite being fully functional, the cluster is at risk of data loss if it fails.
集群是连接节点的集合。如果你只运行一个Elasticsearch实例或节点,那么你拥有一个单节点集群或一个节点的集群。当节点加入或离开时,集群会自动重新组织自身,以便数据在所有节点之间均匀分布。尽管功能完整,但如果集群发生故障,则存在数据丢失的风险。
120. What is ElasticSearch fuzzy search?
什么是ElasticSearch模糊搜索?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9849 | 官方: 否 | 付费: 否
答案:
With fuzzy search, you can find documents with terms similar to your search term based on a Levenshtein edit distance measure. Edit distance is essentially the number of single-character changes or edits required to change one term into another. Among these changes are: - Change one character (box → fox)
使用模糊搜索,你可以基于Levenshtein编辑距离度量找到与搜索词相似的术语的文档。编辑距离本质上是将一个术语转换为另一个术语所需的单字符更改或编辑次数。这些更改包括:- 更改一个字符(box → fox)
- Remove one character (black → lack)
- Insert one character (sic → sick)
Transpose two adjacent characters (act → cat)
Within a specific edit distance, the fuzzy query generates a list of all possible variations and expansions of the search term. After that, the query returns a list of all possible matches. The most relevant and exact matches appear near the top of the list.在特定的编辑距离内,模糊查询生成搜索词的所有可能变体和扩展的列表。之后,查询返回所有可能匹配的列表。最相关和精确的匹配出现在列表顶部附近。
121. What is ElasticSearch Mapping?
什么是ElasticSearch映射?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba984c | 官方: 否 | 付费: 否
答案:
ElasticSearch mappings define how documents and their fields are indexed and stored in ElasticSearch databases or ElasticSearch DBs. This defines the types and formats of the fields that appear in the documents. As a result, mapping can have a significant impact on how Elasticsearch searches for and stores data. After creating an index, we must define the mapping. An incorrect preliminary definition and mapping might lead to incorrect search results.
ElasticSearch映射定义了文档及其字段如何在Elasticsearch数据库或Elasticsearch DBs中被索引和存储。这定义了文档中出现的字段的类型和格式。因此,映射对Elasticsearch搜索和存储数据的方式有显著影响。创建索引后,我们必须定义映射。不正确的初步定义和映射可能导致不正确的搜索结果。
Types of mapping - Static mapping: Users perform static mappings when they create an index. We use static mappings to define data types and indexes. It is easy to define fields and their types when creating an index.
映射类型 - 静态映射:用户在创建索引时执行静态映射。我们使用静态映射来定义数据类型和索引。在创建索引时,定义字段及其类型很容易。
- Dynamic mapping: Elasticsearch automatically creates dynamic mappings for the tables. The dynamic mapping of Elasticsearch comes in handy when we need to store extra attributes on documents. It is not always necessary to configure field names and types when indexing documents, as these will be created automatically by Elasticsearch based on any predefined rules.
122. How do you stop the ElasticSearch search service from running on a Linux server?
如何停止在Linux服务器上运行的ElasticSearch搜索服务?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba984f | 官方: 否 | 付费: 否
答案:
To shut down or turn off the Elasticsearch service on a Linux server, you will need to 'kill' the running process. It is accomplished by sending a SIGTERM request to the process, which ends or terminates it.
要关闭或关闭Linux服务器上的Elasticsearch服务,你需要'杀死'正在运行的进程。这是通过向进程发送SIGTERM请求来实现的,这会终止或结束它。
In order to initiate the shutdown process, you must first determine the process identifier (PID) for the Elasticsearch service you wish to terminate. Grep command can be used to locate processes easily. If you wish to locate all Elasticsearch-related processes running on a server, you can use the following command:
为了启动关闭过程,你必须首先确定要终止的Elasticsearch服务的进程标识符(PID)。Grep命令可以轻松定位进程。如果你希望定位服务器上运行的所有与Elasticsearch相关的进程,可以使用以下命令:
ps -ef | grep elas
ps -ef | grep elas
After identifying the correct PID, simply execute a kill command with the PID of the Elasticsearch process. Upon successful execution of the kill command, Elasticsearch should no longer be running.
识别正确的PID后,只需执行带Elasticsearch进程PID的kill命令。kill命令成功执行后,Elasticsearch应该不再运行。
123. Can you please list out different ElasticSearch data types for the document fields?
能否请你列出文档字段的不同ElasticSearch数据类型?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9854 | 官方: 否 | 付费: 否
答案:
Field types (also called field data types) describe the type of information or data a field contains, such as a string or boolean, and its intended use. The following are some data types for document fields:
字段类型(也称为字段数据类型)描述了字段包含的信息或数据类型,例如字符串或布尔值,以及其预期用途。以下是文档字段的一些数据类型:
Common data types: - Binary: A binary value that is encoded as a Base64 string.
常见数据类型:- 二进制:以Base64字符串编码的二进制值。
- Boolean: A true or false value.
- Keywords: The keyword family, which includes the keyword, constant keyword, and wildcard.
- Numbers: Numeric types such as long, double, float, bytes, integer, etc.
- Dates: Date types, such as date_nano, date.
Alias: Represents the alias of an existing field.
Objects and relational types: - Object: Represent a JSON object.对象和关系类型:- 对象:表示一个JSON对象。
- Nested: A JSON object that maintains a relationship between its subfields.
- Flattened: An entire JSON object represented by a single field value.\
Join: Establishes a parent/child relationship between documents within an index.
Structured and Spatial data types: - Range: Range types, like date_range, long_range, float_range, double_range, and IP_range.结构化和空间数据类型:- 范围:范围类型,如date_range、long_range、float_range、double_range和IP_range。
- Point: Arbitrary cartesian points.
- Geo_point: Longitude and latitude points
- Shape: Arbitrary cartesian geometries.
- Geo_shape: Complex shapes like polygons.
124. How does ElasticSearch work?
ElasticSearch是如何工作的?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9857 | 官方: 否 | 付费: 否
答案:
The Working of ElasticSearch is summarized as follows: - Firstly, raw data is gathered from a variety of sources, such as log files, system metrics, or web applications. Beats are lightweight data shipping agents (data shippers) that collect different types of data and forward it to Logstash.
ElasticSearch的工作原理总结如下:- 首先,从各种来源收集原始数据,例如日志文件、系统指标或Web应用程序。Beats是轻量级的数据传输代理(数据托运器),负责收集不同类型的数据并将其转发到Logstash。
- This raw data is normalized, analyzed, and enriched prior to being indexed in Elasticsearch. Logstash performs several transformations and enhancements, and then sends the data to be indexed in Elasticsearch.
- As soon as the data has been indexed in Elasticsearch, then users can run queries against it, and then aggregate it to generate insights. ElasticSearch enables you to store, search, and analyze vast or huge amounts of data in near real-time, providing results in milliseconds.
- Lastly, from Kibana, users can create powerful visualizations of data, and visualize complex queries through interactive diagrams, geospatial data, and graphs.
125. What is ElasticSearch used for?
ElasticSearch有什么用途?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba985e | 官方: 否 | 付费: 否
答案:
Elasticsearch's speed and scalability as well as its ability to index different types of data make it ideal for a number of use cases. In addition to its high scalability, Elasticsearch also offers near-real-time search capabilities. All this adds up to a solution that offers much more than a search engine and supports many operational and critical business use cases. Since Elasticsearch has powerful search capabilities, it is typically the underlying technology for applications requiring complex search requirements. Listed below are some of the use cases of ElasticSearch: - Application search, Enterprise search, and Website search.
Elasticsearch的速度和可扩展性以及其索引不同类型数据的能力使其非常适合多种使用场景。除了高可扩展性外,Elasticsearch还提供近实时搜索能力。所有这些组合成一个解决方案,不仅仅是一个搜索引擎,还支持许多运营和关键的业务用例。由于Elasticsearch具有强大的搜索能力,它通常是需要复杂搜索需求的应用程序的底层技术。以下列出了一些ElasticSearch的使用场景:- 应用程序搜索、企业搜索和网站搜索。
- Analyzing log data in near-real-time and on a scalable basis.
- Business analytics and security analytics.
- Analysis and visualization of geospatial data.
- Monitoring the performance of applications.
- Monitoring infrastructure metrics and containers.
126. SQL question: Problem Statement: Find the second largest value in a specified column of a relation or table.
SQL 问题:问题陈述:查找关系或表的指定列中的第二大值。
- 知识点: 数据库 (标签: interviewbit, ey, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 安永
- id: 69b37aee58d557c902bab5f4 | 官方: 否 | 付费: 否
答案:
Input:
输入:
| Employee Name 员工姓名 | Salary 薪资 |
|---|---|
| Rajesh | 34000 |
| Amit | 20000 |
| Harshit | 24000 |
| Mukul | 31000 |
Output:
输出:
31000
Method 1:
方法1:
SELECT MAX (name_of_column) FROM name_of_table WHERE name_of_column NOT IN (SELECT MAX (name_of_column) FROM name_of_table);
SELECT MAX (name_of_column) FROM name_of_table WHERE name_of_column NOT IN (SELECT MAX (name_of_column) FROM name_of_table);
Explanation:
说明:
Here, firstly we are finding the maximum value in the specified column and then we are searching again by excluding the found maximum value.
这里,首先我们找到指定列中的最大值,然后再次搜索时排除已找到的最大值。
Method 2:
方法2:
SELECT name_of_column
SELECT name_of_column
FROM name_of_table p
FROM name_of_table p
WHERE 2 = (SELECT COUNT (DISTINCT name_of_column) FROM name_of_table q WHERE p.column_name <= q.column_name)
WHERE 2 = (SELECT COUNT (DISTINCT name_of_column) FROM name_of_table q WHERE p.column_name <= q.column_name)
We have used a nested sub-query above. Note that this is a generic SQL query that prints the nth largest value. For each record processed by the outer query, the inner query would be executed and it will return how many records have a value lesser than the current value. As our task here is to determine the second largest value, therefore we will stop as soon as the inner returns 2.
上面我们使用了嵌套子查询。注意,这是一个通用的SQL查询,用于打印第n大的值。对于外层查询处理的每条记录,内层查询都会执行,并返回有多少条记录的值小于当前值。由于这里的任务是确定第二大的值,因此一旦内层返回2,我们就会停止。
127. What do you mean by “normalization”?
“规范化”是什么意思?
- 知识点: 数据库 (标签: interviewbit, ey, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 安永
- id: 69b37aee58d557c902bab5fd | 官方: 否 | 付费: 否
答案:
- Normalization is a way to keep data in the database in an organized manner. In this process, tables are created and relationships are established according to the rules designed to protect the data and to make the database flexible by removing redundancy and inconsistent dependency. Normalization is crucial for many reasons.
- But more specifically, it is important because it enables databases to take up less disk space resulting in increased performance.
128. What is a transparent DBMS?
什么是透明DBMS?
- 知识点: 数据库 (标签: interviewbit, ey, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 安永
- id: 69b37aef58d557c902bab615 | 官方: 否 | 付费: 否
答案:
A transparent DBMS is one that keeps its physical structure hidden from the users.
透明DBMS是一种对用户隐藏其物理结构的DBMS。
129. Report the second highest salary from the Employees table using the SQL query provided. If no second highest salary is reported, the query should return null.
使用提供的SQL查询从Employees表中报告第二高的薪水。如果没有第二高的薪水,查询应返回null。
- 知识点: 数据库 (主题: general-programming;标签: interviewbit, genc, topic-specific, general-programming)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37afd58d557c902babef0 | 官方: 否 | 付费: 否
答案:
Table: Employee
表:Employee
| Column 列 | Type 类型 |
|---|---|
| id | int |
| salary | int |
SELECT max(salary) as SecondHighestSalary
SELECT max(salary) as SecondHighestSalary
FROM employee
FROM employee
WHERE salary <
WHERE salary <
(SELECT max(salary)
(SELECT max(salary)
FROM Employee)
FROM Employee)
130. What is the difference between Database and Database Management System?
数据库和数据库管理系统有什么区别?
- 知识点: 数据库 (主题: general-programming;标签: interviewbit, genc, topic-specific, general-programming)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37afe58d557c902babf0e | 官方: 否 | 付费: 否
答案:
Databases are the collection of data that are stored for future use. The database management system is the software that manages the database and its operation. Here are a couple of differences that can help in better understanding the differences between these terms.
数据库是存储起来以备未来使用的数据集合。数据库管理系统是管理数据库及其操作的软件。以下是一些差异,有助于更好地理解这些术语之间的区别。
| Database 数据库 | Database Management System 数据库管理系统 |
|---|---|
| A database is a repository of connected information about people, locations, or things. 数据库是关于人员、地点或事物的关联信息的存储库。 | A database management system (DBMS) is a set of software programs that allow you to create, manage, and operate a database. 数据库管理系统(DBMS)是一组软件程序,允许你创建、管理和操作数据库。 |
| A database management system (DBMS) is a set of software programs that allow you to create, manage, and operate a database. 数据库管理系统(DBMS)是一组软件程序,允许你创建、管理和操作数据库。 | A computer database management system (DBMS) keeps all the records in one place. 计算机数据库管理系统(DBMS)将所有记录保存在一个地方。 |
| Databases are not intended for a high number of people who can access data at the same time, but rather for a small number of people (preferably no more than a few people) who access data at different times. 数据库并非面向大量可同时访问数据的人群,而是面向在不同时间访问数据的小部分人群(最好不超过几个人)。 | A large number of people can access the data at the same time through the database management system. 大量人员可以通过数据库管理系统同时访问数据。 |
| When it comes to databases, you can make very little change at a time. 对于数据库,你一次只能进行很小的更改。 | A database management system (DBMS) is able to handle a lot of requests at one time (because it is used by many people at once). 数据库管理系统(DBMS)能够一次处理大量请求(因为它同时被许多人使用)。 |
| Without using SQL, retrieving information from databases can be very slow. 不使用SQL,从数据库检索信息可能会非常缓慢。 | It is quite easy to retrieve information in a database management system computer system because of which, the retrieval is fast. 在数据库管理系统计算机系统中,检索信息相当容易,因此检索速度很快。 |
| (C, C++, Java, etc.) can be used to retrieve information from the databases manually, through queries, or with programs. (C、C++、Java等)可用于手动、通过查询或程序从数据库检索信息。 | Queries written in SQL, or the statement written in NoSQL can retrieve the data from the database management system. 用SQL编写的查询或NoSQL编写的语句可以从数据库管理系统中检索数据。 |
GenC Interview Preparation
131. What is meant by Proactive Updates, Retroactive Updates and Simultaneous Update in Database Management Systems?
在数据库管理系统中,主动更新、追溯更新和同时更新分别是什么意思?
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37afe58d557c902babf74 | 官方: 否 | 付费: 否
答案:
The meaning of the given terms are as follows: - Proactive Updates: These changes are made to the database before it is put into use in the actual world.
所给术语的含义如下:- 主动更新:这些更改是在数据库投入实际使用之前所做的。
- Retroactive Updates: These updates are applied to a database after it has been operational in the real world.
- Simultaneous Updates: These updates are applied to the database at the same moment as they become effective in the actual world.
132. What is meant by Intension and Extension in Database Management Systems?
在数据库管理系统中,Intension 和 Extension 分别指什么?
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37afe58d557c902babf77 | 官方: 否 | 付费: 否
答案:
The meaning of Intension and Extension are as follows: - Intension: Intension, often known as Database Schema, is a term that refers to the description of a database. This is defined during database design and is largely unmodified.
Intension 和 Extension 的含义如下:- Intension:Intension,通常称为数据库模式(Database Schema),是指数据库的描述。它在数据库设计期间定义,并且基本不会修改。
- Extension: The number of tuples available in the database at any given time is referred to as the extension. The value of this variable changes as tuples are created, updated, and destroyed. As a result, the data in the database at a certain point in time is referred to as the database's extension or, more generally, the database's snapshot.
133. Define Index Hunting. What is it used for in Database Management Systems?
什么是索引查找(Index Hunting)?它在数据库管理系统中有什么用途?
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37afe58d557c902babf7a | 官方: 否 | 付费: 否
答案:
Index hunting is the process of enhancing a collection of indices. The purpose of doing Index Hunting is that indexes make the performance of the queries better and also reduce the time required to process a query. Given below are the various ways in which Index Hunting improves the performance of the queries: - The most optimal queries are suggested with the usage of the query optimizer.
索引查找是优化索引集合的过程。进行索引查找的目的是,索引能提升查询性能,并减少处理查询所需的时间。以下是索引查找改善查询性能的各种方式:- 查询优化器会建议最合适的查询。
- For checking the effect, measurements such as index, query distribution, and performance are used.
- Optimization is also done on the databases for a few of the problem queries.
134. What do you understand about transactions in SQL? What are the properties of transactions in SQL?
你如何理解 SQL 中的事务?SQL 中事务的属性有哪些?
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37afe58d557c902babf7d | 官方: 否 | 付费: 否
答案:
A transaction is a logical unit of work performed on a database. Transactions are logically ordered units or sequences of work that can be completed manually by a human or automatically by a database application. The propagation of one or more changes to the database is referred to as a transaction. For instance, whether you create, update, or delete a record from a table, you are completing a transaction on that table. To preserve data integrity and address database issues, it's critical to keep track of these transactions. In practice, you will group several SQL queries together and run them all at the same time as part of a transaction. Transactions n SQL contain the four standard qualities listed below, which are frequently abbreviated as ACID. - Atomicity: Atomicity ensures the successful completion of all processes inside the work unit. Otherwise, the transaction will be aborted at the point of failure, and all preceding activities would be reversed.
事务是在数据库上执行的逻辑工作单元。事务是由人手动或由数据库应用程序自动完成的逻辑有序单元或工作序列。一个或多个数据库更改的传播称为事务。例如,无论你是创建、更新还是删除表中的记录,你都在对该表执行一个事务。为了保持数据完整性并解决数据库问题,跟踪这些事务至关重要。实际上,你会将多个 SQL 查询分组在一起,并在一个事务中同时运行它们。SQL 中的事务包含以下四个标准特性,通常缩写为 ACID。- 原子性:原子性确保工作单元内所有过程的成功完成。否则,事务将在失败点中止,并且所有先前操作将被撤销。
- Consistency: When a transaction is successfully committed, consistency ensures that the database changes states properly.
- Isolation: Isolation allows transactions to execute independently of one another while remaining transparent to them.
- Durability: Durability ensures that a committed transaction's outcome or effect is preserved in the event of a system failure.
135. Define Subqueries in SQL. Given a table of employees, write down a SQL query using subqueries to find all the employees with salaries greater than five thousand.
在 SQL 中定义子查询。给定一个员工表,写一个使用子查询的 SQL 查询,以找出所有薪水大于五千的员工。
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37afe58d557c902babf80 | 官方: 否 | 付费: 否
答案:
A subquery in SQL is a query that is defined inside another query to retrieve data or information from the database. The outer query of a subquery is referred to as the main query, while the inner query is referred to as the subquery. Subqueries are always processed first, and the subquery's result is then passed on to the main query. It can be nested inside any query, including SELECT, UPDATE, and OTHER. Any comparison operators, such as >, or =, can be used in a subquery. The syntax of a subquery in SQL is given as follows:
SQL 中的子查询是在另一个查询内部定义以从数据库检索数据或信息的查询。子查询的外部查询称为主查询,而内部查询称为子查询。子查询总是首先处理,然后子查询的结果传递给主查询。它可以嵌套在任何查询中,包括 SELECT、UPDATE 和其他查询。子查询中可以使用任何比较运算符,例如 > 或 =。SQL 中子查询的语法如下:
SELECT columnName [, columnName ]
SELECT columnName [, columnName ]
FROM tableOne [, tableTwo ]
FROM tableOne [, tableTwo ]
WHERE columnName OPERATOR
WHERE columnName OPERATOR
(SELECT columnName [, columName ]
(SELECT columnName [, columName ]
FROM tableOne [, tableTwo ]
FROM tableOne [, tableTwo ]
[WHERE])
[WHERE])
A SQL query using subqueries to find all the employees with salaries greater than five thousand in the employee's table is given below:
下面给出一个使用子查询查找员工表中所有工资超过五千的员工的 SQL 查询:
SQL> SELECT * FROM EMPLOYEES
SQL> SELECT * FROM EMPLOYEES
WHERE EMPLOYEE_ID IN (SELECT EMPLOYEE_ID
WHERE EMPLOYEE_ID IN (SELECT EMPLOYEE_ID
FROM EMPLOYEES
FROM EMPLOYEES
WHERE SALARY > 4500) ;
WHERE SALARY > 4500) ;
136. State the various levels of data abstraction in Database Management Systems.
说明数据库管理系统中的数据抽象的各种级别。
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37aff58d557c902babf8c | 官方: 否 | 付费: 否
答案:
In Database Management Systems, there are three basic levels of data abstraction. They are as follows: - Physical Level: The physical level of abstraction specifies how data is stored and is the lowest degree of abstraction.
在数据库管理系统中,有三个基本的数据抽象级别。它们如下:- 物理级:抽象的物理级规定了数据如何存储,是抽象的最低级别。
- Logical or Conceptual Level: After the Physical level, there is the Logical level of abstraction. This layer decides what data is saved in the database and how the data pieces relate to one another.
- View Level: The greatest level of abstraction, the View Level describes only a portion of the entire database.
137. What are Database objects in Database Management Systems?
数据库管理系统中的数据库对象是什么?
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37aff58d557c902babfa8 | 官方: 否 | 付费: 否
答案:
A database object is any object defined in a database that is used to store or reference data. Everything we create from the create command is called a database object. It can be used to store and manipulate data. Some examples of database objects are as follows: - Table - Table is a basic storage unit with compound rows and columns. Its syntax is as follows:
数据库对象是在数据库中定义的、用于存储或引用数据的任何对象。我们通过 create 命令创建的所有内容都称为数据库对象。它可以用于存储和操作数据。数据库对象的一些示例如下:- 表 - 表是具有复合行和列的基本存储单元。其语法如下:
CREATE TABLE [schema.]table (column datatype DEFAULT expr); - Views - Views are a logical representation of subsets of data from one or more tables. A view is a logical table that is based on another view or a table. A view is similar to a window through which data from tables can be viewed or updated, but it does not include any data of its own. Base tables are the tables that a view is built on. In the data dictionary, the view is saved as a SELECT statement. Its syntax is as follows:
CREATE TABLE [schema.]table (column datatype DEFAULT expr); - 视图 - 视图是一个或多个表中数据子集的逻辑表示。视图是基于另一个视图或表的逻辑表。视图类似于一个窗口,通过它可以查看或更新表中的数据,但它本身不包含任何数据。基表是视图所基于的表。在数据字典中,视图保存为一条 SELECT 语句。其语法如下:
CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view
CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view
[(alias[, alias]...)]
[(alias[, alias]...)]
AS subquery
AS subquery
[WITH CHECK OPTION [CONSTRAINT constraint]]
[WITH CHECK OPTION [CONSTRAINT constraint]]
[WITH READ ONLY [CONSTRAINT constraint]]; - Sequence - Sequences generate primary key values. A sequence is a database object that has been created by a user and can be shared by several users to generate unique integers. The creation of a primary key value, which must be unique for each row, is a common use for sequences. An internal Oracle routine generates the sequence and increments (or decrements) it. Its syntax is as follows:
[WITH READ ONLY [CONSTRAINT constraint]]; - 序列 - 序列生成主键值。序列是由用户创建的数据库对象,可以由多个用户共享以生成唯一的整数。创建主键值(每行必须唯一)是序列的常见用途。内部Oracle例程生成序列并递增(或递减)它。其语法如下:
CREATE SEQUENCE sequence
CREATE SEQUENCE sequence
[INCREMENT BY n]
[INCREMENT BY n]
[START WITH n]
[START WITH n]
[{MAXVALUE n | NOMAXVALUE}]
[{MAXVALUE n | NOMAXVALUE}]
[{MINVALUE n | NOMINVALUE}]
[{MINVALUE n | NOMINVALUE}]
[{CYCLE | NOCYCLE}]
[{CYCLE | NOCYCLE}]
[{CACHE n | NOCACHE}]; - Indexes - Indexes are used to improve the performance of some queries on the databases. This database object is used to create an index in the database. It is a schema object that can speed up row fetching by using a pointer. Indexes can be created explicitly or automatically. If you don't have an index on the column, full crawling of the table will occur. Indexes provide direct and fast access to table rows. Its goal is to reduce disk Input and Output needs by using an indexed path to quickly locate data. The index is used and maintained automatically by the database server. Once an index is created, no direct action is required by the user. Indexes are logically and physically independent of the table they index. This means they can be created or deleted at any time and do not affect the base tables or other indexes. Its syntax is as follows:
[{CACHE n | NOCACHE}]; - 索引 - 索引用于提高数据库上某些查询的性能。此数据库对象用于在数据库中创建索引。它是一个模式对象,可以通过使用指针加速行提取。索引可以显式或自动创建。如果列上没有索引,将发生全表扫描。索引提供对表行的直接和快速访问。其目标是通过使用索引路径快速定位数据来减少磁盘输入和输出需求。索引由数据库服务器自动使用和维护。一旦创建索引,用户无需直接操作。索引在逻辑和物理上独立于其所索引的表。这意味着它们可以随时创建或删除,并且不影响基表或其他索引。其语法如下:
CREATE INDEX index
CREATE INDEX index
ON table (column[, column]...); - Synonyms - This database object is used to build database indexes. It creates a synonym to make object access easier (another name for an object). You can use synonyms to make referring to a table owned by another user easier and to shorten long object names. You must prefix the table name with the name of the user who created it, followed by a period, to refer to a table owned by another user. Creating a synonym for a table, view, sequence, procedure, or other object avoids the requirement to qualify the object name with the schema and gives you an alternate name. This approach is very handy when dealing with long object names, such as views.In terms of syntax, the meaning of various things are as follows:
ON table (column[, column]...); - 同义词 - 此数据库对象用于构建数据库索引。它创建同义词以使对象访问更容易(对象的另一个名称)。您可以使用同义词使引用另一个用户拥有的表更容易,并缩短长对象名称。要引用另一个用户拥有的表,必须在表名前加上创建它的用户名,后跟一个句点。为表、视图、序列、过程或其他对象创建同义词可避免使用模式限定对象名称的要求,并为您提供替代名称。在处理长对象名称(如视图)时,这种方法非常方便。在语法方面,各种内容的含义如下:
PUBLIC: creates a synonym accessible to all users SYNONYM: it is the name of the synonym to be created OBJECT: identifies the object for which the synonym is created
PUBLIC:创建所有用户均可访问的同义词 SYNONYM:要创建的同义词的名称 OBJECT:标识为其创建同义词的对象
Its syntax is as follows:
其语法如下:
CREATE [PUBLIC] SYNONYM synonym FOR object;
CREATE [PUBLIC] SYNONYM synonym FOR object;
138. State some benefits of using views in a Database Management System.
说明在数据库管理系统中使用视图的一些好处。
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37aff58d557c902babfab | 官方: 否 | 付费: 否
答案:
Some benefits of using views in a Database Management System are as follows: - Views can represent a subset of the data in a table. As a result, a view can limit the extent to which the underlying tables are exposed to the outside world: a user may be allowed to query the view but not the whole of the base database.
在数据库管理系统中使用视图的一些好处如下: - 视图可以表示表中数据的子集。因此,视图可以限制底层表对外部世界的暴露程度:可以允许用户查询视图,但不能查询整个基础数据库。
- Views can be used as aggregated tables, in which the database engine aggregates data (sum, average, and so on) and displays the generated results alongside the data.
- Views allow us to combine and simplify numerous tables into a single virtual table.
- Views take up extremely minimal storage space; the database simply maintains the specification of a view, not a copy of all the data it displays.
- Views can obscure data complexity.
- Views can give additional security depending on the SQL engine utilized.
139. State your understanding of Entity Relationship (or the ER) model. Also, define the following terms: Entities, Entity Types, and Entity Sets in Database Management Systems.
说明您对实体关系(或ER)模型的理解。此外,在数据库管理系统中定义以下术语:实体、实体类型和实体集。
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37aff58d557c902babfb2 | 官方: 否 | 付费: 否
答案:
A diagrammatic approach to database architecture in which real-world things are represented as entities and relationships between them are indicated is known as an Entity-Relationship model. Given below is an image of a sample ER diagram for a student studying in college.
一种数据库架构的图解方法,其中现实世界的事物被表示为实体,它们之间的关系被表示出来,这被称为实体-关系模型。下面是一张示例ER图,用于展示一个在大学学习的学生。
The definition of the given terms are as follows: - Entity: A real-world object with attributes that indicate the object's qualities is defined as an entity. A student, an employee, or a teacher, for example, symbolizes an entity.
所给术语的定义如下:- 实体:具有指示对象品质的属性的现实世界对象被定义为实体。例如,一个学生、一名员工或一位教师代表一个实体。
- Entity Type: A group of entities with the same attributes is referred to as an entity type. An entity type is represented by one or more linked tables in a database. Entity type or attributes can be thought of as a trait that distinguishes the entity from others. A student, for example, is an entity with properties such as student id, student name, and so on.
- Entity Set: An entity set is a collection of all the entities in a database that belongs to a given entity type. For instance, a group of all students, employees, teachers, and so on represents an entity set.
140. What do you understand about the ACID properties in Database Management Systems?
关于数据库管理系统中的ACID属性,你了解什么?
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37aff58d557c902babfb8 | 官方: 否 | 付费: 否
答案:
ACID is an acronym for Atomicity, Consistency, Isolation, and Durability. A transaction is a logical unit of work that reads and updates the contents of a database in some instances. Transactions employ read and write operations to access data. To maintain database consistency, certain properties are followed before and after a transaction. They are referred to as ACID properties. Let us now take a closer look at each of these characteristics: - Atomicity: When a transaction is atomic, it means that it either happens all at once or it does not happen at all. There is no intermediate ground, which means that there are no steps to transactions. Each transaction is viewed as a single entity that is either completed or not. It entails the two processes listed below.
ACID是原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持久性(Durability)的缩写。事务是一个逻辑工作单元,在某些情况下读取和更新数据库的内容。事务使用读和写操作来访问数据。为了保持数据库一致性,在事务前后遵循某些属性。它们被称为ACID属性。现在让我们更仔细地看看这些特性:- 原子性:当一个事务是原子的时,意味着它要么全部发生,要么根本不发生。没有中间状态,这意味着事务没有中间步骤。每个事务都被视为一个单一实体,要么完成,要么未完成。它涉及下面列出的两个过程。
Abort: Any database updates are lost if a transaction aborts. Commit: When a transaction commits, the changes contained within it become visible. Atomicity is often known as the "all or nothing rule.
中止:如果事务中止,任何数据库更新都会丢失。提交:当事务提交时,其中包含的更改变得可见。原子性通常被称为“全有或全无规则”。
Think about the following scenario: T, which is made up of two separate transactions: T1 and T2. A $100 transfer was made from account X to account Y. The amount deducted from X but not added to Y is deducted if a transaction fails after T1 but before T2 (for example, after write(X) but before write(Y)). As a result, the database is in a state of inconsistency. As a result, to ensure that the database state is legitimate, the transaction must be completed in its entirety. - Consistency: To ensure that the database is consistent, integrity constraints must be maintained both before and after the transaction. It relates to the accuracy of a database. As seen in the sample above, the total amount before and after the transaction must be maintained.The total before T is 500 + 200 = 700.The total after T is 400 + 300 = 700.As a result, the database is well-organized. There is inconsistency when T1 succeeds but T2 fails. As a result, T isn't finished.
考虑以下场景:T由两个独立的事务组成:T1和T2。从账户X向账户Y转移了100美元。如果在T1之后但在T2之前事务失败(例如,在write(X)之后但在write(Y)之前),则从X扣除的金额未添加到Y。因此,数据库处于不一致状态。因此,为了确保数据库状态合法,事务必须完整完成。- 一致性:为了确保数据库一致,必须在事务前后维护完整性约束。它与数据库的准确性有关。如上面的示例所示,事务前后的总额必须保持不变。T之前的总额是500 + 200 = 700。T之后的总额是400 + 300 = 700。因此,数据库是有序的。当T1成功但T2失败时,就会出现不一致。因此,T没有完成。
- Isolation: This property ensures that several transactions can run concurrently without generating database state inconsistencies. Transactions are carried out in a non-disruptive manner. Changes in one transaction are not visible to other transactions until the change for that transaction is put to memory or committed. This feature ensures that concurrently running transactions provide the same state as if they were run sequentially in some order. To better understand Isolation, consider the following scenario. Let us say X and Y are both 500, and there are two transactions T and T."
Assume T has been operating until Read (Y), after which T" will start. T" reads the correct value of X but the incorrect value of Y as a result of this interleaving, and the sum computed by T" (X+Y = 50, 000+500=50, 500) is inconsistent with the sum at the end of the transaction: T = 50, 000 + 450 = 50, 450 (X+Y = 50, 000 + 450 = 50, 450). This results in a database inconsistency due to the loss of 50 units. As a result, transactions must be carried out in isolation, and modifications should be seen only after they have been written to the main memory. - Durability: This property ensures that database updates and modifications are stored and written to disk after the transaction has concluded and that they survive even if the system fails. These modifications are now permanently recorded in nonvolatile memory. As a result, the transaction's effects are never lost.
假设T一直运行到Read (Y),之后T"将开始。由于这种交错,T"读取了正确的X值但错误的Y值,并且T"计算的总和(X+Y = 50, 000+500=50, 500)与事务结束时的总和:T = 50, 000 + 450 = 50, 450(X+Y = 50, 000 + 450 = 50, 450)不一致。这由于丢失50个单位而导致数据库不一致。因此,事务必须隔离执行,并且修改应仅在写入主存后才可见。- 持久性:此属性确保在事务结束后数据库更新和修改被存储并写入磁盘,并且即使系统发生故障它们也能存活。这些修改现在永久记录在非易失性存储器中。因此,事务的影响永远不会丢失。
Each transaction is a series of actions that works as a single unit, provides consistent outcomes, is separated from other processes, and the modifications it makes are durably stored, according to the ACID properties.
根据ACID属性,每个事务是一系列操作,作为单个单元工作,提供一致的结果,与其他过程隔离,并且它所做的修改被持久存储。
141. Define the terms: Aggregation and Atomicity in Database Management Systems.
定义数据库管理系统中的术语:聚合和原子性。
- 知识点: 数据库 (标签: interviewbit, genpact, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Genpact
- id: 69b37aff58d557c902babfbb | 官方: 否 | 付费: 否
答案:
The definition of the given terms are as follows: - Aggregation: Aggregation is an Entity Relationship model feature that allows one relationship set to interact with another relationship set.
所给术语的定义如下:- 聚合:聚合是实体关系模型的一个特性,它允许一个关系集与另一个关系集交互。
Atomicity: The atomicity attribute specifies that a database alteration must either adhere to all of the rules or not at all. As a result, if one portion of the transaction fails, the transaction as a whole fails.
GenPact Interview Preparation
142. What is a join in SQL?
SQL中的连接是什么?
- 知识点: 数据库 (标签: interviewbit, goldman-sachs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 高盛
- id: 69b37b1458d557c902bacbfe | 官方: 否 | 付费: 否
答案:
Joins in SQL join rows from two or more tables based on a shared column. The different categories of joins are: - INNER JOIN returns rows when both tables have a match.
SQL中的连接基于共享列连接来自两个或多个表的行。连接的不同类别有:- INNER JOIN在两个表都有匹配时返回行。
- LEFT JOIN returns all rows from the left table, even if the right table has no matches.
- RIGHT JOIN returns all rows from the right table, even if the left table doesn't have any matches.
- FULL OUTER JOIN returns rows when one of the tables has a match.
- SELF JOIN is a SQL statement that joins a table to itself as if it were two tables, temporarily renaming at least one table.
CARTESIAN JOIN (CROSS JOIN) returns the Cartesian product of two or more joined tables' sets of records.
Additional Resources其他资源
SQL
SQL
Data Structures
数据结构
OOPs
面向对象编程
Java
Java
JavaScript
JavaScript
Networking
网络
143. What is a Database Transaction? And why are Database Transactions Important?
什么是数据库事务?为什么数据库事务很重要?
- 知识点: 数据库 (标签: interviewbit, hashedin, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HashedIn
- id: 69b37b3058d557c902badbba | 官方: 否 | 付费: 否
答案:
A database transaction is a set of operations that are treated as a single unit of work. If one operation fails, then the entire transaction is rolled back (canceled) and the data is restored to the state it was in before the transaction started. Transactions ensure that the database maintains its integrity by preventing data from being corrupted or lost if one of its components fails. If no transaction is specified, the database system will treat each SQL statement as an independent transaction, which can lead to inconsistent data and errors if any of the SQL statements fail.
数据库事务是一组被视为单一工作单元的操作。如果一个操作失败,则整个事务被回滚(取消),数据恢复到事务开始前的状态。事务通过防止在某个组件发生故障时数据被损坏或丢失,确保数据库保持其完整性。如果未指定事务,数据库系统会将每条SQL语句视为独立的事务,这可能导致数据不一致,并且如果任何SQL语句失败还会引发错误。
The main reason database transactions are important is to ensure data integrity. When using a database, there is always a risk that something might go wrong and cause an error, or worse, corrupt data. Transactions can be set to automatically roll back if an error occurs, thus preventing data from being changed in the case of an error. If you’re writing data to your database, it’s important to use database transactions. By doing so, you can ensure that your data is written correctly and that if there’s an error, it will be rolled back so no data is lost. If you don’t use database transactions, an error could cause your data to be written incorrectly or not written at all.
数据库事务之所以重要的主要原因是确保数据完整性。使用数据库时,总是存在某些环节出错并导致错误、甚至更糟——损坏数据的风险。事务可以设置为在发生错误时自动回滚,从而在出错时防止数据被更改。如果你正在向数据库写入数据,使用数据库事务很重要。通过这样做,你可以确保数据被正确写入,并且如果出现错误,它将被回滚,从而不会丢失任何数据。如果你不使用数据库事务,错误可能导致数据被错误写入或完全未写入。
144. What are Databases?
什么是数据库?
- 知识点: 数据库 (标签: interviewbit, hashedin, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HashedIn
- id: 69b37b3058d557c902badbc6 | 官方: 否 | 付费: 否
答案:
Databases consist of logical, consistent, and organized data that can be accessed, managed, and updated easily. It is also known as an electronic database. Electronic databases are structured to provide the facility of creating, inserting, and updating data efficiently. They are typically stored on magnetic disks, tapes, or another sort of secondary storage medium. Objects in the database are called tables, and the records and fields are called records. An entity described by a database is described in terms of fields, which contain information about particular aspects or attributes of that entity. Database management systems are used to extract data from databases using queries.
数据库由逻辑上一致且有组织的数据组成,这些数据可以轻松地被访问、管理和更新。它也被称为电子数据库。电子数据库的结构旨在提供高效创建、插入和更新数据的功能。它们通常存储在磁盘、磁带或另一种二级存储介质上。数据库中的对象称为表,记录和字段称为记录。数据库所描述的实体通过字段来描述,字段包含有关该实体特定方面或属性的信息。数据库管理系统用于通过查询从数据库中提取数据。
145. What do you mean by DBMS?
你说的DBMS是什么意思?
- 知识点: 数据库 (标签: interviewbit, hcl, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: HCL Technologies
- id: 69b37b3658d557c902badf6e | 官方: 否 | 付费: 否
答案:
The Database management system (DBMS), is software or a tool that helps in managing the data of the entire organization. Large amounts of data can be stored properly and can be presented as information whenever required to take business decisions.
数据库管理系统(DBMS)是帮助管理整个组织数据的软件或工具。大量数据可以被妥善存储,并在需要做出业务决策时随时作为信息呈现。
Following are some of the features of a Database management system (DBMS): - Database Customization.
以下是数据库管理系统(DBMS)的一些特性:- 数据库定制。
- Easiness in Data Management.
- Data Availability.
- Minimized Redundancy.
- Data Accuracy, Consistency and Relevance.
- File Consistency.
- Improved Data Security.
Data Structuring.
Some DBMS examples are MySQL, PostgreSQL, FileMaker, Oracle, Microsoft Access.一些DBMS示例包括MySQL、PostgreSQL、FileMaker、Oracle、Microsoft Access。
146. What is the procedure for creating a MySQL database with PHP?
使用 PHP 创建 MySQL 数据库的步骤是什么?
- 知识点: 数据库 / 编程语言基础 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb13ea | 官方: 否 | 付费: 否
答案:
A database is a collection of interconnected data that allows for efficient data retrieval, insertion, and deletion from a database and organises the data into tables, views, schemas, and reports. For example, a university database organises data about students, faculty, and administrative staff, among other things, allowing for easy data retrieval, insertion, and deletion.
数据库是相互关联数据的集合,它允许高效地从数据库中检索、插入和删除数据,并将数据组织成表、视图、模式和报表。例如,大学数据库组织有关学生、教职员工和行政人员等的数据,从而便于轻松地检索、插入和删除数据。
The following are the fundamental procedures for creating a MySQL database with PHP: - Connect to the MySQL server from your PHP script.
以下是使用 PHP 创建 MySQL 数据库的基本步骤:- 从你的 PHP 脚本连接到 MySQL 服务器。
- If the connection is successful, construct a database using SQL and save it in a string variable.
- Then, one by one, the constructed queries will be run.
147. What are the benefits of a database management system (DBMS)? Mention the many DBMS languages available.
数据库管理系统(DBMS)有哪些好处?提及可用的多种 DBMS 语言。
- 知识点: 数据库 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb140b | 官方: 否 | 付费: 否
答案:
Database Management System (DBMS) is a collection of apps or tools that allow users to construct and manage databases. A database management system (DBMS) provides a tool or interface for executing various database activities such as inserting, removing, updating, and so on. It is software that allows data to be stored more compactly and securely than a file-based system. A database management system (DBMS) assists a user in overcoming issues such as data inconsistency, data redundancy, and other issues in a database, making it more comfortable and organised to use. The following are some of the benefits of using a database management system: - Data sharing: Data from the same database can be accessed by multiple people at the same time.
数据库管理系统(DBMS)是允许用户构建和管理数据库的应用程序或工具的集合。数据库管理系统(DBMS)提供用于执行各种数据库活动(如插入、删除、更新等)的工具或接口。它是一种软件,允许比基于文件的系统更紧凑、更安全地存储数据。数据库管理系统(DBMS)帮助用户克服数据库中的数据不一致、数据冗余等问题,使其使用起来更舒适、更有条理。以下是使用数据库管理系统的一些好处:- 数据共享:同一数据库中的数据可同时被多人访问。
- Integrity limitations: These limitations allow for more refined data storage in a database.
- Data redundancy control: Supports a system for controlling data redundancy by combining all data into a single database.
- Data Independence: This allows the structure of the data to be changed without affecting the structure of any running application.
Backup and recovery feature: Provides a 'backup and recovery capability that automatically creates a data backup and restores the data as needed.
The following are the several languages found in DBMS: - DDL (Data Definition Language) is a set of commands used to define a database.以下是 DBMS 中发现的几种语言:- DDL(数据定义语言)是用于定义数据库的一组命令。
- DML (Data Manipulation Language) is a set of commands that can be used to manipulate data in a database.
- DCL (Data Control Language) - Consists of commands that deal with database system user permissions and controls.
- TCL (Transaction Control Language) is a set of instructions that deal with database transactions.
148. What are the ACID attributes of a database management system (DBMS)?
数据库管理系统(DBMS)的 ACID 属性是什么?
- 知识点: 数据库 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb140e | 官方: 否 | 付费: 否
答案:
Any type of information can be stored in a database using a database management system. ACID (atomicity, consistency, isolation, and durability) properties must be supported by the database management system. It is used to verify that data transactions in a database system are processed reliably. - Atomicity: Atomicity refers to transactions that are either totally successful or completely unsuccessful. Each transaction here refers to a single logical data operation. As a result, even if one element of a transaction fails, the transaction as a whole fails, leaving the database state unaffected.
使用数据库管理系统可以将任何类型的信息存储在数据库中。数据库管理系统必须支持 ACID(原子性、一致性、隔离性和持久性)属性。它用于验证数据库系统中的数据事务是否被可靠地处理。- 原子性:原子性指事务要么完全成功,要么完全失败。这里的每个事务指单个逻辑数据操作。因此,即使事务的某个元素失败,整个事务也会失败,数据库状态不受影响。
- Consistency: Consistency ensures that the data adheres to all of the validation standards. In basic terms, your transaction never leaves the database before it has completed its state. The purpose is to verify that the database is consistent before and after the transaction. A transaction is aborted and an error is raised if it leaves data in an incorrect state.
- Isolation: Concurrency control is the primary purpose of isolation. This feature ensures that each transaction is isolated, ensuring that it will not be affected by any other concurrent transactions. It means that until a transaction is completed, it will not be interrupted by another transaction.
Durability: Once a transaction is completed and committed, its modifications are saved in the database indefinitely. This attribute assures that the data saved in the database is immutable until it is affected by another update or deletion transaction.
Even if a significant problem occurs, such as a crash or a power outage, once the transaction is committed, it will remain in this condition. The completed transactions are recorded on non-volatile memory devices such as hard drives, for this reason, ensuring that the data is always available, even if the DB instance is restarted.即使发生重大问题,如崩溃或断电,一旦事务提交,它将保持此状态。已完成的事务记录在硬盘等非易失性存储设备上,因此确保数据始终可用,即使 DB 实例重新启动。
The ACID qualities protect the database's data integrity and consistency, ensuring that data does not become corrupt as a result of a failure. Only transactions that were successful will be handled in databases that use the ACID features, and if a failure occurs before a transaction is completed, the data will not be modified.
ACID 特性保护数据库的数据完整性和一致性,确保数据不会因故障而损坏。在使用 ACID 特性的数据库中,只有成功的事务才会被处理,如果事务完成前发生故障,数据将不会被修改。
149. What are the various levels of abstraction in a database management system?
数据库管理系统中有哪些不同的抽象级别?
- 知识点: 数据库 (标签: interviewbit, justdial, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Justdial
- id: 69b37b8158d557c902bb1427 | 官方: 否 | 付费: 否
答案:
The technique of hiding unnecessary elements from the user is known as data abstraction. To achieve Data Independence, there are three degrees of data abstraction, which we divide into three levels. Users and data should not interact directly with each other, according to data independence. The user should be on a different level than the data, and the data should also be on a distinct level. Data Independence can be obtained in this way. In DBMS, there are three degrees of data abstraction. They are as follows: - Physical level: The physical level of abstraction specifies how data is kept and is the lowest degree of abstraction. The physical level of a database management system (DBMS) specifies how data is really stored and describes data structures in-depth as well as database access techniques. The database developer will pick how to store the data in the database. It is quite difficult to comprehend.
对用户隐藏不必要元素的技术称为数据抽象。为了实现数据独立性,有三个数据抽象程度,我们将其分为三个级别。根据数据独立性,用户和数据不应直接相互交互。用户应处于与数据不同的级别,数据也应处于不同的级别。这样可以获得数据独立性。在 DBMS 中,有三个数据抽象程度。它们如下:- 物理层:抽象的物理层指定数据如何保存,是最低程度的抽象。数据库管理系统(DBMS)的物理层指定数据实际如何存储,并深入描述数据结构以及数据库访问技术。数据库开发者将选择如何在数据库中存储数据。这相当难以理解。
- Logical level: After the Physical level, there is the Logical level of abstraction. This layer decides what data is saved in the database and how the data pieces relate to one another. Let's look at an example where we're storing data using the relational model. The student table will comprise columns such as student name, age, mail id, roll no, and so on to hold the data of a student. All of them must be defined at this level while developing the database. Though the data is kept in the database, the tables' structures, such as the student table, teacher table, books table, and so on, are specified at the conceptual or logical level. The relationship between the tables is also defined here. Overall, we might say that we are developing a conceptual model of the data.
- View Level: The greatest level of abstraction, the View Level describes only a portion of the entire database. When you get to the third level, which is the highest level, you'll see that it's called the view level. This is the level that is visible from the outside. In the view level, there are various levels of views, each of which attempts to describe only a portion of the complete data. Because it provides different views of the same database, it simplifies user interaction. It also allows you to have several views of the same database. As a student, we can examine our grades, attendance, price structure, and other information if we have a login-id and password in a university system. The university professors, on the other hand, will hold a different viewpoint. He will have options such as salary, editing a student's grades, entering student attendance, and so on. As a result, both the student and the instructor have opposing viewpoints. As a result, the system's security is enhanced. In this case, the student is unable to alter his grades, but the faculty member who is permitted to do so can do so. As a result, depending on their level of authorisation, different users will see things differently.
150. What do you understand by query optimisation in the context of SQL?
在 SQL 的上下文中,你对查询优化有何理解?
- 知识点: 数据库 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8b58d557c902bb1ce7 | 官方: 否 | 付费: 否
答案:
A single query can be run using various methods or rewritten in various formats and structures. As a result, the topic of query optimization arises: which of these forms or paths is the most efficient? The query optimizer considers all alternative query plans to discover the most efficient way to execute a query.
一个查询可以使用多种方法运行,或以各种格式和结构重写。因此,查询优化的问题就出现了:这些形式或路径中哪一种最有效?查询优化器会考虑所有备选查询计划,以找出执行查询的最高效方式。
The purpose of query optimization is to reduce the number of system resources necessary to complete a query, allowing the user to receive the proper result set more quickly. - It gives the user faster results, making the application appear to be speedier.
查询优化的目的是减少完成查询所需的系统资源数量,使用户能够更快地收到正确的结果集。- 它为用户提供更快的结果,使应用程序看起来更迅速。
- Second, because each request takes less time than unoptimized queries, the system can handle more queries in the same amount of time.
Finally, query optimization decreases the amount of wear on the server's hardware (for example, disk drives) and allows it to run more efficiently (e.g. lower power consumption, less memory usage).
A query can be optimised in one of two ways: - Analyze and alter relational phrases that are equivalent: Reduce the number of tuples and columns in the intermediate and final query processes (discussed here).查询可以通过以下两种方式之一进行优化:- 分析并改写等价的关系表达式:减少中间查询过程和最终查询过程中的元组和列的数量(此处讨论)。
- For each operation, multiple algorithms can be used: These underlying techniques influence the frequency of disk and block accesses by determining how tuples are accessed from the data structures they are stored in, indexing, hashing, and data retrieval.
151. What do you understand about Data Independence in the context of DataBase Management Systems (DBMS)?
在数据库管理系统(DBMS)的背景下,你对数据独立性有何理解?
- 知识点: 数据库 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8b58d557c902bb1cf4 | 官方: 否 | 付费: 否
答案:
In Database Management Systems (DBMS), data independence implies that the application is independent of the storage structure and data access mechanism. It allows you to change the schema definition at one level without having to change the schema definition at the next level up.
在数据库管理系统(DBMS)中,数据独立性意味着应用程序独立于存储结构和数据访问机制。它允许你在一个层次上更改模式定义,而无需在上一层次更改模式定义。
Data independence can be divided into two categories: - Physical Data Independence: The data contained in the database is referred to as physical data. It's in a binary format. Physical changes should not have an impact on the logical level. For example, if we wish to edit data within a table, we shouldn't change the table's format.
数据独立性可以分为两类:- 物理数据独立性:数据库中包含的数据称为物理数据。它采用二进制格式。物理更改不应影响逻辑层次。例如,如果我们希望编辑表中的数据,就不应该更改表的格式。
- Logical Data Independence (LDI): The ability to update the conceptual schema without having to change the external schema is referred to as logical data independence. To distinguish the external level from the conceptual view, logical data independence is used. Any modifications to the conceptual representation of the data will not affect the user’s view of the data.
152. What do you understand about ACID properties in the context of Database Management Systems (DBMS)?
在数据库管理系统(DBMS)的背景下,你对 ACID 属性有何理解?
- 知识点: 数据库 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8b58d557c902bb1cf7 | 官方: 否 | 付费: 否
答案:
The ACID properties for a transaction in SQL DBMS refers to the following properties:
SQL DBMS 中事务的 ACID 属性指的是以下属性:
- Atomicity: Atomicity refers to the fact that data remains atomic. It means that if any operation on the data is conducted, it should either be performed or executed completely, or it should not be performed at all. It also implies that the operation should not be interrupted or just half completed. When performing operations on a transaction, the operation should be completed rather than partially.
- Consistency: The term "consistency" denotes that the value should be retained at all times. The integrity of the data should be maintained in DBMS, which means that whenever a modification is made to the database, it should always be preserved. The integrity of the data is critical in transactions so that the database remains consistent before and after the transaction. The information should always be accurate.
- Isolation: The term "isolation" refers to the act of being separated from others. Isolation in DBMS refers to the property of a database where no data from one database should impact the other and where many transactions can take place at the same time. In other words, when the operation on the first database is finished, the process on the second database should begin. It indicates that if two actions are conducted on two different databases, the value of one database may not be affected by the value of the other. When two or more transactions occur at the same time in the case of transactions, consistency should be maintained. Any modifications made in one transaction will not be visible to other transactions until the change is committed to the memory.
- Durability: The term "durability" refers to something's ability to last. The term durability in DBMS refers to the fact that if an operation is completed successfully, the data remains permanent in the database. The database's durability should be such that even if the system fails or crashes, the database will survive. However, if the database is lost, the recovery manager is responsible for guaranteeing the database's long-term viability. Every time we make a change, we must use the COMMIT command to commit the values.
153. What do you understand about checkpoints in the context of Database Management Systems (DBMS)? What are the advantages of using checkpoints?
在数据库管理系统(DBMS)的背景下,你对检查点有何理解?使用检查点有哪些优势?
- 知识点: 数据库 (标签: interviewbit, lti, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: LTIMindtree
- id: 69b37b8b58d557c902bb1cfd | 官方: 否 | 付费: 否
答案:
The checkpoint specifies a time when the DBMS was in a consistent state and all transactions had been committed. These checkpoints are tracked during transaction execution. Transaction log files will be created after the execution. The log file is destroyed when it reaches the savepoint/checkpoint by recording its update to the database. Then a new log is produced with the transaction's upcoming execution actions, which is updated until the next checkpoint, and the process continues.
检查点指定了 DBMS 处于一致状态且所有事务均已提交的时间点。这些检查点在事务执行期间被跟踪。事务日志文件将在执行后创建。当日志文件通过记录其对数据库的更新到达保存点/检查点时,该日志文件被销毁。然后会生成一个新的日志,其中包含事务即将执行的操作,该日志会持续更新直到下一个检查点,此过程不断重复。
When transaction logs are created in a real-time setting, they consume a significant amount of storage space. Keeping track of each update and maintaining it may also take up more physical space on the system. As the transaction log file grows in size, it may eventually become unmanageable. Checkpoints can be used to address this. A Checkpoint is a way for deleting all prior transaction logs and saving them in a permanent storage location.
在实时环境中创建事务日志时,它们会消耗大量存储空间。跟踪每次更新并维护它也可能占用系统上更多的物理空间。随着事务日志文件大小的增长,它最终可能变得难以管理。检查点可用于解决此问题。检查点是一种删除所有先前事务日志并将其保存到永久存储位置的方法。
The following are the advantages of checkpoints: - It makes the data recovery procedure go faster.
以下是检查点的优势:- 它使数据恢复过程进行得更快。
- The majority of DBMS packages perform self-checkpoints.
- To avoid unnecessary redo operations, checkpoint records in the log file are employed.
- It has very low overhead and can be done frequently because dirty pages are flushed away continuously in the background.
154. What do you understand by super key, candidate key, primary key and foreign key in the context of database management systems?
在数据库管理系统的上下文中,你对超键、候选键、主键和外键的理解是什么?
- 知识点: 数据库 (标签: interviewbit, mindtree, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mindtree
- id: 69b37bd358d557c902bb4bf3 | 官方: 否 | 付费: 否
答案:
- Super key: Super Key is a set of attributes that can be used to uniquely identify a tuple. The super key is created by adding zero or more attributes to the candidate key. A candidate key is a super key, but not the other way around.
- Candidate key: A candidate key is the smallest set of attributes that can uniquely identify a tuple. For each tuple, the Candidate Key value is unique and non-null. In relation, there can be more than one candidate key. The candidate key might be simple (only having one attribute) or composite (containing multiple attributes).
- Primary key: In relation, there may be more than one candidate key, with one being chosen as the primary key. This primary key is chosen by the database administrator based on the requirements amongst the candidate keys.
- Foreign key: A foreign key is a column or set of columns in a relational database table that connects data from two other tables. It serves as a cross-reference between tables by referencing the primary key of another table and therefore creating a relationship between them.
For example, let us consider tables with the following schema :
例如,让我们考虑具有以下模式的表:
Teacher :
Teacher:
teacher_id (primary key), teacher_name, teacher_phone_number, teacher_aadhar, teacher_department_id
teacher_id(主键)、teacher_name、teacher_phone_number、teacher_aadhar、teacher_department_id
Department :
Department:
department_id (primary key), department_name
department_id(主键)、department_name
Here, for the Teacher table, the following are the different types of keys present : - The candidate keys can be teacher_id, teacher_phone_number and teacher_aadhar since they all can uniquely identify a record of the table.
这里,对于 Teacher 表,存在以下不同类型的键:- 候选键可以是 teacher_id、teacher_phone_number 和 teacher_aadhar,因为它们都能唯一标识表中的一条记录。
- Out of the above three candidate keys, any one of them can be chosen as the primary key. We generally choose teacher_id as the primary key.
- Any of the above candidate keys when grouped with any other key form the super key. For example, teacher_id, teacher_name can together form a super key.
- Teacher_department_id is a foreign key for the Teacher table since it is a primary key in the Department table and it links the two tables.
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
155. Differentiate between Delete and Truncate SQL commands.
区分 Delete 和 Truncate SQL 命令。
- 知识点: 数据库 (标签: interviewbit, mindtree, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mindtree
- id: 69b37bd358d557c902bb4bfd | 官方: 否 | 付费: 否
答案:
The following table lists the differences between Delete and Truncate SQL commands:
下表列出了 Delete 和 Truncate SQL 命令之间的区别:
| Delete | Truncate |
|---|---|
| The DELETE command is used to remove specific rows from a table (one or more). DELETE 命令用于从表中删除特定行(一行或多行)。 | This command is used to delete all of the rows in a table. 此命令用于删除表中的所有行。 |
| It is a Data Manipulation Language (DML) command. 它是数据操作语言(DML)命令。 | It is a Data Definition Language (DDL) command. 它是数据定义语言(DDL)命令。 |
| In order to filter the records, the DELETE command may include a WHERE clause. 为了筛选记录,DELETE 命令可以包含 WHERE 子句。 | The TRUNCATE command may not use a WHERE clause. TRUNCATE 命令不能使用 WHERE 子句。 |
| The DELETE statement deletes rows one by one and records each deleted row in the transaction log. DELETE 语句逐行删除行,并在事务日志中记录每个删除的行。 | TRUNCATE TABLE deletes data by relocating the data pages that were used to hold the table data, and only the page deallocations are recorded in the transaction log. TRUNCATE TABLE 通过重新定位用于保存表数据的数据页来删除数据,并且仅在事务日志中记录页释放。 |
| A tuple is locked before being deleted with the DELETE statement. 使用 DELETE 语句删除元组之前,会锁定该元组。 | Before removing the table data, the data page is locked in this command. 在此命令中,删除表数据之前会锁定数据页。 |
| DELETE permission on the table is required to use Delete. 使用 Delete 需要对表具有 DELETE 权限。 | To use Truncate on a table, the table must have at least ALTER permission. 要对表使用 Truncate,该表必须至少具有 ALTER 权限。 |
| The DELETE command is more time consuming than the TRUNCATE command. DELETE 命令比 TRUNCATE 命令更耗时。 | The TRUNCATE command, on the other hand, is faster than the DELETE command. 另一方面,TRUNCATE 命令比 DELETE 命令更快。 |
| With indexed views, the delete command can be used. 对于索引视图,可以使用 delete 命令。 | Truncate isn't compatible with indexed views. Truncate 与索引视图不兼容。 |
| After performing the DELETE Statement on the table, the identity of the column is preserved. 对表执行 DELETE 语句后,列的身份标识会保留。 | If the table contains an identity column, the column's identity is reset to its seed value. 如果表包含标识列,则该列的标识会重置为其种子值。 |
156. Write a query in SQL to find the details of an employee having the nth highest salary from a given table Employee. The value of n needs to be taken as user input. Assume that the table Employee has the following schema.
编写一个 SQL 查询,从给定表 Employee 中查找具有第 n 高薪水的员工的详细信息。n 的值需要作为用户输入。假设表 Employee 具有以下模式。
- 知识点: 数据库 (标签: interviewbit, mindtree, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mindtree
- id: 69b37bd358d557c902bb4c09 | 官方: 否 | 付费: 否
答案:
name - denoting the name of the employee salary - denoting the salary of the employee
name - 表示员工的姓名 salary - 表示员工的薪水
Approach:
方法:
We use the dense_rank() function to display the details of the employee having the nth highest salary. The function DENSE_RANK returns the rank of a row in an ordered collection of rows as a NUMBER. The ranks are in ascending order, starting with 1. Based on the values of the value exprs in the order by clause, DENSE RANK computes the rank of each row returned from a query in relation to the other rows as an analytic function.
我们使用 dense_rank() 函数来显示具有第 n 高薪水的员工的详细信息。函数 DENSE_RANK 将一行在有序行集合中的排名返回为 NUMBER。排名按升序排列,从 1 开始。根据 order by 子句中 value exprs 的值,DENSE RANK 作为分析函数计算查询返回的每一行相对于其他行的排名。
Query:
查询:
select name, salary from(
select name, salary from(
select name, salary, dense_rank()
select name, salary, dense_rank()
over(order by salary desc)input from Employee)
over(order by salary desc)input from Employee)
where input = &n;
where input = &n;
Explanation:
说明:
In the above query, we first sort the data according to the descending order of the salary and assign a rank to each of the employees starting from 1. In case of an event where the salary of two employees is the same, they both are assigned the same rank. Then we display the data whose rank is equal to the given input.
在上面的查询中,我们首先根据工资的降序对数据进行排序,并为每位员工从1开始分配一个排名。如果两位员工的工资相同,则他们被分配相同的排名。然后我们显示排名等于给定输入的数据。
157. Differentiate between SQL and NoSQL databases.
区分 SQL 和 NoSQL 数据库。
- 知识点: 数据库 (标签: interviewbit, mindtree, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mindtree
- id: 69b37bd358d557c902bb4c15 | 官方: 否 | 付费: 否
答案:
Following are the differences between SQL and NoSQL databases:
以下是 SQL 和 NoSQL 数据库之间的区别:
| SQL Database SQL 数据库 | NoSQL Database NoSQL 数据库 |
|---|---|
| SQL databases are referred to as Relational Database Management Systems (RDBMS). SQL 数据库被称为关系数据库管理系统(RDBMS)。 | NoSQL databases are referred to as non-relational or distributed databases. NoSQL 数据库被称为非关系型或分布式数据库。 |
| SQL databases have fixed and static predefined schema. SQL 数据库具有固定且静态的预定义模式。 | NoSQL databases can have dynamic schema. NoSQL 数据库可以具有动态模式。 |
| SQL databases are vertically scalable in almost all cases. This means that by boosting RAM, CPU, or SSD, you may increase the demand on a single server. 在几乎所有情况下,SQL 数据库都是垂直可扩展的。这意味着通过提升 RAM、CPU 或 SSD,你可以增加单个服务器的需求。 | NoSQL databases, on the other hand, are horizontally scalable. By sharding, or adding multiple servers to your NoSQL database, you can handle greater traffic. It's the difference between adding more storeys to a single building and adding more buildings to a neighbourhood. NoSQL databases can grow in size and power, making them the best solution for huge or constantly changing data sets. 另一方面,NoSQL 数据库是水平可扩展的。通过分片或向你的 NoSQL 数据库添加多个服务器,你可以处理更大的流量。这就像在单个建筑上增加更多楼层与在社区中添加更多建筑之间的区别。NoSQL 数据库可以在规模和能力上增长,使其成为庞大或不断变化的数据集的最佳解决方案。 |
| SQL databases are table-based. As a result, relational SQL databases are a preferable choice for applications that require multi-row transactions, such as accounting systems, or for legacy systems that were designed with a relational structure in mind. SQL 数据库是基于表的。因此,对于需要多行事务的应用程序(如会计系统)或按照关系结构设计的遗留系统,关系型 SQL 数据库是更可取的选择。 | Key-value pairs, document-based, graph databases, and wide-column stores are all types of NoSQL databases. 键值对、基于文档、图数据库和宽列存储都是 NoSQL 数据库的类型。 |
| The ACID characteristics (Atomicity, Consistency, Isolation, and Durability) are followed by SQL databases. SQL 数据库遵循 ACID 特性(原子性、一致性、隔离性和持久性)。 | The Brewers CAP theorem is followed by NoSQL databases (Consistency, Availability and Partition tolerance). NoSQL 数据库遵循 Brewer 的 CAP 定理(一致性、可用性和分区容错性)。 |
158. What are some of the advantages of MongoDB?
MongoDB有哪些优势?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4cd9 | 官方: 否 | 付费: 否
答案:
Some advantages of MongoDB are as follows: - MongoDB supports field, range-based, string pattern matching type queries. for searching the data in the database
MongoDB的一些优势如下:- MongoDB支持字段、基于范围、字符串模式匹配类型的查询,用于在数据库中搜索数据。
- MongoDB support primary and secondary index on any fields
- MongoDB basically uses JavaScript objects in place of procedures
- MongoDB uses a dynamic database schema
- MongoDB is very easy to scale up or down
- MongoDB has inbuilt support for data partitioning (Sharding).
159. When to use MongoDB?
何时使用MongoDB?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4cdc | 官方: 否 | 付费: 否
答案:
You should use MongoDB when you are building internet and business applications that need to evolve quickly and scale elegantly. MongoDB is popular with developers of all kinds who are building scalable applications using agile methodologies. MongoDB is a great choice if one needs to: - Support a rapid iterative development.
当你正在构建需要快速演进和优雅扩展的互联网及业务应用程序时,应使用MongoDB。MongoDB受到各种使用敏捷方法论构建可扩展应用程序的开发者的青睐。如果需要满足以下条件,MongoDB是一个很好的选择:- 支持快速的迭代开发。
- Scale to high levels of read and write traffic - MongoDB supports horizontal scaling through Sharding, distributing data across several machines, and facilitating high throughput operations with large sets of data.
- Scale your data repository to a massive size.
- Evolve the type of deployment as the business changes.
- Store, manage and search data with text, geospatial, or time-series dimensions.
160. What are the data types in MongoDB?
MongoDB中有哪些数据类型?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4cdf | 官方: 否 | 付费: 否
答案:
MongoDB supports a wide range of data types as values in documents. Documents in MongoDB are similar to objects in JavaScript. Along with JSON’s essential key/value–pair nature, MongoDB adds support for a number of additional data types. The common data types in MongoDB are: - Null{"x" : null}
MongoDB支持广泛的数据类型作为文档中的值。MongoDB中的文档类似于JavaScript中的对象。除了JSON基本的键/值对特性外,MongoDB还增加了对许多额外数据类型的支持。MongoDB中常见的数据类型有:- Null{"x" : null}
- Boolean{"x" : true}
- Number{"x" : 4}
- String{"x" : "foobar"}
- Date{"x" : new Date()}
- Regular expression{"x" : /foobar/i}
- Array{"x" : ["a", "b", "c"]}
- Embedded document{"x" : {"foo" : "bar"}}
- Object ID{"x" : ObjectId()}
- Binary DataBinary data is a string of arbitrary bytes.
- Code{"x" : function() { / ... / }}
161. How to perform queries in MongoDB?
如何在MongoDB中执行查询?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4ce2 | 官方: 否 | 付费: 否
答案:
The find method is used to perform queries in MongoDB. Querying returns a subset of documents in a collection, from no documents at all to the entire collection. Which documents get returned is determined by the first argument to find , which is a document specifying the query criteria.
find方法用于在MongoDB中执行查询。查询返回集合中的文档子集,范围可以从没有文档到整个集合。返回哪些文档由find的第一个参数决定,该参数是一个指定查询条件的文档。
Example: > db.users.find({"age" : 24})
示例:> db.users.find({"age" : 24})
162. How do you Delete a Document?
如何删除文档?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4ce5 | 官方: 否 | 付费: 否
答案:
The CRUD API in MongoDB provides deleteOne and deleteMany for this purpose. Both of these methods take a filter document as their first parameter. The filter specifies a set of criteria to match against in removing documents. For example: > db.books.deleteOne({"_id" : 3})
MongoDB中的CRUD API为此提供了deleteOne和deleteMany。这两个方法都将筛选文档作为它们的第一个参数。筛选指定了一组条件,用于匹配要删除的文档。例如:> db.books.deleteOne({"_id" : 3})
- Data Science
- All Events
- My Events
163. How do you Update a Document?
如何更新文档?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4ce8 | 官方: 否 | 付费: 否
答案:
Once a document is stored in the database, it can be changed using one of several update methods: updateOne , updateMany , and replaceOne. updateOne and updateMany each takes a filter document as their first parameter and a modifier document, which describes changes to make, as the second parameter. replaceOne also takes a filter as the first parameter, but as the second parameter replaceOne expects a document with which it will replace the document matching the filter.
一旦文档存储在数据库中,可以使用几种更新方法之一进行更改:updateOne、updateMany和replaceOne。updateOne和updateMany都将筛选文档作为第一个参数,并将描述更改的修改器文档作为第二个参数。replaceOne也将筛选作为第一个参数,但作为第二个参数,replaceOne期望一个文档,它将用该文档替换匹配筛选的文档。
For example, in order to replace a document:
例如,要替换一份文档:
{
"_id" : ObjectId("4b2b9f67a1f631733d917a7a"),
"_id" : ObjectId("4b2b9f67a1f631733d917a7a"),
"name" : "alice",
"name" : "alice",
"friends" : 24,
"friends" : 24,
"enemies" : 2
"enemies" : 2
}
164. How to add data in MongoDB?
如何在MongoDB中添加数据?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4ceb | 官方: 否 | 付费: 否
答案:
The basic method for adding data to MongoDB is “inserts”. To insert a single document, use the collection’s insertOne method:
向MongoDB添加数据的基本方法是“插入”。若要插入单个文档,请使用集合的insertOne方法:
db.books.insertOne({"title" : "Start With Why"})
For inserting multiple documents into a collection, we use insertMany . This method enables passing an array of documents to the database.
若要向集合中插入多个文档,我们使用insertMany。此方法允许向数据库传递一个文档数组。
165. What are some features of MongoDB?
MongoDB有哪些特性?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4cee | 官方: 否 | 付费: 否
答案:
- Indexing: It supports generic secondary indexes and provides unique, compound, geospatial, and full-text indexing capabilities as well.
- Aggregation: It provides an aggregation framework based on the concept of data processing pipelines.
- Special collection and index types: It supports time-to-live (TTL) collections for data that should expire at a certain time
- File storage: It supports an easy-to-use protocol for storing large files and file metadata.
- Sharding: Sharding is the process of splitting data up across machines.
166. How does Scale-Out occur in MongoDB?
MongoDB中的Scale-Out是如何发生的?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: system-design
- 分类: fullstack
- id: 69b37bd458d557c902bb4cf1 | 官方: 否 | 付费: 否
答案:
The document-oriented data model of MongoDB makes it easier to split data across multiple servers. Balancing and loading data across a cluster is done by MongoDB. It then redistributes documents automatically. The mongos acts as a query router, providing an interface between client applications and the sharded cluster. Config servers store metadata and configuration settings for the cluster. MongoDB uses the config servers to manage distributed locks. Each sharded cluster must have its own config servers.
MongoDB的面向文档数据模型使数据更易于在多个服务器间拆分。集群间的数据平衡和加载由MongoDB完成,它会自动重新分配文档。mongos充当查询路由器,提供客户端应用与分片集群之间的接口。配置服务器存储集群的元数据和配置设置。MongoDB使用配置服务器来管理分布式锁。每个分片集群必须拥有自己的配置服务器。
167. What is the Mongo Shell?
什么是Mongo Shell?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4cf4 | 官方: 否 | 付费: 否
答案:
It is a JavaScript shell that allows interaction with a MongoDB instance from the command line. With that one can perform administrative functions, inspecting an instance, or exploring MongoDB.
它是一个JavaScript shell,允许从命令行与MongoDB实例进行交互。使用它,可以执行管理功能、检查实例或探索MongoDB。
To start the shell, run the mongo executable:
要启动shell,请运行mongo可执行文件:
$ mongod
$ mongo
MongoDB shell version: 4.2.0
MongoDB shell版本:4.2.0
connecting to: test
正在连接到:testThe shell is a full-featured JavaScript interpreter, capable of running arbitrary JavaScript programs. Let’s see how basic math works on this:
shell 是一个功能完备的 JavaScript 解释器,能够运行任意 JavaScript 程序。让我们看看基本数学运算在此是如何工作的:x = 100;
200
x / 5;
20
168. What are Databases in MongoDB?
什么是 MongoDB 中的数据库?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4cf7 | 官方: 否 | 付费: 否
答案:
MongoDB groups collections into databases. MongoDB can host several databases, each grouping together collections. Some reserved database names are as follows: admin local config
MongoDB 将集合分组到数据库中。MongoDB 可以托管多个数据库,每个数据库将集合分组在一起。一些保留的数据库名称如下:admin local config
169. What is a Collection in MongoDB?
什么是 MongoDB 中的集合?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4cfa | 官方: 否 | 付费: 否
答案:
A collection in MongoDB is a group of documents. If a document is the MongoDB analog of a row in a relational database, then a collection can be thought of as the analog to a table. Documents within a single collection can have any number of different “shapes.”, i.e. collections have dynamic schemas. For example, both of the following documents could be stored in a single collection:
MongoDB 中的集合是一组文档。如果文档是关系数据库中行的 MongoDB 类比,那么集合可以被视为表的类比。单个集合中的文档可以具有任意数量的不同“形状”,即集合具有动态模式。例如,以下两个文档都可以存储在一个集合中:
{"greeting" : "Hello world!", "views": 3}
{"greeting" : "Hello world!", "views": 3}
{"signoff": "Good bye"}
{"signoff": "Good bye"}
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
170. What is a Document in MongoDB?
什么是 MongoDB 中的文档?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4cfd | 官方: 否 | 付费: 否
答案:
A Document in MongoDB is an ordered set of keys with associated values. It is represented by a map, hash, or dictionary. In JavaScript, documents are represented as objects: {"greeting" : "Hello world!"}
MongoDB 中的文档是带有关联值的有序键集合。它由映射、哈希或字典表示。在 JavaScript 中,文档表示为对象:{"greeting" : "Hello world!"}
Complex documents will contain multiple key/value pairs: {"greeting" : "Hello world!", "views" : 3}
复杂文档将包含多个键/值对:{"greeting" : "Hello world!", "views" : 3}
171. What do the words Entity, Entity Type, and Entity Set mean in DBMS?
在 DBMS 中,Entity、Entity Type 和 Entity Set 这些词是什么意思?
- 知识点: 数据库 (标签: interviewbit, mphasis, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mphasis
- id: 69b37bd658d557c902bb4dbb | 官方: 否 | 付费: 否
答案:
- Entity: An entity is a real-world entity with attributes, which are nothing more than the object's qualities. An employee, for example, is a type of entity. This entity can have characteristics like empid (employee id), empname (employee name), and so on.
- Entity Type: An entity type is a group of objects with similar attributes. An entity type, in general, corresponds to one or maybe more related tables in a database. As a result, entity type can be thought of as a trait that uniquely identifies an entity. Employees can have properties like empid, empname, department, and so on.
- Entity Set: In a database, an entity set is a group of all the objects of a specific entity type. An entity set can include a group of employees, a group of companies, as well as a group of persons, for example.
172. What do you know about Top-N Analysis in SQL?
你对 SQL 中的 Top-N 分析了解多少?
- 知识点: 数据库 (标签: interviewbit, mphasis, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mphasis
- id: 69b37bd658d557c902bb4dce | 官方: 否 | 付费: 否
答案:
In SQL, Top-N Analysis is used to limit the number of rows returned from ordered collections of data. Top-N queries look for a column's n least or greatest values. Top-N inquiries include both the lowest and largest value sets. Following this method of searching could save you a great deal of effort. Top-N analyses are beneficial when only the n bottom-most or n top-most records from a table must be displayed based on criteria. This set of results could be used for subsequent analysis.
在 SQL 中,Top-N 分析用于限制从有序数据集合返回的行数。Top-N 查询查找某一列的最小或最大的 n 个值。Top-N 查询包括最小和最大的值集。遵循这种搜索方法可以为你节省大量精力。当需要根据条件仅显示表中最低的 n 条或最高的 n 条记录时,Top-N 分析非常有用。这组结果可用于后续分析。
We can, for example, use Top-N analysis to run the following queries: - The top two products with the most sales in the previous two months.
例如,我们可以使用 Top-N 分析来运行以下查询: - 前两个月销售额最高的两个产品。
The top two agents by the number of policies sold.
Performing Top-N Analysis: We can readily grasp the workings of Top-N analysis in SQL by running the following queries:执行 Top-N 分析:通过运行以下查询,我们可以轻松掌握 SQL 中 Top-N 分析的工作原理:
Syntax:
语法:
SELECT [column_list], ROWNUM
SELECT [column_list], ROWNUM
FROM (SELECT [column_list]
FROM (SELECT [column_list]
FROM table_name
FROM table_name
ORDER BY Top-N_clolumn)
ORDER BY Top-N_clolumn)
WHERE ROWNUM<=N;
WHERE ROWNUM<=N;
173. What are some of the most popular SQL clauses used with SELECT queries?
与 SELECT 查询一起使用的一些最流行的 SQL 子句有哪些?
- 知识点: 数据库 (标签: interviewbit, mphasis, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Mphasis
- id: 69b37bd658d557c902bb4de5 | 官方: 否 | 付费: 否
答案:
The following are some examples of SQL clauses that are commonly used in conjunction with a SELECT query: - In SQL, the WHERE clause is used to filter records based on certain requirements.
以下是一些常与 SELECT 查询结合使用的 SQL 子句示例:- 在 SQL 中,WHERE 子句用于根据特定条件筛选记录。
- The ORDER BY clause in SQL is used to sort entries in ascending (ASC) or descending (DESC) order based on specified field(s).
- The SQL GROUP BY clause is used to aggregate records with similar data and can be combined with some aggregation methods to provide summarised database results.
In SQL, the HAVING clause is used in conjunction with the GROUP BY clause to filter records. It differs from the WHERE clause in that aggregated records cannot be filtered using the WHERE clause.
Mphasis Interview Preparation
174. What are the String Data Types in MySQL?
MySQL 中有哪些字符串数据类型?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fca | 官方: 否 | 付费: 否
答案:
| Type Name 类型名称 | Meaning 含义 |
|---|---|
| CHAR | fixed-length nonbinary(character) string 固定长度非二进制(字符)字符串 |
| VARCHAR | variable-length nonbinary string 可变长度非二进制字符串 |
| BINARY | fixed-length binary string 固定长度二进制字符串 |
| VARBINARY | variable-length binary string 可变长度二进制字符串 |
| TINYBLOB | Very small BLOB(binary large object) 非常小的 BLOB(二进制大对象) |
| BLOB | Small BLOB 小型 BLOB |
| MEDIUMBLOB | Medium-sized BLOB 中型 BLOB |
| LONGBLOB | Large BLOB 大型 BLOB |
| TINYTEXT | A very small nonbinary string 非常小的非二进制字符串 |
| TEXT | Small nonbinary string 小型非二进制字符串 |
| MEDIUMTEXT | Medium-sized nonbinary string 中型非二进制字符串 |
| LONGTEXT | Large nonbinary string 大型非二进制字符串 |
| ENUM | An enumeration; each column value is assigned, one enumeration member 枚举;每个列值被分配一个枚举成员 |
| SET | A set; each column value is assigned zero or more set members 集合;每个列值被分配零个或多个集合成员 |
| NULL | NULL in SQL is the term used to represent a missing value. A NULL value in a table is a value in a field that appears to be blank. This value is different than a zero value or a field that contains spaces. SQL 中的 NULL 是用于表示缺失值的术语。表中的 NULL 值是指字段中看似空白的值。该值不同于零值或包含空格的字段。 |
175. How to add users in MySQL?
如何在 MySQL 中添加用户?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fcd | 官方: 否 | 付费: 否
答案:
You can add a User by using the CREATE command and specifying the necessary credentials. For example:
您可以使用 CREATE 命令并指定必要的凭据来添加用户。例如:
CREATE USER ‘testuser’ IDENTIFIED BY ‘sample password’;
CREATE USER ‘testuser’ IDENTIFIED BY ‘sample password’;
176. What is BLOB in MySQL?
什么是 MySQL 中的 BLOB?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fd0 | 官方: 否 | 付费: 否
答案:
BLOB is an acronym that stands for a binary large object. It is used to hold a variable amount of data. There are four types of BLOB: - TINYBLOB
BLOB是“二进制大对象”(binary large object)的首字母缩写,用于保存可变数量的数据。BLOB有四种类型:- TINYBLOB
- BLOB
- MEDIUMBLOB
LONGBLOB
A BLOB can hold a very large amount of data. For example - documents, images, and even videos. You could store your complete novel as a file in a BLOB if needed.BLOB可以保存非常大量的数据,例如文档、图像甚至视频。如果需要,你可以将整本小说作为文件存储在BLOB中。
177. What are the Temporal Data Types in MySQL?
MySQL中的时间数据类型有哪些?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fd3 | 官方: 否 | 付费: 否
答案:
| Type Name 类型名称 | Meaning 含义 |
|---|---|
| DATE | A date value, in ' CCYY-MM-DD ' Format 日期值,格式为' CCYY-MM-DD ' |
| TIME | A Time value, in ' hh : mm :ss ' format 时间值,格式为' hh : mm :ss ' |
| DATETIME | Date and time value, in ' CCYY-MM-DD hh : mm :ss ' format 日期和时间值,格式为' CCYY-MM-DD hh : mm :ss ' |
| TIMESTAMP | A timestamp value, in ' CCYY-MM-DD hh : mm :ss ' format 时间戳值,格式为' CCYY-MM-DD hh : mm :ss ' |
| YEAR | A year value, in CCYY or YY format 年份值,格式为CCYY或YY |
Example: To select the records with an Order Date of "2018-11-11" from a table:
示例:从表中选择订单日期为“2018-11-11”的记录:
SELECT * FROM Orders WHERE OrderDate='2018-11-11'
SELECT * FROM Orders WHERE OrderDate='2018-11-11'
178. What is MySQL?
什么是MySQL?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fd6 | 官方: 否 | 付费: 否
答案:
MySQL is a database management system for web servers. It can grow with the website as it is highly scalable. Most of the websites today are powered by MySQL.
MySQL是用于Web服务器的数据库管理系统。它高度可扩展,可以随网站一起增长。如今大多数网站都由MySQL驱动。
179. What are the Numeric Data Types in MySQL?
MySQL中的数值数据类型有哪些?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fd9 | 官方: 否 | 付费: 否
答案:
MySQL has numeric data types for integer, fixed-point, floating-point, and bit values, as shown in the table below. Numeric types can be signed or unsigned, except BIT. A special attribute enables the automatic generation of sequential integer or floating-point column values, which is useful for applications that require a series of unique identification numbers.
MySQL具有用于整数、定点数、浮点数和位值的数值数据类型,如下表所示。数值类型可以有符号或无符号,但BIT除外。一个特殊属性允许自动生成连续的整数或浮点数列值,这对于需要一系列唯一标识号的应用非常有用。
| Type Name 类型名称 | Meaning 含义 |
|---|---|
| TINYINT | Very Small Integer 很小的整数 |
| SMALLINT | Small Integer 小整数 |
| MEDIUMINT | Medium-sized Integer 中等大小的整数 |
| INT | Standard Integer 标准整数 |
| BIGINT | Large Integer 大整数 |
| DECIMAL | Fixed-point number 定点数 |
| FLOAT | Single-precision floating-point number 单精度浮点数 |
| DOUBLE | Double-precision floating-point number 双精度浮点数 |
| BIT | Bit-field 位字段 |
180. How do you view a database in MySQL?
如何查看MySQL中的数据库?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fdc | 官方: 否 | 付费: 否
答案:
One can view all the databases on the MySQL server host using the following command:
可以使用以下命令查看MySQL服务器主机上的所有数据库:
mysql> SHOW DATABASES;
mysql> SHOW DATABASES;
181. How to Delete Data From a MySQL Table?
如何从MySQL表中删除数据?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fdf | 官方: 否 | 付费: 否
答案:
In MySQL, the DELETE statement is used to delete records from a table:
在MySQL中,DELETE语句用于从表中删除记录:
DELETE FROM table_name
DELETE FROM table_name
WHERE column_name = value_name
WHERE column_name = value_name
182. How to create an Index in MySQL?
如何在MySQL中创建索引?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fe2 | 官方: 否 | 付费: 否
答案:
In MySQL, there are different index types, such as a regular INDEX, a PRIMARY KEY, or a FULLTEXT index. You can achieve fast searches with the help of an index. Indexes speed up performance by either ordering the data on disk so it's quicker to find your result or, telling the SQL engine where to go to find your data.
在MySQL中,有不同类型的索引,例如常规INDEX、PRIMARY KEY或FULLTEXT索引。借助索引可以实现快速搜索。索引通过排序磁盘上的数据以更快找到结果,或告知SQL引擎去哪里查找数据,从而提升性能。
Example: Adding indexes to the history table:
示例:向历史表添加索引:
ALTER TABLE history ADD INDEX(author(10));
ALTER TABLE history ADD INDEX(author(10));
ALTER TABLE history ADD INDEX(title(10));
ALTER TABLE history ADD INDEX(title(10));
ALTER TABLE history ADD INDEX(category(5));
ALTER TABLE history ADD INDEX(category(5));
ALTER TABLE history ADD INDEX(year);
ALTER TABLE history ADD INDEX(year);
DESCRIBE history;
DESCRIBE history;
183. How do you remove a column from a database?
如何从数据库中删除列?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fe5 | 官方: 否 | 付费: 否
答案:
You can remove a column by using the DROP keyword:
您可以使用DROP关键字删除列:
ALTER TABLE classics DROP pages;
ALTER TABLE classics DROP pages;
184. How do you Insert Data Into MySQL?
如何向MySQL插入数据?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fe8 | 官方: 否 | 付费: 否
答案:
The INSERT INTO statement is used to add new records to a MySQL table:
INSERT INTO语句用于向MySQL表添加新记录:
INSERT INTO table_name (column1, column2, column3,...)
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
VALUES (value1, value2, value3,...)
If we want to add values for all the columns of the table, we do not need to specify the column names in the SQL query. However, the order of the values should be in the same order as the columns in the table. The INSERT INTO syntax would be as follows:
如果我们要为表的所有列添加值,则无需在SQL查询中指定列名。但是,值的顺序应与表中的列顺序一致。INSERT INTO语法如下:
INSERT INTO table_name
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
VALUES (value1, value2, value3, ...);
185. How do you create a table using MySQL?
如何使用MySQL创建表?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4feb | 官方: 否 | 付费: 否
答案:
Use the following to create a table using MySQL:
使用以下方法通过MySQL创建表:
CREATE TABLE history (
CREATE TABLE history (
author VARCHAR(128),
author VARCHAR(128),
title VARCHAR(128),
title VARCHAR(128),
type VARCHAR(16),
type VARCHAR(16),
year CHAR(4)) ENGINE InnoDB;
year CHAR(4)) ENGINE InnoDB;
186. How do you create a database in MySQL?
如何在MySQL中创建数据库?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4fee | 官方: 否 | 付费: 否
答案:
Use the following command to create a new database called ‘books’:
使用以下命令创建一个名为“books”的新数据库:
CREATE DATABASE books;
CREATE DATABASE books;
187. What are some of the common MySQL commands?
一些常见的MySQL命令有哪些?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4ff1 | 官方: 否 | 付费: 否
答案:
| Command 命令 | Action 作用 |
|---|---|
| ALTER | To alter a database or table 修改数据库或表 |
| BACKUP | To back-up a table 备份表 |
| \c | To cancel Input 取消输入 |
| CREATE | To create a database 创建数据库 |
| DELETE | To delete a row from a table 从表中删除行 |
| DESCRIBE | To describe a table's columns 描述表的列 |
| DROP | To delete a database or table 删除数据库或表 |
| EXIT(ctrl+c) | To exit 退出 |
| GRANT | To change user privileges 修改用户权限 |
| HELP (\h, ?) | Display help 显示帮助 |
| INSERT | Insert data 插入数据 |
| LOCK | Lock table(s) 锁定表 |
| QUIT(\q) | Same as EXIT 同EXIT |
| RENAME | Rename a Table 重命名表 |
| SHOW | List details about an object 列出对象详情 |
| SOURCE | Execute a file 执行文件 |
| STATUS (\s) | Display the current status 显示当前状态 |
| TRUNCATE | Empty a table 清空表 |
| UNLOCK | Unlock table(s) 解锁表 |
| UPDATE | Update an existing record 更新现有记录 |
| USE | Use a database 使用数据库 |
188. What are MySQL Database Queries?
什么是MySQL数据库查询?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4ff4 | 官方: 否 | 付费: 否
答案:
A query is a specific request or a question. One can query a database for specific information and have a record returned.
查询是一个具体的请求或问题。人们可以向数据库查询特定信息并返回一条记录。
189. How can you interact with MySQL?
如何与MySQL交互?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4ff7 | 官方: 否 | 付费: 否
答案:
There are three main ways you can interact with MySQL: - using a command line
与MySQL交互主要有三种方式:- 使用命令行
- via a web interface
- through a programming language
190. What does a MySQL database contain?
MySQL数据库包含什么?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4ffa | 官方: 否 | 付费: 否
答案:
A MySQL database contains one or more tables, each of which contains records or rows. Within these rows are various columns or fields that contain the data itself.
MySQL数据库包含一个或多个表,每个表包含记录或行。在这些行中,有各种列或字段,包含实际数据。
191. What does SQL in MySQL stand for?
MySQL中的SQL代表什么?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb4ffd | 官方: 否 | 付费: 否
答案:
The SQL in MySQL stands for Structured Query Language. This language is also used in other databases such as Oracle and Microsoft SQL Server. One can use commands such as the following to send requests from a database:
MySQL中的SQL代表结构化查询语言。这种语言也用于其他数据库,如Oracle和Microsoft SQL Server。人们可以使用以下命令向数据库发送请求:
SELECT title FROM publications WHERE author = ' J. K. Rowling’;
SELECT title FROM publications WHERE author = ' J. K. Rowling’;
Note that SQL is not case sensitive. However, it is a good practice to write the SQL keywords in CAPS and other names and variables in a small case.
注意,SQL不区分大小写。然而,好的实践是将SQL关键字写成大写,其他名称和变量写成小写。
You can check out this SQL Tutorial to learn more about SQL.
您可以查看这个SQL教程以了解更多关于SQL的信息。
192. What do you mean by ‘databases’?
你所说的“数据库”是什么意思?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb5000 | 官方: 否 | 付费: 否
答案:
A database is a structured collection of data stored in a computer system and organized in a way to be quickly searched. With databases, information can be rapidly retrieved.
数据库是存储在计算机系统中的结构化数据集合,并组织成可以快速搜索的方式。使用数据库,信息可以快速检索。
193. What are some of the advantages of using MySQL?
使用MySQL有哪些优点?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb5003 | 官方: 否 | 付费: 否
答案:
- Flexibility: MySQL runs on all operating systems
- Power: MySQL focuses on performance
- Enterprise-Level SQL Features: MySQL had for some time been lacking in advanced features such as subqueries, views, and stored procedures.
- Full-Text Indexing and Searching
- Query Caching: This helps enhance the speed of MySQL greatly
- Replication: One MySQL server can be duplicated on another, providing numerous advantages
- Configuration and Security
194. What is Database Trigger?
什么是数据库触发器?
- 知识点: 数据库 (标签: interviewbit, nagarro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Nagarro
- id: 69b37bf958d557c902bb617f | 官方: 否 | 付费: 否
答案:
A database trigger is a SQL statement that is run when you insert, update, or delete a row in your database. It allows you to execute code before or after the data is inserted into your database. This can be useful if you want to check for certain conditions before inserting data into your database, such as making sure the value of one field does not already exist. It also has other uses, such as checking if a user is logged in before allowing them to modify a record or deleting an existing record. A database trigger can be written in any programming language, although some languages are better suited than others. There are two types of triggers: Stored and User-Defined. - Stored triggers execute the code when a row is inserted (INSERT), updated (UPDATE), or deleted (DELETE).
数据库触发器是一种 SQL 语句,当您在数据库中插入、更新或删除一行时运行。它允许您在将数据插入数据库之前或之后执行代码。如果您想在将数据插入数据库之前检查某些条件,例如确保某个字段的值尚不存在,这会很有用。它还有其他用途,例如在允许用户修改或删除现有记录之前检查用户是否已登录。数据库触发器可以用任何编程语言编写,尽管有些语言比其他语言更合适。触发器有两种类型:存储触发器和用户定义触发器。- 存储触发器在插入(INSERT)、更新(UPDATE)或删除(DELETE)一行时执行代码。
- User-defined triggers can have custom logic built on top of them using VALUES.
195. What is the job of ALTER DATABASE command?
ALTER DATABASE 命令的作用是什么?
- 知识点: 数据库 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37bff58d557c902bb6663 | 官方: 否 | 付费: 否
答案:
The ALTER DATABASE command is a SQL command used to modify the properties or characteristics of a database in a relational database management system (RDBMS). Some examples of modifications that can be made using the ALTER DATABASE command include:
ALTER DATABASE 命令是一种 SQL 命令,用于修改关系数据库管理系统(RDBMS)中数据库的属性或特征。使用 ALTER DATABASE 命令可以进行的修改示例如下:
Changing the name of the database. 2. Modifying the default file locations for the database's data and log files. 3. Changing the compatibility level of the database. 4. Adding or removing filegroups from the database. 5. Setting the default language for the database. 6. Enabling or disabling features such as full-text search or change data capture.
- 更改数据库的名称。 2. 修改数据库数据和日志文件的默认文件位置。 3. 更改数据库的兼容性级别。 4. 向数据库添加或从中删除文件组。 5. 设置数据库的默认语言。 6. 启用或禁用全文搜索或变更数据捕获等功能。
Here is an example of how the ALTER DATABASE command could be used to change the default file location for a database's data files in SQL Server:
以下是一个示例,说明如何在 SQL Server 中使用 ALTER DATABASE 命令更改数据库数据文件的默认文件位置:
ALTER DATABASE MyDatabase
ALTER DATABASE MyDatabase
MODIFY FILE (NAME = MyDatabase_Data, FILENAME = 'C:\MyDatabase\MyDatabase_Data.mdf');
MODIFY FILE (NAME = MyDatabase_Data, FILENAME = 'C:\MyDatabase\MyDatabase_Data.mdf');
This command will change the default file location for the data files of the database "MyDatabase" to the specified location on the C drive.
此命令会将数据库“MyDatabase”的数据文件的默认文件位置更改为 C 盘上的指定位置。
196. What is an Oracle data integrator?
什么是 Oracle 数据集成器?
- 知识点: 数据库 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37c0058d557c902bb667c | 官方: 否 | 付费: 否
答案:
Oracle Data Integrator (ODI) is a data integration and ETL (extract, transform, load) tool developed by Oracle. It is designed to help organizations extract data from various sources, transform it into a desired format, and load it into a target database or system.
Oracle Data Integrator (ODI) 是 Oracle 开发的一款数据集成和 ETL(提取、转换、加载)工具。它旨在帮助组织从各种来源提取数据,将其转换为所需格式,并加载到目标数据库或系统中。
ODI is a graphical design tool that allows developers to build data integration workflows using a visual interface. It includes a number of pre-built connectors and transformations that can be used to extract data from various sources, including relational databases, flat files, and web services. It also includes a runtime engine that can execute the data integration workflows and load the data into the target systems.
ODI 是一款图形化设计工具,允许开发者使用可视化界面构建数据集成工作流。它包含许多预构建的连接器和转换,可用于从各种来源(包括关系数据库、平面文件和 Web 服务)提取数据。它还包含一个运行时引擎,可以执行数据集成工作流并将数据加载到目标系统中。
Some key features of Oracle Data Integrator include:
Oracle Data Integrator 的一些关键特性包括:
Data integration: ODI can extract data from various sources, transform it, and load it into the target systems. 2. Data quality: ODI includes a range of data quality transformations that can be used to clean and validate data before it is loaded into the target systems. 3. Scalability: ODI can handle large volumes of data and can be scaled to meet the needs of enterprise-level data integration projects. 4. Reusability: ODI allows developers to create reusable objects, such as mappings and transformations, which can be used in multiple data integration workflows.
- 数据集成:ODI 可以从各种来源提取数据,对其进行转换,并将其加载到目标系统中。 2. 数据质量:ODI 包含一系列数据质量转换,可用于在将数据加载到目标系统之前清理和验证数据。 3. 可扩展性:ODI 可以处理大量数据,并可以扩展以满足企业级数据集成项目的需求。 4. 可重用性:ODI 允许开发者创建可重用对象,例如映射和转换,这些对象可用于多个数据集成工作流。
ODI is often used to support data warehousing, master data management, and other data integration projects in organizations.
ODI 通常用于支持组织中的数据仓库、主数据管理和其他数据集成项目。
197. What are the benefits of a DataBase Management System?
数据库管理系统有哪些优势?
- 知识点: 数据库 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37c0058d557c902bb6681 | 官方: 否 | 付费: 否
答案:
A database management system (DBMS) is a software application that is used to create, manage, and manipulate databases. A database is a collection of data that is organized in a specific way, and a DBMS is used to access and manipulate that data.
数据库管理系统 (DBMS) 是一种用于创建、管理和操作数据库的软件应用程序。数据库是以特定方式组织的数据集合,而 DBMS 用于访问和操作这些数据。
There are several benefits to using a DBMS, including:
使用 DBMS 有若干优势,包括:
Data organization: A DBMS helps to organize data in a structured and efficient way, making it easier to access and retrieve data when needed. 2. Data security: A DBMS provides various security features, such as user authentication and data encryption, to protect data from unauthorized access. 3. Data integrity: A DBMS ensures that data is stored and accessed correctly, and it prevents data inconsistencies and corruption. 4. Data consistency: A DBMS ensures that data is consistent across the entire database, and it prevents data inconsistencies caused by multiple users accessing the same data simultaneously. 5. Data independence: A DBMS allows users to access data without having to know the underlying physical structure of the data, which makes it easier to modify the physical structure without affecting the way users access the data. 6. Data scalability: A DBMS can handle large volumes of data and can be scaled to meet the needs of an organization as it grows.
- 数据组织:DBMS 有助于以结构化和高效的方式组织数据,使在需要时访问和检索数据更加容易。 2. 数据安全:DBMS 提供各种安全功能,例如用户身份验证和数据加密,以保护数据免遭未经授权的访问。 3. 数据完整性:DBMS 确保数据被正确存储和访问,并防止数据不一致和损坏。 4. 数据一致性:DBMS 确保数据在整个数据库中保持一致,并防止多个用户同时访问相同数据所导致的数据不一致。 5. 数据独立性:DBMS 允许用户访问数据而无需了解数据的底层物理结构,这使得修改物理结构更加容易,而不会影响用户访问数据的方式。 6. 数据可扩展性:DBMS 可以处理大量数据,并可以随着组织的发展进行扩展以满足其需求。
198. What is a Relational DataBase Management System (RDBMS)?
什么是关系数据库管理系统 (RDBMS)?
- 知识点: 数据库 (标签: interviewbit, ntt-data, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: NTT DATA
- id: 69b37c0058d557c902bb6684 | 官方: 否 | 付费: 否
答案:
A relational database management system (RDBMS) is a type of DBMS (database management system) that is based on the relational model of data. In a relational database, data is organized into tables (also known as relations) and is accessed using a standard language called SQL (Structured Query Language).
关系数据库管理系统 (RDBMS) 是一种基于关系数据模型的 DBMS(数据库管理系统)。在关系数据库中,数据被组织成表(也称为关系),并使用一种称为 SQL(结构化查询语言)的标准语言进行访问。
In an RDBMS, data is stored in tables that consist of rows and columns. Each row represents a record (also known as a tuple), and each column represents an attribute of that record. For example, consider the following table:
在 RDBMS 中,数据存储在由行和列组成的表中。每一行代表一条记录(也称为元组),每一列代表该记录的一个属性。例如,考虑以下表:
| ID | FirstName | LastName | Age |
|---|---|---|---|
| 1 | John | Smith | 25 |
| 2 | Jane | Doe | 30 |
| 3 | Bob | Johnson | 35 |
| ID | FirstName | LastName | Age |
|---|---|---|---|
| 1 | John | Smith | 25 |
| 2 | Jane | Doe | 30 |
| 3 | Bob | Johnson | 35 |
In this table, "ID" is an attribute that uniquely identifies each record, "FirstName" and "LastName" are attributes that store the first and last names of each person, and "Age" is an attribute that stores the age of each person.
在这个表中,“ID”是唯一标识每条记录的属性,“FirstName”和“LastName”是存储每个人名字和姓氏的属性,而“Age”是存储每个人年龄的属性。
RDBMS are widely used to store and manage data in many types of organizations and are popular because they provide a number of benefits, such as:
RDBMS 广泛用于在许多类型的组织中存储和管理数据,并且因其提供了许多优势而受欢迎,例如:
Data integrity: RDBMSs ensure that data is stored and accessed correctly, and they prevent data inconsistencies and corruption. 2. Data security: RDBMSs provide various security features, such as user authentication and data encryption, to protect data from unauthorized access. 3. Data scalability: RDBMSs can handle large volumes of data and can be scaled to meet the needs of an organization as it grows. 4. Data independence: RDBMSs allow users to access data without having to know the underlying physical structure of the data, which makes it easier to modify the physical structure without affecting the way users access the data.
- 数据完整性:RDBMS 确保数据被正确存储和访问,并防止数据不一致和损坏。 2. 数据安全性:RDBMS 提供各种安全功能,如用户认证和数据加密,以保护数据免受未经授权的访问。 3. 数据可扩展性:RDBMS 可以处理大量数据,并且可以扩展以满足组织增长的需求。 4. 数据独立性:RDBMS 允许用户访问数据,而无需了解数据的底层物理结构,这使得修改物理结构更容易,而不会影响用户访问数据的方式。
199. What constitutes an Oracle Instance?
Oracle实例由什么构成?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0a58d557c902bb6ce4 | 官方: 否 | 付费: 否
答案:
- The SGA is a distributed memory that several programs can use. This section contains data that the instance needs to function.
System Global Area (SGA), a distributed memory space on RAM, and applications running make up an instance.
- 系统全局区(SGA),RAM上的分布式内存空间,以及运行的应用程序构成一个实例。
The running processes are OS processes, and every program in the instance has a specific role to play.
- 运行中的进程是操作系统进程,并且实例中的每个程序都有其特定的职责。
When an instance is "started," it creates the GAS and runs processes.
- 当一个实例“启动”时,它会创建GAS并运行进程。
The processes are destroyed and the common memory space is returned to the operating system when the instance status is "shut off."
- 当实例状态为“关闭”时,进程会被销毁,共享内存空间会归还给操作系统。
200. What is a trace file, and how does one make one?
什么是跟踪文件,如何创建跟踪文件?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0a58d557c902bb6cef | 官方: 否 | 付费: 否
答案:
A trace file can be created for each server and backend process. When a process or user process detects an operational fault, it spills data about the bugs to its trace. This information can be used to fine-tune the database.
可以为每个服务器和后台进程创建跟踪文件。当进程或用户进程检测到操作故障时,它会将有关错误的数据转储到其跟踪文件中。这些信息可用于微调数据库。
201. What are the advantages of ORDBMS?
ORDBMS 有哪些优势?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0a58d557c902bb6cf2 | 官方: 否 | 付费: 否
答案:
The items themselves can be saved in the database. The DBMS language can be used with an OOPs language. The language used in the program may even be the same, removing the need for the developer to have two versions of his objects.
数据项本身可以保存在数据库中。DBMS语言可以与OOPs语言一起使用。程序中使用的语言甚至可能是相同的,从而消除了开发人员需要为其对象维护两个版本的需求。
202. What occurs when we run an SQL statement in Oracle?
在Oracle中运行SQL语句时会发生什么?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0a58d557c902bb6cf5 | 官方: 否 | 付费: 否
答案:
At the very beginning, it validates the syntax and semantics in the cache of the library before creating a blueprint.
最初,在创建蓝图之前,它会验证库缓存中的语法和语义。
Data will be automatically returned to the client if it is already present in the buffer.
如果数据已存在于缓冲区中,数据将自动返回给客户端。
If the data is not present in the database, it will go to the data files and store it in the database buffer cache, then transmit it to the server, which will then deliver it to the user.
如果数据不在数据库中,则会进入数据文件并将其存储在数据库缓冲区缓存中,然后传输给服务器,服务器再将其传递给用户。
203. What is the distinction between a database and an instance?
数据库和实例之间的区别是什么?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0b58d557c902bb6cf8 | 官方: 否 | 付费: 否
答案:
The physical files that hold the data and information that compose up a database are referred to as database files. The control files, data files, and redo log files are among them.
构成数据库的保存数据和信息的物理文件被称为数据库文件。其中包含控制文件、数据文件和重做日志文件。
Whereas, The storage that is distributed and accessible by all threads and background processes is referred to as an instance.
而实例指的是由所有线程和后台进程分配并可访问的存储。
204. What are Oracle's disk components?
Oracle的磁盘组件有哪些?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0b58d557c902bb6cfb | 官方: 否 | 付费: 否
答案:
- Redo Log Files.
Parameter files.
- 参数文件。
Control files.
- 控制文件。
Data files.
- 数据文件。
Password files.
- 密码文件。
205. In a company, how does an Oracle DBA position vary from an Oracle Developer role? Is there any resemblance between these as well?
在公司中,Oracle DBA 职位与 Oracle 开发人员角色有何不同?这两者之间是否有相似之处?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0b58d557c902bb6cfe | 官方: 否 | 付费: 否
答案:
The Oracle developer is mostly in charge of creating backend applications. The model data in accordance with business rules. They generate tables, indexes, and other types of restrictions. They are required to be familiar with SQL and PL/SQL. These languages are used to create processes. Oracle developers, on the other hand, are not required to manage the database software.
Oracle 开发人员主要负责创建后端应用程序。根据业务规则对数据进行建模。他们生成表、索引和其他类型的约束。他们需要熟悉 SQL 和 PL/SQL。这些语言用于创建过程。然而,Oracle 开发人员不负责管理数据库软件。
But, an Oracle DBA's primary responsibility is to administer the database, which covers areas such as doing maintenance to keep the databases operational, taking backups, maintaining privacy standards, and so on. DBAs are not typically tasked with writing code. DBAs, like developers, are expected to have a strong understanding of SQL and PL/SQL, as they are also essential for database administration. DBAs may be allocated development responsibilities or, at the very least, support developers when needed, depending on the company's structure.
但是,Oracle DBA 的主要职责是管理数据库,涵盖诸如进行维护以保持数据库运行、进行备份、维护隐私标准等方面。DBA 通常不负责编写代码。与开发人员一样,DBA 被期望对 SQL 和 PL/SQL 有深刻理解,因为这些对于数据库管理也至关重要。根据公司的结构,DBA 可能被分配开发职责,或者至少在需要时支持开发人员。
206. Why Are Bind Variables Important?
为什么绑定变量很重要?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0b58d557c902bb6d01 | 官方: 否 | 付费: 否
答案:
Bind variables are crucial because most database suppliers provide an execution plan cache, which stores recently processed SQL statements and planning processes for again use.
绑定变量至关重要,因为大多数数据库供应商提供执行计划缓存,该缓存存储最近处理的 SQL 语句和规划过程以供再次使用。
207. What is the definition of normalization? What do the various types of normalization entail?
规范化的定义是什么?各种类型的规范化涉及什么内容?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0b58d557c902bb6d04 | 官方: 否 | 付费: 否
答案:
It is the process of structuring a relational database's fields and tables to reduce complexity and dependence. It guarantees that our data is consistent by saving the memory.
这是组织关系数据库的字段和表以减少复杂性和依赖性的过程。它通过节省内存来保证我们的数据一致性。
First normal form - Only single (atomic) valued attributes or columns should be used. A column's values must all belong to a certain domain. 2. Second normal form - It must be written in First Normal. It should also not be partially dependent. 3. Third normal form - It's in the shape of the Second Normal. It also lacks transitive dependencies. 4. Boyce and Codd Normal Form - Boyce and Codd is a more advanced variation of the Third Normal Form. This form is used to deal with anomalies that aren't addressed by 3NF. BCNF refers to a 3NF table that does not contain several identical candidate keys.
- 第一范式 - 应仅使用单个(原子)值的属性或列。列的值必须都属于特定域。 2. 第二范式 - 它必须写在第一范式中。它也不应具有部分依赖。 3. 第三范式 - 它处于第二范式的形式。它也没有传递依赖。 4. Boyce 和 Codd 范式 - Boyce 和 Codd 是第三范式的更高级变体。此形式用于处理 3NF 未解决的异常。BCNF 指的是不包含多个相同候选键的 3NF 表。
208. What are the elements of a logical data model, and how do they vary from a physical data model?
逻辑数据模型的元素是什么,它们与物理数据模型有何不同?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0b58d557c902bb6d07 | 官方: 否 | 付费: 否
答案:
The following are the elements of a logical data model:
以下是逻辑数据模型的元素:
Entity - An entity is a type of object that we utilize to store data. It comes with its own table. 2. Attribute - This reflects the information about the entity we're looking at. It is recorded as a table column with a particular data type connected to it. 3. Record - A record is a group of all the features associated with an object for a single condition, expressed in a table as a row. 4. Domain - A domain is the collection of all possibilities for a certain property. 5. Relationship - A relationship between two entities is represented by this object.
- 实体 - 实体是我们用来存储数据的对象类型。它有自己的表。 2. 属性 - 这反映我们正在查看的实体的信息。它记录为具有特定数据类型的表列。 3. 记录 - 记录是与单个条件的对象相关联的所有特征的组,在表中表示为一行。 4. 域 - 域是特定属性的所有可能值的集合。 5. 关系 - 此对象表示两个实体之间的关系。
209. What is the Oracle Grid Architecture?
什么是 Oracle 网格架构?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: system-design
- 分类: fullstack
- id: 69b37c0b58d557c902bb6d0a | 官方: 否 | 付费: 否
答案:
Oracle's grid design combines a huge database server, memory, and connections to create a customized, as per requirement computing resource for business computing demands. The grid computing architecture constantly evaluates the consumption of resources and changes supply accordingly.
Oracle 的网格设计结合了大型数据库服务器、内存和连接,以创建定制的、根据要求的计算资源,用于满足业务计算需求。网格计算架构不断评估资源消耗并相应调整供应。
You might, for example, run several programs on a grid of numerous connected database servers. If monthly reports are pending, the database administrator might automatically supply a dedicated server to that program to manage the growing demands.
例如,你可能会在由众多互联数据库服务器组成的网格上运行多个程序。如果月度报表尚未完成,数据库管理员可能会自动为该程序提供一台专用服务器,以应对不断增长的需求。
Grid computing employs advanced workload management, enabling programs to work cooperatively across several servers. As per requirement data processing ability may be added or deleted, and resources within a region can be provided flexibly. Web services enable the rapid integration of apps to establish a business.
网格计算采用高级工作负载管理,使程序能够在多台服务器上协同工作。根据需要,数据处理能力可以增加或删除,并且区域内资源可以灵活提供。Web服务使得应用能够快速集成以建立业务。
210. What are the different types of Oracle database shutdown modes?
Oracle数据库关闭模式有哪些不同类型?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0b58d557c902bb6d0d | 官方: 否 | 付费: 否
答案:
- Normal: New connections are not permitted in this option, and the database is terminated when all sessions quit.
- Immediate: New connections are not permitted, and all ongoing operations are returned.
- Transactional: New connections are not permitted, and Oracle will hold until all current processes have been finished.
- Abort: This occurs instantly, although the database is not completely shut down. When the database is restarted, it will have to conduct a quick restoration. We can't utilize this in everyday situations.
211. What is the distinction between a data block, an extent, and a segment?
数据块、区和段之间的区别是什么?
- 知识点: 数据库 (主题: oracle, dba, database;标签: interviewbit, oracle-dba, topic-specific, oracle, dba, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c0b58d557c902bb6d12 | 官方: 否 | 付费: 否
答案:
- A data block is a database object's basic logical storage unit. As objects expand in size, they require extra storage in the form of continuous data blocks.
- Extents are collections of consecutive data chunks.
- When all of an object's extents are gathered together, the segment is considered.
212. What are functions and their usage in SQL?
SQL 中的函数及其用法是什么?
- 知识点: 数据库 (标签: interviewbit, paypal, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: PayPal
- id: 69b37c0f58d557c902bb6f59 | 官方: 否 | 付费: 否
答案:
SQL functions are short bits of code that are commonly used and reused in database systems to process and manipulate data. The measured values are the functions. It always accomplishes a certain goal. When constructing functions, keep the following rules in mind:
SQL 函数是常用于数据库系统中处理和操作数据的简短代码片段,可重复使用。这些测量值就是函数。它总是实现某个特定目标。在构建函数时,请牢记以下规则:
- A function must be given a name, which cannot begin with a special character such as @, $, #, or other characters.
- Only SELECT statements can be used by functions.
- It compiles every time a function is called.
- Functions are required to return a value or a result.
- Input parameters are always utilised with functions.
213. What do you mean by autocommit mode in SQL Server?
SQL Server 中的自动提交模式是什么意思?
- 知识点: 数据库 (标签: interviewbit, paypay, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: PayPay
- id: 69b37c1158d557c902bb701a | 官方: 否 | 付费: 否
答案:
If you enable auto-commit mode, this means that once you have finished your statement, the method commit will be automatically called on the statement. The SQL Server Database Engine uses it as its default transaction management mode. By setting implicit_transactions ON, you can disable auto-commit. In SQL Server, you can disable auto-commit by running the following T-SQL command.
如果启用自动提交模式,这意味着一旦你完成语句,提交方法将自动在语句上调用。SQL Server 数据库引擎将其用作默认事务管理模式。通过设置 implicit_transactions ON,你可以禁用自动提交。在 SQL Server 中,你可以通过运行以下 T-SQL 命令来禁用自动提交。
SET IMPLICIT_TRANSACTIONS ON
SET IMPLICIT_TRANSACTIONS ON
When you use implicit transactions, every change you make starts a transaction that must be manually committed. If you want to enable it, simply run the OFF clause in the above command. You may enable auto-commit with the following command.
当你使用隐式事务时,你所做的每个更改都会启动一个必须手动提交的事务。如果你想启用它,只需运行上述命令中的 OFF 子句。你可以使用以下命令启用自动提交。
SET IMPLICIT_TRANSACTIONS OFF
SET IMPLICIT_TRANSACTIONS OFF
214. What is a rollback transaction?
什么是回滚事务?
- 知识点: 数据库 (标签: interviewbit, paypay, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: PayPay
- id: 69b37c1158d557c902bb702b | 官方: 否 | 付费: 否
答案:
In SQL, a rollback can be defined as the process of restoring a database to its previous state if there has been an error during the execution of a transaction. A rollback can either be performed automatically by a database system or manually by an end-user. The rollback function brings a transaction back to the beginning or undo any changes since the last COMMIT. Additionally, it releases resources used by the transaction.
在 SQL 中,回滚可以定义为在事务执行过程中出现错误时,将数据库恢复到先前状态的过程。回滚可以由数据库系统自动执行,也可以由最终用户手动执行。回滚功能将事务带回起点或撤销自上次 COMMIT 以来的任何更改。此外,它还释放事务使用的资源。
Example: Consider the following ScalerEmp table.
示例:考虑以下 ScalerEmp 表。
| Emp_ID | Name | Date of Joining | Position | Age |
|---|---|---|---|---|
| 101 | Ankit Verma | 1 July 2022 | Program Manager | 29 |
| 102 | Ashutosh Mukherji | 5 Jan 2021 | SEO Manager | 25 |
| 103 | Sonal Dange | 23 March 2020 | Content Writer | 26 |
| 104 | Isha Joshi | 1 July 2022 | Data Analyst | 27 |
| 105 | Kunal Swami | 10 October 2021 | Business Development Executive | 29 |
| Emp_ID | Name | Date of Joining | Position | Age |
|---|---|---|---|---|
| 101 | Ankit Verma | 1 July 2022 | Program Manager | 29 |
| 102 | Ashutosh Mukherji | 5 Jan 2021 | SEO Manager | 25 |
| 103 | Sonal Dange | 23 March 2020 | Content Writer | 26 |
| 104 | Isha Joshi | 1 July 2022 | Data Analyst | 27 |
| 105 | Kunal Swami | 10 October 2021 | Business Development Executive | 29 |
Perform the following SQL query:
执行以下 SQL 查询:
DELETE from ScalerEmp Where Age = 29;
DELETE from ScalerEmp Where Age = 29;
ROLLBACK;
ROLLBACK;
Output:
输出:
| Emp_ID | Name | Date of Joining | Position | Age |
|---|---|---|---|---|
| 102 | Ashutosh Mukherji | 5 Jan 2021 | SEO Manager | 25 |
| 103 | Sonal Dange | 23 March 2020 | Content Writer | 26 |
| 104 | Isha Joshi | 1 july 2022 | Data Analyst | 27 |
| Emp_ID | Name | Date of Joining | Position | Age |
|---|---|---|---|---|
| 102 | Ashutosh Mukherji | 5 Jan 2021 | SEO Manager | 25 |
| 103 | Sonal Dange | 23 March 2020 | Content Writer | 26 |
| 104 | Isha Joshi | 1 july 2022 | Data Analyst | 27 |
In the above table, we can see that two employee records with the age of 29 that satisfy the age criteria have been removed from the ScalerEmp table. Lastly, we executed a ROLLBACK query to undo the changes.
在上表中,我们可以看到 ScalerEmp 表中符合年龄条件的两位年龄为 29 的员工记录已被移除。最后,我们执行了一个 ROLLBACK 查询以撤销更改。
Now, use the select command to display records from the ScalerEmp table.
现在,使用 select 命令显示 ScalerEmp 表中的记录。
Select * from ScalerEmp;
Select * from ScalerEmp;
Output:
输出:
| Emp_ID | Name | Date of Joining | Position | Age |
|---|---|---|---|---|
| 101 | Ankit Verma | 1 July 2022 | Program Manager | 29 |
| 102 | Ashutosh Mukherji | 5 Jan 2021 | SEO Manager | 25 |
| 103 | Sonal Dange | 23 March 2020 | Content Writer | 26 |
| 104 | Isha Joshi | 1 July 2022 | Data Analyst | 27 |
| 105 | Kunal Swami | 10 October 2021 | Business Development Executive | 29 |
| Emp_ID | Name | Date of Joining | Position | Age |
|---|---|---|---|---|
| 101 | Ankit Verma | 1 July 2022 | Program Manager | 29 |
| 102 | Ashutosh Mukherji | 5 Jan 2021 | SEO Manager | 25 |
| 103 | Sonal Dange | 23 March 2020 | Content Writer | 26 |
| 104 | Isha Joshi | 1 July 2022 | Data Analyst | 27 |
| 105 | Kunal Swami | 10 October 2021 | Business Development Executive | 29 |
As we can see from the above table, the Rollback statement restored the ScalerEmp table to its previous state.
从上表中我们可以看到,Rollback 语句将 ScalerEmp 表恢复到了之前的状态。
215. Write SQL query to find an employee with the second highest salary.
编写 SQL 查询以找出薪水第二高的员工。
- 知识点: 数据库 (标签: interviewbit, persistent, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Persistent Systems
- id: 69b37c1858d557c902bb7426 | 官方: 否 | 付费: 否
答案:
Consider the following table “Employee”:
考虑以下表“Employee”:
| Name | Position | Salary |
|---|---|---|
| Gourav | SDE 2 | 1,00,000 |
| Sonal | Data Analyst | 1,50,000 |
| Kunal | Content Specialist | 80,000 |
| Farhan | Team Lead | 2,00,000 |
| Ashutosh | Product Lead | 1,70,000 |
| Name | Position | Salary |
|---|---|---|
| Gourav | SDE 2 | 1,00,000 |
| Sonal | Data Analyst | 1,50,000 |
| Kunal | Content Specialist | 80,000 |
| Farhan | Team Lead | 2,00,000 |
| Ashutosh | Product Lead | 1,70,000 |
To find the second-highest-paid employee, simply run the SQL query below:
要找出薪水第二高的员工,只需运行下面的 SQL 查询:
SELECT MAX(Salary) FROM Employee WHERE Salary < (SELECT MAX(Salary) FROM Employee);
SELECT MAX(Salary) FROM Employee WHERE Salary < (SELECT MAX(Salary) FROM Employee);
Or
或者
SELECT Name, MAX(Salary) as Salary from Employee where Salary <(SELECT MAX(Salary) FROM Employee);
SELECT Name, MAX(Salary) as Salary from Employee where Salary <(SELECT MAX(Salary) FROM Employee);
216. What does aggregation mean in relation to databases?
在数据库方面,聚合是什么意思?
- 知识点: 数据库 (标签: interviewbit, persistent, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Persistent Systems
- id: 69b37c1858d557c902bb7429 | 官方: 否 | 付费: 否
答案:
The aggregate function in database management is a function that takes the values of multiple rows and combines them into a single valuable entity. Since the values do not make sense separately, they are combined. Aggregation establishes a relationship which combines these values from different rows to create a single entity. Some common aggregate functions include Count, Average (i.e., arithmetic mean), Median, Minimum, Maximum, Mode, Sum, and Range.
数据库管理中的聚合函数是一种将多行的值组合成一个有价值实体的函数。由于这些值单独没有意义,因此将它们组合起来。聚合建立了一种关系,将来自不同行的这些值组合起来创建单个实体。一些常见的聚合函数包括计数、平均值(即算术平均值)、中位数、最小值、最大值、众数、求和和范围。
217. Describe the ACID properties of a database.
描述数据库的ACID属性。
- 知识点: 数据库 (标签: interviewbit, persistent, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Persistent Systems
- id: 69b37c1858d557c902bb742c | 官方: 否 | 付费: 否
答案:
A transaction is a sequence of operations performed as one unit of work, and it can include one or more steps. Transactions make use of the read and write operations to access data. A database must follow certain properties and guidelines before and after each transaction to maintain consistency. Such properties are known as ACID properties. ACID stands for Atomicity, Consistency, Isolation and Durability, which are properties of a transaction in a database system.
事务是作为单个工作单元执行的一系列操作,它可以包含一个或多个步骤。事务利用读和写操作来访问数据。数据库必须在每个事务前后遵循某些属性和准则以保持一致性。这些属性被称为ACID属性。ACID代表原子性、一致性、隔离性和持久性,它们是数据库系统中事务的属性。
ACID properties are designed to maintain the integrity of the data, ensuring that the data does not become corrupted by some failure, guaranteeing validity even in the presence of errors or failures. Therefore, all transactions in a database must adhere to ACID properties.
ACID属性旨在维护数据的完整性,确保数据不会因某些故障而损坏,即使在出现错误或故障时也能保证有效性。因此,数据库中的所有事务都必须遵守ACID属性。
218. What are the features of PL/SQL?
PL/SQL有哪些特性?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1958d557c902bb752c | 官方: 否 | 付费: 否
答案:
Following are the features of PL/SQL: - PL/SQL provides the feature of decision making, looping, and branching by making use of its procedural nature.
以下是PL/SQL的特性:- PL/SQL通过其过程化特性提供了决策、循环和分支的功能。
- Multiple queries can be processed in one block by making use of a single command using PL/SQL.
- The PL/SQL code can be reused by applications as they can be grouped and stored in databases as PL/SQL units like functions, procedures, packages, triggers, and types.
- PL/SQL supports exception handling by making use of an exception handling block.
- Along with exception handling, PL/SQL also supports error checking and validation of data before data manipulation.
- Applications developed using PL/SQL are portable across computer hardware or operating system where there is an Oracle engine.
219. What is the purpose of WHEN clause in the trigger?
触发器中的WHEN子句的目的是什么?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb752f | 官方: 否 | 付费: 否
答案:
- WHEN clause specifies for what condition the trigger has to be triggered.
220. How do you write comments in a PL/SQL code?
如何在PL/SQL代码中编写注释?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c1a58d557c902bb7532 | 官方: 否 | 付费: 否
答案:
- Comments are those sentences that have no effect on the functionality and are used for the purpose of enhancing the readability of the code. They are of two types:
Single Line Comment: This can be created by using the symbol -- and writing what we want to mention as a comment next to it.
单行注释:可以通过使用符号--并在其旁边写下我们想要提及的注释内容来创建。
Multi-Line comment: These are the comments that can be specified over multiple lines and the syntax goes like / comment information / - Example:
多行注释:这些是可以跨多行指定的注释,语法类似于/注释信息/ - 示例:
SET SERVEROUTPUT ON;
SET SERVEROUTPUT ON;
DECLARE
声明
-- Hi There! I am a single line comment.
-- 嗨,你好!我是单行注释。
var_name varchar2(40) := 'I love PL/SQL' ;
var_name varchar2(40) := '我喜欢PL/SQL' ;
BEGIN
BEGIN
/*
Hi! I am a multi line
嗨!我是一个多行
comment. I span across
注释。我跨越
multiple lines
多行
*/
dbms_output.put_line(var_name);
dbms_output.put_line(var_name);
END;
结束;
/
Output:
输出:
I love PL/SQL
我喜欢PL/SQL
221. When does a DECLARE block become mandatory?
什么时候DECLARE块成为必需的?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7535 | 官方: 否 | 付费: 否
答案:
- This statement is used by anonymous blocks of PL/SQL such as non-stored and stand-alone procedures. When they are being used, the statement should come first in the stand-alone file.
222. What is a Trigger? Name some instances when “Triggers” can be used.
什么是触发器?请列举一些可以使用“触发器”的实例。
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7538 | 官方: 否 | 付费: 否
答案:
- As the name indicates, ‘Trigger’ means to ‘activate’ something. In the case of PL/SQL, a trigger is a stored procedure that specifies what action has to be taken by the database when an event related to the database is performed.
- Syntax:
TRIGGER trigger_name
TRIGGER trigger_name
trigger_event
trigger_event
[ restrictions ]
[ restrictions ]
BEGIN
BEGIN
actions_of_trigger;
actions_of_trigger;
END;
结束;
In the above syntax, if the trigger_name the trigger is in the enabled state, the trigger_event causes the database to fire actions_of_trigger if the restrictions are TRUE or unavailable. - They are mainly used in the following scenarios:
在上述语法中,如果触发器的trigger_name处于启用状态,当restrictions为TRUE或不可用时,trigger_event会导致数据库触发actions_of_trigger。- 它们主要用于以下场景:
In order to maintain complex integrity constraints. For the purpose of auditing any table information. Whenever changes are done to a table, if we need to signal other actions upon completion of the change, then we use triggers. In order to enforce complex rules of business. It can also be used to prevent invalid transactions. - You can refer https://docs.oracle.com/database/121/TDDDG/tdddg_triggers.htm for more information regarding triggers.
为了维护复杂的完整性约束。用于审计任何表的信息。每当对表进行更改时,如果我们需要在更改完成后通知其他操作,则使用触发器。为了实施复杂的业务规则。它也可以用于防止无效事务。- 您可以参考https://docs.oracle.com/database/121/TDDDG/tdddg_triggers.htm获取有关触发器的更多信息。
223. How can a name be assigned to an unnamed PL/SQL Exception Block?
如何为未命名的PL/SQL异常块指定名称?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb753b | 官方: 否 | 付费: 否
答案:
- This can be done by using Pragma called EXCEPTION_INIT.
- This gives the flexibility to the programmer to instruct the compiler to provide custom error messages based on the business logic by overriding the pre-defined messages during the compilation time.
- Syntax:
DECLARE
声明
exception_name EXCEPTION;
exception_name EXCEPTION;
PRAGMA EXCEPTION_INIT (exception_name, error_code);
PRAGMA EXCEPTION_INIT (exception_name, error_code);
BEGIN
BEGIN
// PL/SQL Logic
// PL/SQL 逻辑
EXCEPTION
EXCEPTION
WHEN exception_name THEN
WHEN exception_name THEN
// Steps to handle exception
// 处理异常的步骤
END;
结束;
224. What is the use of WHERE CURRENT OF in cursors?
在游标中使用 WHERE CURRENT OF 有什么作用?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb753e | 官方: 否 | 付费: 否
答案:
- We use this clause while referencing the current row from an explicit cursor. This clause allows applying updates and deletion of the row currently under consideration without explicitly referencing the row ID.
- Syntax:UPDATE table_name SET field=new_value WHERE CURRENT OF cursor_name
225. What is a PL/SQL cursor?
什么是 PL/SQL 游标?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7541 | 官方: 否 | 付费: 否
答案:
- A PL/SQL cursor is nothing but a pointer to an area of memory having SQL statements and the information of statement processing. This memory area is called a context area. This special area makes use of a special feature called cursor for the purpose of retrieving and processing more than one row.
- In short, the cursor selects multiple rows from the database and these selected rows are individually processed within a program.
- There are two types of cursors:
Implicit Cursor:
隐式游标:
Oracle automatically creates a cursor while running any of the commands - SELECT INTO, INSERT, DELETE or UPDATE implicitly.
当运行任何命令(如 SELECT INTO、INSERT、DELETE 或 UPDATE)时,Oracle 会自动隐式地创建一个游标。
The execution cycle of these cursors is internally handled by Oracle and returns the information and status of the cursor by making use of the cursor attributes- ROWCOUNT, ISOPEN, FOUND, NOTFOUND.
这些游标的执行周期由 Oracle 内部处理,并通过使用游标属性——ROWCOUNT、ISOPEN、FOUND、NOTFOUND——来返回游标的信息和状态。
Explicit Cursor: This cursor is a SELECT statement that was declared explicitly in the declaration block. The programmer has to control the execution cycle of these cursors starting from OPEN to FETCH and close. The execution cycle while executing the SQL statement is defined by Oracle along with associating a cursor with it. - Explicit Cursor Execution Cycle:Due to the flexibility of defining our own execution cycle, explicit cursors are used in many instances. The following diagram represents the execution flow of an explicit cursor:
显式游标:这是在声明块中显式声明的 SELECT 语句。程序员必须控制这些游标的执行周期,从 OPEN 到 FETCH 再到 CLOSE。执行 SQL 语句时的执行周期由 Oracle 定义,同时将游标与之关联。- 显式游标执行周期:由于能够灵活地定义我们自己的执行周期,显式游标在许多情况下被使用。下图展示了显式游标的执行流程:
Cursor Declaration:
The first step to use an explicit cursor is its declaration. Declaration can be done in a package or a block.使用显式游标的第一步是其声明。声明可以在包或块中完成。
Syntax: CURSOR cursor_name IS query; where cursor_name is the name of the cursor, the query is the query to fetch data from any table. - Open Cursor:
语法:CURSOR cursor_name IS query; 其中 cursor_name 是游标的名称,query 是从任何表中获取数据的查询。- 打开游标:
Before the process of fetching rows from cursor, the cursor has to be opened.
在从游标获取行的过程之前,必须先打开游标。
Syntax to open a cursor: OPEN cursor_name;
打开游标的语法:OPEN cursor_name;
When the cursor is opened, the query and the bind variables are parsed by Oracle and the SQL statements are executed. The execution plan is determined by Oracle and the result set is determined after associating the cursor parameters and host variables and post these, the cursor is set to point at the first row of the result set. - Fetch from cursor:
当游标被打开时,Oracle 会解析查询和绑定变量,并执行 SQL 语句。Oracle 确定执行计划,并在关联游标参数和宿主变量后确定结果集,随后游标被设置为指向结果集的第一行。- 从游标获取:
FETCH statement is used to place the content of the current row into variables.
FETCH 语句用于将当前行的内容放入变量中。
Syntax: FETCH cursor_name INTO variable_list;
语法:FETCH cursor_name INTO variable_list;
In order to get all the rows of a result set, each row needs to be fetched. - Close Cursor:
为了获取结果集中的所有行,需要逐行进行获取。- 关闭游标:
Once all the rows are fetched, the cursor needs to be closed using the CLOSE statement.
一旦所有行都被获取,需要使用 CLOSE 语句关闭游标。
Syntax: CLOSE cursor_name;
语法:CLOSE cursor_name;
The instructions tell Oracle to release the memory allocated to the cursor. Cursors declared in procedures or anonymous blocks are by default closed post their execution. Cursors declared in packages need to be closed explicitly as the scope is global. Closing a cursor that is not opened will result in INVALID_CURSOR exception.
这些指令告知 Oracle 释放分配给游标的内存。在过程或匿名块中声明的游标默认在执行后自动关闭。在包中声明的游标需要显式关闭,因为其作用域是全局的。关闭一个未打开的游标将导致 INVALID_CURSOR 异常。
226. Explain the basic structure followed in PL/SQL?
解释 PL/SQL 中遵循的基本结构?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7544 | 官方: 否 | 付费: 否
答案:
- The basic structure of PL/SQL follows the BLOCK structure. Each PL/SQL code comprises SQL and PL/SQL statement that constitutes a PL/SQL block.
Each PL/SQL block consists of 3 sections:
The optional Declaration Section可选的声明部分
The mandatory Execution Section
必需的执行部分
The optional Exception handling Section
可选的异常处理部分
[DECLARE]
[DECLARE]
--declaration statements (optional)
--声明语句(可选)
BEGIN
BEGIN
--execution statements
--执行语句
[EXCEPTION]
[异常处理]
--exception handling statements (optional)
--异常处理语句(可选)
END;
结束;
227. What do you understand by PL/SQL table?
你对PL/SQL表有什么理解?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7547 | 官方: 否 | 付费: 否
答案:
- PL/SQL tables are nothing but objects of type tables that are modeled as database tables. They are a way to provide arrays that are nothing but temporary tables in memory for faster processing.
- These tables are useful for moving bulk data thereby simplifying the process.
228. How do you create a table in MySQL?
如何在MySQL中创建表?
- 知识点: 数据库 (标签: interviewbit, publicis-sapient, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Publicis Sapient
- id: 69b37c2058d557c902bb7a38 | 官方: 否 | 付费: 否
答案:
To create a table in MySQL, you can use the CREATE TABLE statement. Here is the syntax for creating a table in MySQL:
要在MySQL中创建表,可以使用CREATE TABLE语句。以下是在MySQL中创建表的语法:
CREATE TABLE table_name (
CREATE TABLE table_name (
column_name1 data_type(size),
column_name1 data_type(size),
column_name2 data_type(size),
column_name2 data_type(size),
...
);
Replace "table_name" with the name you want to give to your table, and "column_name" and "data_type" with the names and data types of the columns you want to include in your table. The size parameter is optional and specifies the size or precision of the column.
将“table_name”替换为您想为表指定的名称,将“column_name”和“data_type”替换为您想包含在表中的列的名称和数据类型。size参数是可选的,用于指定列的大小或精度。
Here is an example of how you might create a table in MySQL:
以下是一个如何在MySQL中创建表的示例:
CREATE TABLE customers (
CREATE TABLE customers (
customer_id INT(11) NOT NULL AUTO_INCREMENT,
customer_id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
PRIMARY KEY (customer_id)
PRIMARY KEY (customer_id)
);
This MySQL statement will create a table with the name "customers", and will include three columns: "customer_id", "name", and "email". The "customer_id" column is an integer data type with a size of 11, and is set as the primary key for the table. The "name" and "email" columns are both variable character data types with a size of 255.
这个 MySQL 语句将创建一个名为“customers”的表,并包含三个列:“customer\_id”、“name”和“email”。“customer\_id”列是大小为 11 的整数数据类型,并被设置为该表的主键。“name”和“email”列都是大小为 255 的可变字符数据类型。
229. Can you explain the difference between a UNION and a UNION ALL in SQL?
你能解释一下 SQL 中 UNION 和 UNION ALL 的区别吗?
- 知识点: 数据库 (标签: interviewbit, publicis-sapient, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Publicis Sapient
- id: 69b37c2058d557c902bb7a3b | 官方: 否 | 付费: 否
答案:
In SQL, the UNION and UNION ALL clauses are used to combine the results of two or more SELECT statements into a single result set. However, they are used in slightly different ways and serve different purposes.
在 SQL 中,UNION 和 UNION ALL 子句用于将两个或多个 SELECT 语句的结果合并为一个结果集。然而,它们的使用方式略有不同,且服务于不同的目的。
The UNION clause is used to combine the results of two or more SELECT statements, but only includes unique rows in the final result set. This means that if a row appears in more than one SELECT statement and is included in the final result set, it will only be included once.
UNION 子句用于合并两个或多个 SELECT 语句的结果,但最终结果集中只包含唯一的行。这意味着,如果某一行出现在多个 SELECT 语句中并被包含在最终结果集中,它只会被包含一次。
Here is an example of how you might use a UNION clause in SQL:
以下是一个你可能如何在 SQL 中使用 UNION 子句的示例:
SELECT * FROM table1
SELECT * FROM table1
UNION
UNION
SELECT * FROM table2;
SELECT * FROM table2;
This SQL statement will return all rows from both the "table1" and "table2" tables, but will only include unique rows in the final result set.
这个 SQL 语句将返回“table1”和“table2”表中的所有行,但最终结果集中只包含唯一的行。
The UNION ALL clause is similar to the UNION clause, but includes all rows in the final result set, regardless of whether they are duplicates or not.
UNION ALL 子句与 UNION 子句类似,但会在最终结果集中包含所有行,无论它们是否重复。
Here is an example of how you might use a UNION ALL clause in SQL:
以下是一个你可能如何在 SQL 中使用 UNION ALL 子句的示例:
SELECT * FROM table1
SELECT * FROM table1
UNION ALL
UNION ALL
SELECT * FROM table2;
SELECT * FROM table2;
This SQL statement will return all rows from both the "table1" and "table2" tables, including any duplicates.
这个 SQL 语句将返回“table1”和“table2”表中的所有行,包括任何重复项。
The UNION and UNION ALL clauses are useful tools for combining the results of multiple SELECT statements in SQL, but are used in slightly different ways and serve different purposes. Understanding the differences between these two clauses can help you use them effectively in your SQL queries.
UNION 和 UNION ALL 子句是在 SQL 中合并多个 SELECT 语句结果的有用工具,但它们的使用方式略有不同,且服务于不同的目的。理解这两个子句之间的差异可以帮助你在 SQL 查询中有效地使用它们。
230. Can you explain the difference between a primary and a foreign key in a database?
你能解释一下数据库中主键和外键的区别吗?
- 知识点: 数据库 (标签: interviewbit, publicis-sapient, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Publicis Sapient
- id: 69b37c2058d557c902bb7a3e | 官方: 否 | 付费: 否
答案:
In a database, a primary key is a field or set of fields that uniquely identifies each row in a table. A foreign key is a field or set of fields in one table that refers to the primary key of another table.
在数据库中,主键是唯一标识表中每一行的字段或字段集。外键是一个表中引用另一个表的主键的字段或字段集。
Here is an example of how primary and foreign keys can be used in a database:
以下是一个在数据库中使用主键和外键的示例:
Consider a database with two tables: a "customers" table and an "orders" table. The "customers" table might contain fields for the customer's ID, name, address, and phone number, while the "orders" table might contain fields for the order ID, customer ID, product ID, and quantity.
考虑一个包含两个表的数据库:一个“customers”表和一个“orders”表。“customers”表可能包含客户ID、姓名、地址和电话号码等字段,而“orders”表可能包含订单ID、客户ID、产品ID和数量等字段。
In this example, the customer ID field in the "customers" table could be used as the primary key, since it uniquely identifies each customer. The customer ID field in the "orders" table could then be used as a foreign key, since it refers to the primary key (customer ID) in the "customers" table.
在这个例子中,“customers”表中的客户ID字段可以用作主键,因为它唯一标识每个客户。“orders”表中的客户ID字段则可以用作外键,因为它引用了“customers”表中的主键(客户ID)。
By using primary and foreign keys in this way, the database can establish relationships between the two tables and ensure that the data is consistent and accurate. For example, if a customer's name or address changes in the "customers" table, that change will be automatically reflected in the "orders" table, since the "orders" table uses the customer ID as a foreign key to refer to the "customers" table.
通过以这种方式使用主键和外键,数据库可以在两个表之间建立关系,并确保数据的一致性和准确性。例如,如果“customers”表中客户的姓名或地址发生变化,该变化将自动反映在“orders”表中,因为“orders”表使用客户ID作为外键来引用“customers”表。
Overall, primary and foreign keys are important concepts in database design, and are used to establish relationships between tables and ensure the integrity and accuracy of the data in the database.
总的来说,主键和外键是数据库设计中的重要概念,用于在表之间建立关系,并确保数据库中数据的完整性和准确性。
Here is a comparison of primary and foreign keys in tabular form:
以下是以表格形式对主键和外键的比较:
| Property 属性 | Primary Key 主键 | Foreign Key 外键 |
|---|---|---|
| Definition 定义 | A field or set of fields that uniquely identifies each row in a table 唯一标识表中每一行的字段或字段集 | A field or set of fields in one table that refers to the primary key of another table 一个表中引用另一个表的主键的字段或字段集 |
| Role in database 在数据库中的作用 | Establishes a unique identifier for each row in a table 为表中的每一行建立唯一标识符 | Establishes a relationship between two tables by linking rows in one table to the primary key of another table 通过将一个表中的行链接到另一个表的主键,在两个表之间建立关系 |
| Example 示例 | Customer ID, order ID 客户ID、订单ID | Customer ID in orders table (refers to the primary key in customers table) orders表中的客户ID(引用customers表中的主键) |
| - Definition: A primary key is a field or set of fields that uniquely identifies each row in a table, while a foreign key is a field or set of fields in one table that refers to the primary key of another table. - 定义:主键是唯一标识表中每一行的字段或字段集,而外键是一个表中引用另一个表的主键的字段或字段集。 |
- Role in database: Primary keys play a crucial role in establishing a unique identifier for each row in a table, while foreign keys are used to establish relationships between tables and link rows in one table to the primary key of another table.
Example: In the example provided earlier, the customer ID field in the "customers" table could be used as the primary key, while the customer ID field in the "orders" table could be used as a foreign key to refer to the primary key in the "customers" table.
primary and foreign keys are important concepts in database design and are used to establish relationships between tables and ensure the integrity and accuracy of the data in the database. Understanding the differences between these two types of keys can help you design and use databases more effectively.主键和外键是数据库设计中的重要概念,用于在表之间建立关系,并确保数据库中数据的完整性和准确性。理解这两种键之间的区别可以帮助你更有效地设计和使用数据库。
231. What is a database, and why is it important?
什么是数据库,为什么它很重要?
- 知识点: 数据库 (标签: interviewbit, publicis-sapient, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Publicis Sapient
- id: 69b37c2058d557c902bb7a41 | 官方: 否 | 付费: 否
答案:
A database is a collection of data that is organized and stored in a structured way so that it can be accessed and manipulated efficiently. Databases are used to store and manage large amounts of data and are an important tool in a variety of settings, including business, government, and education.
数据库是以结构化方式组织和存储的数据集合,以便能够高效地访问和操作。数据库用于存储和管理大量数据,是各种环境中的重要工具,包括商业、政府和教育领域。
There are several types of databases, including relational databases, which store data in tables with rows and columns, and object-oriented databases, which store data in the form of objects. While object-oriented databases do support the storage of complex data types and objects, they are not limited to just that data model. Object-oriented databases can also support other data models such as key-value or document-oriented databases.
数据库有多种类型,包括将数据存储在具有行和列的表格中的关系型数据库,以及以对象形式存储数据的面向对象数据库。虽然面向对象数据库确实支持复杂数据类型和对象的存储,但它们并不仅限于该数据模型。面向对象数据库还可以支持其他数据模型,例如键值或面向文档的数据库。
In fact, many modern databases are designed to support multiple data models to provide greater flexibility and meet the needs of different applications. For example, some databases may support both relational and document-oriented data models, allowing developers to choose the model that best fits their data and application requirements.
事实上,许多现代数据库被设计为支持多种数据模型,以提供更大的灵活性并满足不同应用程序的需求。例如,一些数据库可能同时支持关系型和面向文档的数据模型,允许开发人员选择最适合其数据和应用程序需求的模型。
Therefore, it is important to note that while object-oriented databases can store data in the form of objects, they are not limited to just that model, and can support a variety of different data models depending on the specific requirements of the application.
因此,需要注意的是,虽然面向对象数据库可以以对象的形式存储数据,但它们并不仅限于该模型,并且可以根据应用程序的具体需求支持多种不同的数据模型。
Some databases are designed to support specific applications, such as financial systems or inventory management, while others are more general-purpose and can be used for a wide range of applications.
一些数据库被设计为支持特定应用程序,例如金融系统或库存管理,而另一些则更为通用,可用于广泛的应用程序。
In addition to databases designed for specific applications such as financial systems or inventory management, there are several other types of specialized databases designed for specific types of data and applications. Here are some examples: - Time-series databases: These databases are designed for storing and analyzing time-series data, which is data that is collected over time at regular intervals. Examples of time-series data include stock prices, weather data, and website traffic. Time-series databases are optimized for handling large volumes of time-stamped data and for performing time-based queries and analyses.
除了为特定应用(如金融系统或库存管理)设计的数据库之外,还有几种其他类型的专用数据库,专为特定类型的数据和应用而设计。以下是一些示例:- 时间序列数据库:这些数据库专为存储和分析时间序列数据而设计,时间序列数据是按固定时间间隔随时间收集的数据。时间序列数据的示例包括股票价格、天气数据和网站流量。时间序列数据库针对处理大量带有时间戳的数据以及执行基于时间的查询和分析进行了优化。
- Graph databases: Graph databases are designed for storing and querying data that has a graph-like structure, such as social networks, recommendation engines, and knowledge graphs. Graph databases use graph theory to represent and query data, making it easy to navigate complex relationships between entities.
Spatial databases: Spatial databases are designed for storing and querying geospatial data, such as maps, satellite imagery, and location data. Spatial databases use specialized algorithms and data structures to optimize queries that involve spatial data.
Other examples of specialized databases include document databases, which are designed for storing and querying semi-structured and unstructured data such as emails, PDFs, and JSON documents; and columnar databases, which are designed for storing and querying large amounts of structured data such as log files and transaction data.专用数据库的其他示例包括文档数据库,其专为存储和查询半结构化和非结构化数据(如电子邮件、PDF 和 JSON 文档)而设计;以及列式数据库,其专为存储和查询大量结构化数据(如日志文件和事务数据)而设计。
One of the main reasons that databases are important is that they allow for the efficient storage and management of large amounts of data. By organizing data in a structured way, databases make it easy to retrieve, update, and manipulate data as needed. This is especially important for organizations that need to manage large amounts of data, such as customer records, sales data, or inventory information.
数据库之所以重要的主要原因之一是,它们能够高效地存储和管理大量数据。通过以结构化方式组织数据,数据库使得根据需要检索、更新和操作数据变得容易。这对于需要管理大量数据(如客户记录、销售数据或库存信息)的组织尤为重要。
Another reason that databases are important is that they provide a way to ensure the integrity and security of data. Databases can be designed with security measures in place to prevent unauthorized access to data, and can also include features to help ensure that data is accurate and consistent.
数据库之所以重要的另一个原因是,它们提供了一种确保数据完整性和安全性的方式。数据库可以设计有安全措施以防止未经授权访问数据,并且还可以包含有助于确保数据准确和一致的功能。
Databases are an essential tool for storing, managing and accessing large amounts of data in a structured and efficient way. They play a critical role in a wide range of settings and are an important component of many modern computing systems.
数据库是以结构化且高效的方式存储、管理和访问大量数据的重要工具。它们在广泛的场景中发挥着关键作用,并且是许多现代计算系统的重要组成部分。
232. SQL Query to find min, max and average salary from a table?
用于从表中查找最低、最高和平均工资的 SQL 查询?
- 知识点: 数据库 (标签: interviewbit, pwc, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 普华永道
- id: 69b37c2258d557c902bb7b0d | 官方: 否 | 付费: 否
答案:
Suppose assume the table is in the format shown below,:
假设该表采用如下所示的格式:
Employee table:
员工表:
| Name | Salary |
|---|---|
| Ravi | 25000 |
| Sunil | 12000 |
| Tarak | 95000 |
| Name | Salary |
|---|---|
| Ravi | 25000 |
| Sunil | 12000 |
| Tarak | 95000 |
To find the maximum salary,
要查找最高工资,
SELECT MAX(Salary) from Employee; // To just get the max salary
SELECT MAX(Salary) from Employee; // 仅获取最高工资
SELECT * from Employee where Salary = (SELECT MAX(Salary) from Employee); // Employees with highest salary
SELECT * from Employee where Salary = (SELECT MAX(Salary) from Employee); // 工资最高的员工
To find the average salary,
要查找平均工资,
SELECT AVG(Salary) from Employee;
SELECT AVG(Salary) from Employee;
To find the minimum salary,
要查找最低工资,
SELECT MIN(Salary) from Employee; // To just get the min salary
SELECT MIN(Salary) from Employee; // 仅获取最低工资
SELECT * from Employee where Salary = (SELECT MIN(Salary) from Employee); // Employees with lowest salary
SELECT * from Employee where Salary = (SELECT MIN(Salary) from Employee); // 薪资最低的员工
Useful Interview Resources
有用的面试资源
- Free Mock Coding Interview
- DSA Tutorial
- Coding Interview Questions for Practice
- Technical Interview Questions for Practice
- Interview Preparation
233. Explain Normalization and De-Normalization.
解释规范化和反规范化。
- 知识点: 数据库 (标签: interviewbit, qualcomm, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 高通
- id: 69b37c2d58d557c902bb819c | 官方: 否 | 付费: 否
答案:
Databases must be normalized in order to structure them efficiently. It involves establishing tables and establishing connections between them based on certain rules. These rules may eliminate or reduce the amount of redundancy and dependency, making it more flexible. 1NF, 2NF, 3NF, BCNF, 4NF, and 5NF are 6 distinct normal forms. Normalization should be done to avoid data loss but not at the expense of integrity.
必须对数据库进行规范化,以便高效地构建其结构。它涉及建立表并根据某些规则建立表之间的连接。这些规则可以消除或减少冗余和依赖性,使其更加灵活。1NF、2NF、3NF、BCNF、4NF和5NF是6种不同的范式。应进行规范化以避免数据丢失,但不能以牺牲完整性为代价。
The procedure of denormalizing a schema is to convert it into one that has redundant information. Redundancy and keeping redundant data consistent are both beneficial. An over-normalised structure is inefficient in query processing because of its overheads.
反规范化模式的流程是将其转换为包含冗余信息的模式。冗余和保持冗余数据的一致性都是有益的。过度规范化的结构由于开销较大,在查询处理方面效率低下。
234. What is the default port for the MySQL server?
MySQL服务器的默认端口是什么?
- 知识点: 数据库 (标签: interviewbit, siemens, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Siemens
- id: 69b37c5158d557c902bc75e4 | 官方: 否 | 付费: 否
答案:
The MySQL client, MySQL Connectors, and utilities like mysqldump and mysqlpump all use port 3306 as the default port for the old MySQL protocol (port).
MySQL客户端、MySQL连接器以及mysqldump和mysqlpump等实用工具都使用端口3306作为旧MySQL协议(端口)的默认端口。
235. What is a constraint, and why use constraints?
什么是约束,以及为什么要使用约束?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bef | 官方: 否 | 付费: 否
答案:
SQL constraints are a set of rules applied to a column or table to maintain data integrity. SQL consists of many constraints, which are as follows:
SQL约束是应用于列或表的一组规则,以维护数据完整性。SQL包含许多约束,如下所示:
- DEFAULT: It sets a default value for a column.
- UNIQUE: It ensures all values are unique.
- NOT NULL: It prevents NULL values.
- PRIMARY KEY: It enables the unique identification of each record in a table. We can say that it combines NOT NULL and UNIQUE.
- FOREIGN KEY: Links records in two tables.
236. What is the COALESCE function?
什么是COALESCE函数?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bf2 | 官方: 否 | 付费: 否
答案:
The COALESCE function is used to take a set of input values and return the first non-null value from the record.
COALESCE函数用于接收一组输入值,并从记录中返回第一个非空值。
Syntax:
语法:
COALESCE(val1,val2,val3,……,nth val) copy
COALESCE(val1,val2,val3,……,nth val) 复制
237. What are UNION, MINUS, and INTERSECT in SQL?
SQL中的UNION、MINUS和INTERSECT是什么?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bf7 | 官方: 否 | 付费: 否
答案:
In SQL, UNION, MINUS, and INTERSECT are set operators used to combine or compare results from multiple SELECT queries:
在SQL中,UNION、MINUS和INTERSECT是集合运算符,用于合并或比较多个SELECT查询的结果:
UNION:
Combines the results of two SELECT statements and removes duplicate rows.合并两个SELECT语句的结果并删除重复行。
Use when you want to merge datasets without duplicates.
当你想合并数据集而不包含重复项时使用。MINUS:
Returns rows from the first SELECT that are not found in the second.返回第一个SELECT中存在但在第二个中不存在的行。
Used to identify differences between two datasets.
用于识别两个数据集之间的差异。INTERSECT:Returns only the rows that are common to both SELECT statements.
Use when you need data that appears in both datasets.当你需要两个数据集中都出现的数据时使用。
238. What is a view in SQL, and what are its types?
什么是 SQL 中的视图,它有哪些类型?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bfa | 官方: 否 | 付费: 否
答案:
A view is a virtual table representing data from one or more tables without physically storing it. It can simplify complex queries.
视图是一个虚拟表,表示来自一个或多个表的数据,而无需物理存储。它可以简化复杂查询。
There are four types of views in SQL:
SQL 中有四种类型的视图:
- Simple View: It is a view based on a single table and does not have a GROUP BY clause or other SQL features.
- Complex View: This is a view built from several tables and includes a GROUP BY clause as well as functions.
- Inline View: It is a view built on a subquery in the FROM clause, which provides a temporary table and simplifies a complicated query.
- Materialised View: This is a view that saves both the definition and the details. It builds data replicas by physically preserving them.
239. What do you understand about a temporary table? Write a query to create it.
你对临时表有什么了解?编写一个创建临时表的查询。
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bff | 官方: 否 | 付费: 否
答案:
A temporary table is a table that is created to store data temporarily during a session. It exists only while the session is active or until it is dropped manually.
临时表是一种在会话期间临时存储数据而创建的表。它只在会话活跃期间存在,直到手动删除。
It’s useful for storing intermediate results when working with complex queries or large data.
在处理复杂查询或大数据时,它对于存储中间结果非常有用。
Example:
示例:
-- Create a temporary table named 'TempEmployees'
-- 创建一个名为 'TempEmployees' 的临时表
CREATE TEMPORARY TABLE TempEmployees (
CREATE TEMPORARY TABLE TempEmployees (
-- Define a column 'ID' of integer type
-- 定义一个整数类型的列 'ID'
ID INT,
ID INT,
-- Define a column 'Name' that can store up to 50 characters
-- 定义一个最多可存储 50 个字符的列 'Name'
Name VARCHAR(50) );
Name VARCHAR(50) );
copy
copy
240. What are ACID properties?
什么是 ACID 属性?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c06 | 官方: 否 | 付费: 否
答案:
ACID stands for atomicity, consistency, isolation, and durability. These properties ensure the reliable processing of database transactions.
ACID 代表原子性、一致性、隔离性和持久性。这些属性确保数据库事务的可靠处理。
241. When will you use the DISTINCT keyword?
你什么时候会使用 DISTINCT 关键字?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c09 | 官方: 否 | 付费: 否
答案:
- DISTINCT is used to eliminate duplicate rows.
- SELECT COUNT (DISTINCT Table\_name). This can be used to count the unique records.
- However, using it multiple times can impact the table’s performance.
242. What do you mean by foreign key?
你所说的外键是什么意思?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c0c | 官方: 否 | 付费: 否
答案:
A foreign key is a table column or a set of columns in a relational database system that establishes a link between data in two tables. It is used to implement referential integrity by ensuring that the value in the foreign key column matches a primary key value in another table.
外键是关系数据库系统中一个表列或一组列,它建立两个表之间数据的链接。它通过确保外键列中的值与另一个表中的主键值匹配来实现引用完整性。
243. How will you prevent SQL injection?
你将如何防止 SQL 注入?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c0f | 官方: 否 | 付费: 否
答案:
SQL injection can be prevented very efficiently if we use parameterized queries or prepared statements instead of dynamic SQL, where we concatenate strings.
如果我们使用参数化查询或预编译语句而不是动态 SQL(即通过拼接字符串的方式),可以有效防止 SQL 注入。
So instead of writing:
所以不要写:
"SELECT * FROM users WHERE id = " + user_input; copy
"SELECT * FROM users WHERE id = " + user_input; copy
You should write:
而应该写:
"SELECT * FROM users WHERE id = %s" copy
"SELECT * FROM users WHERE id = %s" copy
Now, user input is only data, no matter how the code is executed. This method makes sure that even if the user decides to insert some illegal SQL commands, they will not be executed. Prepared statements are available in most SQL libraries of today, and they are regarded as the most suitable method for implementing application security against SQL injection attacks.
现在,用户输入只是数据,无论代码如何执行。这种方法确保即使你决定插入一些非法 SQL 命令,它们也不会被执行。当今的大多数 SQL 库都提供预编译语句,它们被认为是针对 SQL 注入攻击实现应用程序安全的最合适方法。
244. What is a function in SQL, and why do we use functions?
SQL 中的函数是什么,为什么我们要使用函数?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c12 | 官方: 否 | 付费: 否
答案:
A function is a database object that encapsulates a set of SQL statements that perform operations and return a specific result. SQL functions are used to increase the readability and reusability of code.
函数是封装一组执行操作并返回特定结果的 SQL 语句的数据库对象。SQL 函数用于提高代码的可读性和可重用性。
245. What is normalization? Explain its types.
什么是规范化?解释其类型。
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c15 | 官方: 否 | 付费: 否
答案:
Normalization is used to reduce data redundancy and improve data integrity. Normalization splits the big table into multiple subtables and ensures that database integrity constraints are intact in their relationship with each other. It is a process of decomposing tables to eliminate data redundancy.
规范化用于减少数据冗余并提高数据完整性。规范化将大表拆分为多个子表,并确保数据库完整性约束在其相互关系中保持完整。这是分解表以消除数据冗余的过程。
Types of normalization:
规范化的类型:
- 1NF: Ensures that each column contains only atomic (indivisible) values.
- 2NF: Remove partial dependencies.
- 3NF: Remove transitive dependencies.
- BCNF: Ensures that every determinant is a candidate key.
246. What is AUTO\_INCREMENT?
什么是AUTO_INCREMENT?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c18 | 官方: 否 | 付费: 否
答案:
AUTO\_INCREMENT is used in SQL to automatically generate a unique number whenever a new record is inserted into a table. This is mainly used in scenarios where individual columns or groups of columns cannot be used as primary keys.
AUTO_INCREMENT在SQL中用于在向表插入新记录时自动生成唯一数字。这主要用于无法将单个列或列组用作主键的场景。
For Example:
例如:
-- Create a table named 'Employee'
-- 创建一个名为'Employee'的表
CREATE TABLE Employee (
CREATE TABLE Employee (
-- Use AUTO_INCREMENT to automatically generate a unique ID for each new record
-- 使用AUTO_INCREMENT为每条新记录自动生成唯一ID
Employee_id INT NOT NULL AUTO_INCREMENT,
Employee_id INT NOT NULL AUTO_INCREMENT,
Employee_name VARCHAR(255) NOT NULL,
Employee_name VARCHAR(255) NOT NULL,
Employee_designation VARCHAR(255),
Employee_designation VARCHAR(255),
Age INT,
Age INT,
-- Set 'Employee_id' as the AUTO_INCREMENT Primary Key of the table
-- 将'Employee_id'设置为表的AUTO_INCREMENT主键
PRIMARY KEY (Employee_id) ); copy
PRIMARY KEY (Employee_id) ); copy
247. What are aggregate functions in SQL?
什么是 SQL 中的聚合函数?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c1c | 官方: 否 | 付费: 否
答案:
Aggregate functions in SQL carry out a computation over a collection of values and produce a single outcome. Typical instances encompass: - COUNT(): Returns the number of rows.
SQL中的聚合函数对一组值执行计算并产生单个结果。典型实例包括:- COUNT():返回行数。
- SUM(): Returns the total sum.
- AVG(): Returns the average value.
- MIN() / MAX(): Return the minimum or maximum value, respectively.
248. What are SQL dialects?
什么是SQL方言?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c1f | 官方: 否 | 付费: 否
答案:
SQL dialects are generally the variations of standard SQL syntax and features that are implemented by different database vendors. Examples include: - T-SQL for Microsoft SQL Server
SQL方言通常是不同数据库供应商实现的标准SQL语法和功能的变体。示例包括:- 用于Microsoft SQL Server的T-SQL
- PL/SQL for Oracle
- pgSQL for PostgreSQL
MySQL’s extended SQL
Though the main SQL syntax is still fairly the same, these dialects bring in proprietary functions, procedural abilities, and performance features that are designed specifically for particular systems.尽管主要SQL语法仍然基本相同,但这些方言引入了专有函数、过程能力和专为特定系统设计的性能特性。
249. What are the different types of SQL operators?
SQL 运算符有哪些不同类型?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c22 | 官方: 否 | 付费: 否
答案:
SQL supports several operator categories:
SQL 支持以下几种运算符类别:
Arithmetic Operators: +, -, \, / (perform calculations)
算术运算符:+、-、\、/(执行计算)
- Comparison Operators: =, , =, <> (used in WHERE clauses)
- Logical Operators: AND, OR, NOT (combine multiple conditions)
- Set Operators: UNION, INTERSECT, EXCEPT (combine result sets)
Understanding how to use these operators is crucial for writing efficient and readable SQL queries.
理解如何使用这些运算符对于编写高效且可读的 SQL 查询至关重要。
250. How to select all columns from a table?
如何从表中选择所有列?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c25 | 官方: 否 | 付费: 否
答案:
In SQL, to get all the columns from a table, you can use the wildcard character asterisk (*)
在 SQL 中,要获取表的所有列,可以使用通配符星号(*)
SELECT * FROM table_name; copy
SELECT * FROM table_name; copy
The above query retrieves all the columns of a table. Although it is a good practice during development, in production, it is advisable to explicitly mention the columns to be retrieved so as to increase performance and readability.
上述查询检索表的所有列。虽然在开发过程中这是良好的实践,但在生产环境中,建议明确指定要检索的列,以提高性能和可读性。
251. What are scalar functions in SQL?
SQL 中的标量函数是什么?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c28 | 官方: 否 | 付费: 否
答案:
Scalar functions in SQL are built-in functions that take one or more inputs and return a single value. Some of the common Scalar functions. - UPPER() / LOWER() – Converts text to uppercase or lowercase, respectively
SQL 中的标量函数是内置函数,它们接受一个或多个输入并返回单个值。一些常见的标量函数包括:- UPPER() / LOWER() – 分别将文本转换为大写或小写
- LEN() – Returns the number of characters in a string
- ROUND() – Rounds a numeric value to the specified number of decimal places
GETDATE() – Retrieves the current system date and time
These functions are useful for data formatting, transformation, and validation within SQL queries.这些函数在 SQL 查询中对于数据格式化、转换和验证非常有用。
252. What are indexed views?
什么是索引视图?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c2b | 官方: 否 | 付费: 否
答案:
An indexed view is a view in SQL that has a unique clustered index created on it, thus only the data of the view result is physically stored on the disk. In comparison to traditional views, indexed views improve performance by calculating the joins and aggregations before execution. Indexed views are most beneficial in SQL Server to improve performance in OLAP scenarios.
索引视图是一种 SQL 视图,在其上创建了唯一的聚集索引,因此视图结果的数据会被物理存储在磁盘上。与传统视图相比,索引视图通过在执行前计算连接和聚合来提高性能。索引视图在 SQL Server 中最有益于提高 OLAP 场景中的性能。
253. What are the different isolation levels in SQL?
SQL 中有哪些不同的隔离级别?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c2e | 官方: 否 | 付费: 否
答案:
SQL supports five isolation levels to handle concurrency in transactions:
SQL 支持五种隔离级别来处理事务中的并发:
- Read Uncommitted: Allows dirty reads.
- Read Committed: Default in most databases, and it avoids dirty reads.
- Repeatable Read: Prevents dirty and non-repeatable reads.
- Serializable: Highest isolation in order to prevent phantom reads.
- Snapshot: Maintains versioned data to avoid locking.
These levels balance between data consistency and performance in SQL
这些级别在 SQL 中平衡了数据一致性和性能
254. What is SQL Server Integration Services (SSIS)?
什么是 SQL Server Integration Services (SSIS)?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c31 | 官方: 否 | 付费: 否
答案:
SQL Server Integration Services (SSIS) is a platform developed by Microsoft to carry out ETL (Extract, Transform, Load) functions. It generally allows data migration, transformation, and workflow automation across various data sources. Typically, SSIS is very useful for building data warehouses, which makes it essential for Business Intelligence(BI) projects.
SQL Server Integration Services (SSIS) 是微软开发的一个平台,用于执行 ETL(提取、转换、加载)功能。它通常支持跨各种数据源的数据迁移、转换和工作流自动化。通常,SSIS 在构建数据仓库方面非常有用,这使得它对于商业智能(BI)项目至关重要。
255. What are the applications of SQL?
SQL 有哪些应用?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c34 | 官方: 否 | 付费: 否
答案:
SQL is a popular language in various sectors and career roles. Its most important applications are: - Handling and searching in relational databases
SQL 是一种在各种行业和职业角色中广泛使用的语言。其最重要的应用包括:- 处理和查询关系数据库
- Carrying out data analysis and generating reports
- Creating backend logic in apps
- Helping ETL pipelines in data warehousing
Maintaining data integrity and setting up access control
SQL flexibility turns it into a fundamental skill that data analysts, software developers, DBAs, and BI professionals all have in common.SQL 的灵活性使其成为数据分析师、软件开发人员、数据库管理员和 BI 专业人士都共有的基础技能。
256. What is DESC in SQL?
SQL 中的 DESC 是什么?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7c37 | 官方: 否 | 付费: 否
答案:
In SQL, DESC stands for descending. It is used to sort records in descending order, i.e., highest to lowest. It is usually clubbed with the ORDER BY clause to sort records. Here is an example of the same:
在 SQL 中,DESC 代表降序(descending)。它用于按降序排序记录,即从最高到最低。它通常与 ORDER BY 子句结合使用来排序记录。以下是一个示例:
SELECT * FROM employees ORDER BY salary DESC; copy
SELECT * FROM employees ORDER BY salary DESC; copy
257. What is a schema in SQL?
SQL 中的 schema 是什么?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c3a | 官方: 否 | 付费: 否
答案:
In SQL, a schema can be termed as a structure that groups tables, views, databases, and stored procedures. Using a schema prevents conflict and allows two names to exist in parallel, divided by the schema. Here is an example of the same:
在 SQL 中,schema 可以被称为一种结构,用于分组表、视图、数据库和存储过程。使用 schema 可以防止冲突,并允许两个名称通过 schema 划分而并行存在。以下是一个示例:
CREATE SCHEMA sales;
CREATE SCHEMA sales;
CREATE TABLE sales.orders (
CREATE TABLE sales.orders (
order_id INT,
order_id INT,
order_date DATE );
order_date DATE );
copy
copy
258. Can we rollback DELETE?
我们能回滚 DELETE 操作吗?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c3d | 官方: 否 | 付费: 否
答案:
Yes, after using the DELETE command, you can roll back if you are using the TRANSACTION command. DELETE is a DML command, so when you rollback, all the transactions are undone and the records are restored. Here is an example of the same:
是的,使用 DELETE 命令后,如果使用了 TRANSACTION 命令,您可以回滚。DELETE 是 DML 命令,因此当您回滚时,所有事务都会被撤销,记录会被恢复。以下是一个示例:
BEGIN TRANSACTION; -- Start a transaction
BEGIN TRANSACTION; -- 开始一个事务
DELETE FROM employees
DELETE FROM employees
WHERE employee_id = 101; -- This delete happens temporarily
WHERE employee_id = 101; -- 此删除会临时发生
ROLLBACK; -- Undo the delete
ROLLBACK; -- 撤销删除操作
copy
copy
259. Explain how CASE statements work in SQL.
解释 SQL 中 CASE 语句如何工作。
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c40 | 官方: 否 | 付费: 否
答案:
CASE provides if-then-else logic in SQL like this:
CASE 在 SQL 中提供了 if-then-else 逻辑,如下所示:
SELECT product_name, CASE
SELECT product_name, CASE
WHEN price > 100 THEN 'Premium'
WHEN price > 100 THEN 'Premium'
WHEN price > 50 THEN 'Standard'
WHEN price > 50 THEN 'Standard'
ELSE 'Budget' END AS tier FROM products copy
ELSE 'Budget' END AS tier FROM products copy
260. What is a pivot in SQL?
SQL 中的透视(PIVOT)是什么?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c43 | 官方: 否 | 付费: 否
答案:
The PIVOT command is used to summarise the data. It converts rows into columns, which helps in better analysis. Let’s understand this using an example:
PIVOT 命令用于汇总数据。它将行转换为列,有助于更好地分析。让我们通过一个示例来理解:
Input Data:
输入数据:
ProductYearSalesA2022100B2022150A2023200B2023250
ProductYearSalesA2022100B2022150A2023200B2023250
Question: Find the sales of Product A and Product B in 2022 and 2023
问题:查找2022年和2023年产品A和产品B的销售额
Output Data:
输出数据:
Productsales\_2022sales\_2023A100200B150250
产品销售额\_2022年销售额\_2023年A100200B150250
Query Used:
使用的查询:
SELECT
选择
product, [2022] AS sales_2022, [2023]
产品, [2022] AS sales_2022, [2023]
AS sales_2023 FROM
AS sales_2023 从
( SELECT product, year, sales FROM sales )
( 选择 产品, 年份, 销售额 从 销售 )
AS SourceTable PIVOT ( SUM(sales) FOR year IN ([2022], [2023]) )
AS SourceTable 透视 ( 求和 ( 销售额 ) 针对 年份 在 ([2022], [2023]) )
AS PivotTable; copy
AS PivotTable; 复制
261. What is a dynamic SQL query?
什么是动态SQL查询?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c4a | 官方: 否 | 付费: 否
答案:
A Dynamic SQL query is a technique in SQL wherein the query is built during runtime, giving dynamic inputs in the query. This makes the query flexible enough to create multiple use cases using the same query. Here is an example of the same:
动态SQL查询是SQL中的一种技术,其中查询在运行时构建,在查询中提供动态输入。这使得查询足够灵活,可以使用同一个查询创建多个用例。以下是相同的一个示例:
DECLARE @tableName NVARCHAR(50) = 'employees';
声明 @tableName NVARCHAR(50) = 'employees';
DECLARE @query NVARCHAR(MAX);
声明 @query NVARCHAR(MAX);
SET @query = 'SELECT * FROM ' + @tableName + '
设置 @query = '从 ' + @tableName + ' 中选择 *
WHERE department = ''HR'''; EXEC(@query); copy
其中 department = ''HR''';执行 (@query);复制
262. What is RDBMS? How is it different from a standard DBMS?
什么是RDBMS?它与标准DBMS有何不同?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c4d | 官方: 否 | 付费: 否
答案:
An RDBMS (Relational Database Management System) stores data in structured tables with rows and columns and maintains relationships using keys, whereas a DBMS stores data without enforcing relationships. - RDBMS supports primary keys, foreign keys, and normalization
RDBMS(关系数据库管理系统)将数据存储在具有行和列的规范化表格中,并通过键维护关系,而DBMS存储数据时不强制关系。- RDBMS支持主键、外键和规范化
- DBMS does not enforce relationships between data
- RDBMS ensures better data integrity and consistency
RDBMS supports multi-user access efficiently
Examples of RDBMS include MySQL, PostgreSQL, and Oracle.RDBMS的示例包括MySQL、PostgreSQL和Oracle。
263. What is an Alias in SQL?
SQL中的别名是什么?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c50 | 官方: 否 | 付费: 否
答案:
An Alias in SQL is a temporary name assigned to a table or column to make SQL queries more readable and easier to understand. - Improves query readability
SQL中的别名是为表或列分配的临时名称,使SQL查询更易读且更易于理解。- 提高查询可读性
- Helps simplify complex column names
- Useful in joins and calculated columns
Exists only during query execution
Aliases do not change the actual table or column names in the database.别名不会更改数据库中实际的表名或列名。
264. What is the order of execution in an SQL query?
SQL查询中的执行顺序是什么?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c53 | 官方: 否 | 付费: 否
答案:
The order of execution in SQL defines how a query is processed internally by the database engine, which is different from how the query is written.
SQL中的执行顺序定义了数据库引擎内部如何处理查询,这与查询的编写方式不同。
- FROM – Identifies the source tables
- WHERE – Filters rows
- GROUP BY – Groups rows
- HAVING – Filters grouped data
- SELECT – Selects columns
- ORDER BY – Sorts the final result
Understanding this order helps write correct and optimized SQL queries.
理解这一顺序有助于编写正确且优化的SQL查询。
265. What is the NULL value? Is it the same as zero or a blank space?
什么是NULL值?它与零或空格相同吗?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c56 | 官方: 否 | 付费: 否
答案:
A NULL value represents the absence of data and is not the same as zero or a blank space. - NULL means unknown or missing value
NULL值表示数据的缺失,与零或空格不同。- NULL表示未知或缺失的值
- Zero (0) is a numeric value
- Blank space ("") is an empty string
NULL cannot be compared using = and requires IS NULL
NULL behaves differently in calculations and comparisons and does not represent any actual value.NULL在计算和比较中表现不同,不表示任何实际值。
266. What are joins in SQL?
SQL中的连接是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-joins, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ebe | 官方: 否 | 付费: 否
答案:
A join clause is a SQL command used to combine records from multiple tables or retrieve data from these tables based on the existence of a common field (column) between them. A join condition and SELECT statement can be used to join the tables. Using the SQL JOIN clause, records can be fetched from two or more tables in a database and combined. In general, they are used when users need to retrieve data from tables that contain many-to-many or one-to-many relationships between them.
连接子句是一种SQL命令,用于合并多个表中的记录,或基于它们之间公共字段(列)的存在来检索这些表中的数据。可以使用连接条件和SELECT语句来连接表。使用SQL JOIN子句,可以从数据库中两个或多个表中获取并合并记录。通常,当用户需要从包含多对多或一对多关系的表中检索数据时,会使用它们。
Example: Let's take a look at two tables. Here’s the Employee table.
示例:让我们看一下两个表。这里是员工表。
| Emp_ID | Emp_Name | Emp_No |
|---|---|---|
| 101 | Ashish Kaktan | 9450425345 |
| 102 | Raj Choudhary | 8462309621 |
| 103 | Vivek Oberoi | 7512309034 |
| 104 | Shantanu Khandelwal | 9020330023 |
| 105 | Khanak Desai | 8451004522 |
| Emp_ID | Emp_Name | Emp_No |
|---|---|---|
| 101 | Ashish Kaktan | 9450425345 |
| 102 | Raj Choudhary | 8462309621 |
| 103 | Vivek Oberoi | 7512309034 |
| 104 | Shantanu Khandelwal | 9020330023 |
| 105 | Khanak Desai | 8451004522 |
Here's the Employment table.
这是Employment表。
| Emp_ID | Emp_Profile | Emp_Country | Emp_Join_Date |
|---|---|---|---|
| 101 | Content Writer | Germany | 2021-04-20 |
| 104 | Data Analyst | India | 2022-12-11 |
| 105 | Software Engineer | India | 2022-01-03 |
| 108 | Development Executive | Europe | 2023-02-15 |
| 109 | Marketing Manager | Mexico | 2020-05-23 |
| Emp_ID | Emp_Profile | Emp_Country | Emp_Join_Date |
|---|---|---|---|
| 101 | Content Writer | Germany | 2021-04-20 |
| 104 | Data Analyst | India | 2022-12-11 |
| 105 | Software Engineer | India | 2022-01-03 |
| 108 | Development Executive | Europe | 2023-02-15 |
| 109 | Marketing Manager | Mexico | 2020-05-23 |
Let us now join these two tables together using a SELECT statement, as shown below.
现在让我们使用 SELECT 语句将这两个表连接在一起,如下所示。
SELECT Emp_ID, Emp_Name, Emp_No, Emp_Profile, Emp_Country FROM Employee, Employment WHERE Employee.Emp_ID = Employment.Emp_ID;
SELECT Emp_ID, Emp_Name, Emp_No, Emp_Profile, Emp_Country FROM Employee, Employment WHERE Employee.Emp_ID = Employment.Emp_ID;
Output:
输出:
| Emp_ID | Emp_Name | Emp_No | Emp_Profile | Emp_Country |
|---|---|---|---|---|
| 101 | Ashish Kaktan | 9450425345 | Content Writer | Germany |
| 104 | Shantanu Khandelwal | 9020330023 | Data Analyst | India |
| 105 | Khanak Desai | 8451004522 | Software Engineer | India |
| Emp_ID | Emp_Name | Emp_No | Emp_Profile | Emp_Country |
|---|---|---|---|---|
| 101 | Ashish Kaktan | 9450425345 | Content Writer | Germany |
| 104 | Shantanu Khandelwal | 9020330023 | Data Analyst | India |
| 105 | Khanak Desai | 8451004522 | Software Engineer | India |
267. What is the importance of SQL joins in database management?
SQL 连接在数据库管理中的重要性是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-joins, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ec1 | 官方: 否 | 付费: 否
答案:
SQL joins are important in database management for the following reasons: - A method of stitching a database back together to make it easier to read and use.
SQL 连接在数据库管理中的重要性体现在以下几点:- 一种将数据库重新拼接起来的方法,使其更易于阅读和使用。
- Additionally, they maintain a normalized database. Data normalization helps us keep data redundancy low so that when we delete or update a record, we will have fewer data anomalies in our application.
- Joins have the advantage of being faster, and as a result, are more efficient.
- It is almost always faster to retrieve the data using a join query rather than one that uses a subquery.
- By utilizing joins, it is possible to reduce the workload on the database. For example, instead of multiple queries, you can use one join query. So, you can better utilize the database's ability to search, filter, sort, etc.
268. Explain merge join in SQL.
解释 SQL 中的合并连接。
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-joins, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ec9 | 官方: 否 | 付费: 否
答案:
Merge join produces a single output stream resulting from the joining of two sorted datasets using an INNER, FULL, or LEFT join. It is the most effective of all the operators for joining data. Specifically, merge join requires that both inputs be sorted as well as matching meta-data in the joined columns. Users can't join columns of different data types together. Users are not permitted to combine a column with a numeric data type with a column with a character data type.
合并连接通过使用 INNER、FULL 或 LEFT 连接将两个已排序的数据集合并在一起,产生一个单一的输出流。它是所有连接数据操作符中最有效的。具体来说,合并连接要求两个输入都已排序,并且连接列中的元数据匹配。用户不能将不同数据类型的列连接在一起。用户不允许将具有数值数据类型的列与具有字符数据类型的列合并。
269. State the difference between inner join and left join.
说明内连接和左连接之间的区别。
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-joins, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ecf | 官方: 否 | 付费: 否
答案:
- Inner Join: This join generates datasets that contain matching records in both tables (left and right). By using an inner join, only the rows that match between each of the tables are returned; all non-matching rows are removed.
Example: Let's take a look at two tables. Here’s the Tb1_Employee table.
示例:让我们看看两个表格。这里是 Tb1_Employee 表。
| Emp_ID | Emp_Name | Emp_No |
| 101 | Ashish Kaktan | 9450425345 |
| 102 | Raj Choudhary | 8462309621 |
| 103 | Vivek Oberoi | 7512309034 |
| 104 | Shantanu Khandelwal | 9020330023 |
| 105 | Khanak Desai | 8451004522 |
| Emp_ID | Emp_Name | Emp_No |
|---|---|---|
| 101 | Ashish Kaktan | 9450425345 |
| 102 | Raj Choudhary | 8462309621 |
| 103 | Vivek Oberoi | 7512309034 |
| 104 | Shantanu Khandelwal | 9020330023 |
| 105 | Khanak Desai | 8451004522 |
Here's the Tb2_Employment table.
这里是 Tb2_Employment 表。
| Emp_ID | Emp_Profile | Emp_Country | Emp_Join_Date |
|---|---|---|---|
| 101 | Content Writer | Germany | 2021-04-20 |
| 104 | Data Analyst | India | 2022-12-11 |
| 105 | Software Engineer | India | 2022-01-03 |
| 108 | Development Executive | Europe | 2023-02-15 |
| 109 | Marketing Manager | Mexico | 2020-05-23 |
| Emp_ID | Emp_Profile | Emp_Country | Emp_Join_Date |
|---|---|---|---|
| 101 | Content Writer | Germany | 2021-04-20 |
| 104 | Data Analyst | India | 2022-12-11 |
| 105 | Software Engineer | India | 2022-01-03 |
| 108 | Development Executive | Europe | 2023-02-15 |
| 109 | Marketing Manager | Mexico | 2020-05-23 |
Let’s perform INNER JOIN on these two tables using a SELECT statement, as shown below:
让我们使用 SELECT 语句对这两个表执行 INNER JOIN,如下所示:
SELECT Emp_Name, Emp_No, Emp_Profile, Emp_Country, Emp_Join_Date
SELECT Emp_Name, Emp_No, Emp_Profile, Emp_Country, Emp_Join_Date
FROM Tb1_Employee INNER JOIN Tb2_Employment
FROM Tb1_Employee INNER JOIN Tb2_Employment
ON Tb1_Employee.Emp_ID=Tb2_Employment.Emp_ID;
ON Tb1_Employee.Emp_ID=Tb2_Employment.Emp_ID;
Output:
输出:
| Emp_Name | Emp_No | Emp_Profile | Emp_Country | Emp_Join_Date |
|---|---|---|---|---|
| Ashish Kaktan | 9450425345 | Content Writer | Germany | 2021-04-20 |
| Shantanu Khandelwal | 9020330023 | Data Analyst | India | 2022-12-11 |
| Khanak Desai | 8451004522 | Software Engineer | India | 2022-01-03 |
| - Left Join: It returns datasets that have matching records in both tables (left and right) plus non-matching rows from the left table. By using a left join, all the records in the left table plus the matching records in the right table are returned. - 左连接:它返回两个表(左表和右表)中具有匹配记录的数据集,再加上左表中不匹配的行。通过使用左连接,左表中的所有记录以及右表中匹配的记录都会被返回。 |
Example: Let’s now perform LEFT JOIN on these two tables using a SELECT statement, as shown below:
示例:现在让我们对这两个表使用 SELECT 语句执行左连接,如下所示:
SELECT Tb1_Employee.Emp_Name, Tb1_Employee.Emp_No, Tb2_Employment.Emp_Profile, Tb2_Employment.Emp_Country
SELECT Tb1_Employee.Emp_Name, Tb1_Employee.Emp_No, Tb2_Employment.Emp_Profile, Tb2_Employment.Emp_Country
FROM Tb1_Employee LEFT JOIN Tb2_Employment
FROM Tb1_Employee LEFT JOIN Tb2_Employment
ON Tb1_Employee.Emp_ID=Tb2_Employment.Emp_ID;
ON Tb1_Employee.Emp_ID=Tb2_Employment.Emp_ID;
Output:
输出:
| Emp_Name | Emp_No | Emp_Profile | Emp_Country |
|---|---|---|---|
| Ashish Kaktan | 9450425345 | Content Writer | Germany |
| Raj Choudhary | 8462309621 | Null | Null |
| Vivek Oberoi | 7512309034 | Null | Null |
| Shantanu Khandelwal | 9020330023 | Data Analyst | India |
| Khanak Desai | 8451004522 | Software Engineer | India |
| Emp_Name | Emp_No | Emp_Profile | Emp_Country |
|---|---|---|---|
| Ashish Kaktan | 9450425345 | Content Writer | Germany |
| Raj Choudhary | 8462309621 | Null | Null |
| Vivek Oberoi | 7512309034 | Null | Null |
| Shantanu Khandelwal | 9020330023 | Data Analyst | India |
| Khanak Desai | 8451004522 | Software Engineer | India |
- Data Science
- All Events
- My Events
270. State difference between left join and right join.
说明左连接和右连接之间的区别。
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-joins, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ed2 | 官方: 否 | 付费: 否
答案:
- Left Join: It returns datasets that have matching records in both tables (left and right) plus non-matching rows from the left table. By using a left join, all the records in the left table plus the matching records in the right table are returned.
Example: Let's take a look at two tables. Here’s the Tb1_Employee table.
示例:让我们看看两个表格。这里是 Tb1_Employee 表。
| Emp_ID | Emp_Name | Emp_No |
|---|---|---|
| 101 | Ashish Kaktan | 9450425345 |
| 102 | Raj Choudhary | 8462309621 |
| 103 | Vivek Oberoi | 7512309034 |
| 104 | Shantanu Khandelwal | 9020330023 |
| 105 | Khanak Desai | 8451004522 |
| Emp_ID | Emp_Name | Emp_No |
|---|---|---|
| 101 | Ashish Kaktan | 9450425345 |
| 102 | Raj Choudhary | 8462309621 |
| 103 | Vivek Oberoi | 7512309034 |
| 104 | Shantanu Khandelwal | 9020330023 |
| 105 | Khanak Desai | 8451004522 |
Here's the Tb2_Employment table.
这里是 Tb2_Employment 表。
| Emp_ID | Emp_Profile | Emp_Country | Emp_Join_Date |
|---|---|---|---|
| 101 | Content Writer | Germany | 2021-04-20 |
| 104 | Data Analyst | India | 2022-12-11 |
| 105 | Software Engineer | India | 2022-01-03 |
| 108 | Development Executive | Europe | 2023-02-15 |
| 109 | Marketing Manager | Mexico | 2020-05-23 |
| Emp_ID | Emp_Profile | Emp_Country | Emp_Join_Date |
|---|---|---|---|
| 101 | Content Writer | Germany | 2021-04-20 |
| 104 | Data Analyst | India | 2022-12-11 |
| 105 | Software Engineer | India | 2022-01-03 |
| 108 | Development Executive | Europe | 2023-02-15 |
| 109 | Marketing Manager | Mexico | 2020-05-23 |
Let’s now perform LEFT JOIN on these two tables using a SELECT statement, as shown below:
现在让我们使用 SELECT 语句对这两个表执行左连接,如下所示:
SELECT Tb1_Employee.Emp_Name, Tb1_Employee.Emp_No, Tb2_Employment.Emp_Profile, Tb2_Employment.Emp_Join_Date
SELECT Tb1_Employee.Emp_Name, Tb1_Employee.Emp_No, Tb2_Employment.Emp_Profile, Tb2_Employment.Emp_Join_Date
FROM Tb1_Employee LEFT JOIN Tb2_Employment
FROM Tb1_Employee LEFT JOIN Tb2_Employment
ON Tb1_Employee.Emp_ID=Tb2_Employment.Emp_ID;
ON Tb1_Employee.Emp_ID=Tb2_Employment.Emp_ID;
Output:
输出:
| Emp_Name 员工姓名 | Emp_No 员工编号 | Emp_Profile 员工职位 | Emp_Join_Date 入职日期 |
|---|---|---|---|
| Ashish Kaktan | 9450425345 | Content Writer 内容撰写人 | 2021-04-20 |
| Raj Choudhary | 8462309621 | Null | Null |
| Vivek Oberoi | 7512309034 | Null | Null |
| Shantanu Khandelwal | 9020330023 | Data Analyst 数据分析师 | 2023-02-15 |
| Khanak Desai | 8451004522 | Software Engineer 软件工程师 | 2020-05-23 |
| - Right Join: It returns datasets that have matching records in both tables (left and right) plus non-matching rows from the right table. By using a left join, all the records in the right table plus the matching records in the left table are returned. - 右连接:它返回两个表(左表和右表)中匹配的记录以及右表中不匹配的行。通过使用左连接,返回右表中的所有记录以及左表中匹配的记录。 |
Example: Let’s now perform RIGHT JOIN on these two tables using a SELECT statement, as shown below:
示例:现在让我们使用SELECT语句在这两个表上执行RIGHT JOIN,如下所示:
SELECT Tb1_Employee.Emp_Name, Tb1_Employee.Emp_No, Tb2_Employment.Emp_Profile, Tb2_Employment.Emp_Join_Date
SELECT Tb1_Employee.Emp_Name, Tb1_Employee.Emp_No, Tb2_Employment.Emp_Profile, Tb2_Employment.Emp_Join_Date
FROM Tb1_Employee RIGHT JOIN Tb2_Employment
FROM Tb1_Employee RIGHT JOIN Tb2_Employment
ON Tb1_Employee.Emp_ID=Tb2_Employment.Emp_ID;
ON Tb1_Employee.Emp_ID=Tb2_Employment.Emp_ID;
Output:
输出:
| Emp_Name 员工姓名 | Emp_No 员工编号 | Emp_Profile 员工职位 | Emp_Join_Date 入职日期 |
|---|---|---|---|
| Ashish Kaktan | 9450425345 | Content Writer 内容撰写人 | 2021-04-20 |
| Shantanu Khandelwal | 9020330023 | Data Analyst 数据分析师 | 2022-12-11 |
| Khanak Desai | 8451004522 | Software Engineer 软件工程师 | 2022-01-03 |
| Null | Null | Development Executive 发展主管 | 2023-02-15 |
| Null | Null | Marketing Manager 市场营销经理 | 2020-05-23 |
271. What is a hash join in SQL?
SQL中的哈希连接是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-joins, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ed5 | 官方: 否 | 付费: 否
答案:
Just like any other join, the hash join requires two inputs, which are the probe input (inner table) and the build input (outer table). A hash join involves the use of a hash table to identify rows matching between two tables. The hash join is the option when no other join is preferred (possibly due to the absence of sorting or indexing etc). Hash joins are best when joining large data sets that are unsorted and non-indexed.
与其他任何连接一样,哈希连接需要两个输入,即探测输入(内部表)和构建输入(外部表)。哈希连接涉及使用哈希表来识别两个表之间匹配的行。当没有其他连接可选(可能是因为缺少排序或索引等)时,哈希连接是选项。哈希连接最适合连接大型且未排序且未索引的数据集。
272. Write an SQL query to join three tables.
编写一个SQL查询来连接三个表。
- 知识点: 数据库 / 行为与软技能 (主题: sql, database;标签: interviewbit, sql-joins, topic-specific, sql, database)
- 类型: behavioral | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7edd | 官方: 否 | 付费: 否
答案:
At times, you might need to retrieve data from three or more tables at once. A multi-table join requires consecutive JOIN operations: the first and second tables are joined to form a virtual table and then the third table is joined to this virtual table. Let's take a look at three tables.
有时,您可能需要一次从三个或更多表中检索数据。多表连接需要连续的JOIN操作:第一和第二个表连接形成一个虚拟表,然后第三个表与该虚拟表连接。让我们看看三个表。
Here’s the Employee table.
这是Employee表。
| Emp_ID | Emp_Name | Emp_No |
|---|---|---|
| 101 | Ashish Kaktan | 9450425345 |
| 102 | Raj Choudhary | 8462309621 |
| 103 | Vivek Oberoi | 7512309034 |
| 104 | Shantanu Khandelwal | 9020330023 |
| 105 | Khanak Desai | 8451004522 |
| Emp_ID | Emp_Name | Emp_No |
|---|---|---|
| 101 | Ashish Kaktan | 9450425345 |
| 102 | Raj Choudhary | 8462309621 |
| 103 | Vivek Oberoi | 7512309034 |
| 104 | Shantanu Khandelwal | 9020330023 |
| 105 | Khanak Desai | 8451004522 |
Here's the Employment table.
这是Employment表。
| Emp_ID | Emp_Profile | Emp_Email |
|---|---|---|
| 101 | Content Writer 内容撰写人 | ashish@scaler.com |
| 104 | Data Analyst 数据分析师 | shantanu@scaler.com |
| 105 | Software Engineer 软件工程师 | khanak@scaler.com |
| 109 | Development Executive 发展主管 | akshay@scaler.com |
| 108 | Marketing Manager 市场营销经理 | nikita@scaler.com |
Here’s the EmpDetail.
这是EmpDetail表。
| Emp_Country | Emp_Email | Emp_JoinDate |
|---|---|---|
| Germany | ashish@scaler.com | 2021-04-20 |
| India | shantanu@scaler.com | 2022-12-11 |
| India | khanak@scaler.com | 2022-01-03 |
| Europe | akshay@scaler.com | 2023-02-15 |
| Mexico | nikita@scaler.com | 2020-05-23 |
| Emp_Country | Emp_Email | Emp_JoinDate |
|---|---|---|
| Germany | ashish@scaler.com | 2021-04-20 |
| India | shantanu@scaler.com | 2022-12-11 |
| India | khanak@scaler.com | 2022-01-03 |
| Europe | akshay@scaler.com | 2023-02-15 |
| Mexico | nikita@scaler.com | 2020-05-23 |
SELECT Emp_Name, Emp_No, Emp_Profile, Emp_Country, EmpJoinDate,
选择 Emp_Name、Emp_No、Emp_Profile、Emp_Country、EmpJoinDate,
FROM Employee e INNER JOIN Employment m ON
从 Employee 表 e 内连接 Employment 表 m,条件为
e.Emp_ID = m.EMP_ID INNER JOIN EmpDetail d on
e.Emp_ID = m.EMP_ID,并内连接 EmpDetail 表 d,条件为
d.Emp_Email = m.Emp_Email;
d.Emp_Email = m.Emp_Email;
Output:
输出:
| Emp_Name | Emp_No | Emp_Profile | Emp_Country | Emp_JoinDate |
|---|---|---|---|---|
| 101 | 9450425345 | Content Writer 内容写手 | Germany 德国 | 2021-04-20 |
| 104 | 9020330023 | Data Analyst 数据分析师 | India 印度 | 2022-12-11 |
| 105 | 8451004522 | Software Engineer 软件工程师 | India 印度 | 2022-01-03 |
273. How can you join a table to itself?
如何将一个表与自身连接?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-joins, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ee0 | 官方: 否 | 付费: 否
答案:
Another type of join in SQL is a SELF JOIN, which connects a table to itself. In order to perform a self-join, it is necessary to have at least one column (say X) that serves as the primary key as well as one column (say Y) that contains values that can be matched with those in X. The value of Column Y may be null in some rows, and Column X need not have the exact same value as Column Y for every row.
SQL 中的另一种连接类型是自连接(SELF JOIN),它将一个表与自身连接起来。为了执行自连接,必须至少有一列(例如 X)作为主键,并且至少有一列(例如 Y)包含可以与 X 中的值匹配的值。在某些行中,Y 列的值可能为 NULL,而 X 列不需要在每一行都与 Y 列具有完全相同的值。
Example: Consider the table Employees.
示例:考虑 Employees 表。
| Emp_ID | Emp_Name | Emp_Profile | Emp_Country | ManagerId |
|---|---|---|---|---|
| 101 | Ashish Kaktan | Content Writer 内容写手 | Germany 德国 | 104 |
| 104 | Raj Choudhary | Data Analyst 数据分析师 | India 印度 | 108 |
| 105 | Vivek Oberoi | Software Engineer 软件工程师 | India 印度 | 101 |
| 108 | Shantanu Khandelwal | Development Executive 开发主管 | Europe 欧洲 | 101 |
| 109 | Khanak Desai | Marketing Manager 市场营销经理 | Mexico 墨西哥 |
For instance, we might wish to display results that only include employees with their managers. By using table aliases and a self-join, this can be accomplished easily.
例如,我们可能希望只显示包含员工及其经理的结果。通过使用表别名和自连接,可以轻松实现这一点。
SELECT e.Emp_ID, e.Emp_Name, m.FullName as ManagerName
选择 e.Emp_ID、e.Emp_Name、m.FullName 作为 ManagerName
FROM Employees e JOIN Employees m ON e.ManagerId = m.Emp_ID
从 Employees 表 e 连接 Employees 表 m,条件为 e.ManagerId = m.Emp_ID
Output:
输出:
| Emp_ID | Emp_Name | ManagerName |
|---|---|---|
| 101 | Ashish Kaktan | Raj Choudhary |
| 104 | Raj Choudhary | Shantanu Khandelwal |
| 105 | Vivek Oberoi | Ashish Kaktan |
| 108 | Shantanu Khandelwal | Ashish Kaktan |
| 109 | Khanak Desai | Null |
| Emp_ID | Emp_Name | ManagerName |
|---|---|---|
| 101 | Ashish Kaktan | Raj Choudhary |
| 104 | Raj Choudhary | Shantanu Khandelwal |
| 105 | Vivek Oberoi | Ashish Kaktan |
| 108 | Shantanu Khandelwal | Ashish Kaktan |
| 109 | Khanak Desai | Null |
274. What is Query in SQL?
SQL 中的查询是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-query, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c6058d557c902bc7f06 | 官方: 否 | 付费: 否
答案:
A query is a request for information or data from a database table or set of tables. For example, let us assume that we have a database that stores details about books written by various authors. Now, if we want to know how many books have been written by a particular author, then this question can be referred to as a query that we want to do to the database.
查询是对数据库表或一组表的信息或数据的请求。例如,假设我们有一个数据库,其中存储了由不同作者撰写的书籍的详细信息。现在,如果我们想知道某位特定作者写了多少本书,那么这个问题可以被视为我们想对数据库执行的查询。
Use cases of SQL: - SQL is an interactive question language. Users write SQL commands into interactive SQL software to extract information and display them on the screen, making it a useful and simple tool for ad hoc database queries.
SQL 的使用场景:- SQL 是一种交互式查询语言。用户将 SQL 命令输入到交互式 SQL 软件中以提取信息并在屏幕上显示,使其成为临时数据库查询的有用且简单的工具。
- SQL is a database programming language. To access the information in a database, programmers incorporate SQL instructions into their utility packages. This method of database access is used by both user-written packages and database software packages
- SQL is a server/client language. SQL allows personal computer programs to interface with database servers that store shared data through a network. Many well-known enterprise-class apps use this client/server design.
- SQL is a distributed database language. SQL is used in distributed database control systems to help spread data across numerous linked computer structures. Every device's DBMS software program uses SQL to communicate with other systems, issuing requests for information access. Learn More
275. Let us consider the following schema:
让我们考虑以下模式:
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-query, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c6058d557c902bc7f09 | 官方: 否 | 付费: 否
答案:
Table: Person
表:Person
| Column Name
列名 | Type
类型 |
| id | int |
| varchar |
Here, id is the primary key column for this table. Email represents the email id of the person. For the sake of simplicity, we assume that the emails will not contain uppercase letters. Write an SQL query to report all the duplicate emails. You can return the result table in any order.
这里,id 是此表的主键列。email 表示该人的电子邮件 ID。为简单起见,我们假设电子邮件不会包含大写字母。编写一个 SQL 查询来报告所有重复的电子邮件。你可以按任意顺序返回结果表。
Example:
示例:
Input: Person table:
输入:Person 表:
| id | email |
| 1 | a@gmail.com |
| 2 | c@yahoo.com |
| 3 | a@gmail.com |
| id | |
|---|---|
| 1 | a@gmail.com |
| 2 | c@yahoo.com |
| 3 | a@gmail.com |
Output:
输出:
| Email |
| a@gmail.com |
| a@gmail.com |
Explanation: a@gmail.com is repeated two times.
解释:a@gmail.com 重复了两次。
- Approach 1:
We can first have all the distinct email ids and their respective counts in our result set. For this, we can use the GROUP BY operator to group the tuples by their email id. We will use the COUNT operator to have the total number of a particular email id in the given table. The query for obtaining this resultant set can be written as:
我们可以在结果集中首先获取所有不同的电子邮件 ID 及其各自的计数。为此,我们可以使用 GROUP BY 运算符按电子邮件 ID 对元组进行分组。我们将使用 COUNT 运算符来获取给定表中特定电子邮件 ID 的总数。用于获取此结果集的查询可以写为:
select email, count(email) as email_count
select email, count(email) as email_count
from Person
from Person
group by email;
group by email;
Now, we query in the above resultant query set to find out all the tuples which have an email id count greater than 1. This can be achieved using the following query:
现在,我们在上述结果查询集中查询以找出所有电子邮件 ID 计数大于 1 的元组。这可以使用以下查询来实现:
select email from
select email from
(
select email, count(email) as email_count
select email, count(email) as email_count
from Person
from Person
group by email
group by email
)
where email_count > 1;
where email_count > 1;
- Approach 2:
The HAVING clause, which is significantly simpler and more efficient, is a more popular technique to add a condition to a GROUP BY. So, we can first group the tuples by the email ids and then have a condition to check if their count is greater than 1, only then do we include it in our result set. So we may change the solution above to this one.
使用 HAVING 子句(它明显更简单且更高效)是一种更流行的为 GROUP BY 添加条件的技术。因此,我们可以先将元组按 email id 分组,然后添加一个条件来检查它们的计数是否大于 1,只有当满足该条件时才将其包含在结果集中。所以我们可以将上面的解决方案改为下面这个。
select email
select email
from Person
from Person
group by email
group by email
having count(email) > 1;
having count(email) > 1;
- Approach 3:
We can use the concept of joins to solve this problem. We will self-join the Person table with the condition that their email ids should be the same and their ids should be different. Having done this, we just need to count the number of tuples in our resultant set with distinct email ids. For this, we use the DISTINCT operator. This can be achieved using the following query:
我们可以使用连接的概念来解决这个问题。我们将 Person 表进行自连接,条件是它们的 email id 应相同且它们的 id 应不同。完成此操作后,我们只需统计结果集中具有不同 email id 的元组数量。为此,我们使用 DISTINCT 运算符。这可以通过以下查询来实现:
SELECT DISTINCT p1.email
SELECT DISTINCT p1.email
FROM Person p1, Person p2
FROM Person p1, Person p2
WHERE p1.email = p2.email and p1.id != p2.id;
WHERE p1.email = p2.email and p1.id != p2.id;
276. Given the following schema:
给定以下模式:
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-query, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c6058d557c902bc7f15 | 官方: 否 | 付费: 否
答案:
Table: Customers
表:Customers
| Column Name | Type |
| id | int |
| name | varchar |
| Column Name | Type |
|---|---|
| id | int |
| name | varchar |
The primary key column for this table is id. Each row in the table represents a customer's ID and name.
该表的主键列是 id。表中的每一行代表一个客户的 ID 和姓名。
Table: Orders
表:Orders
| Column Name
列名 | Type
类型 |
| id | int |
| customerId | int |
The primary key column for this table is id. customerId is a foreign key of the ID from the Customers table. The ID of an order and the ID of the customer who placed it are listed in each row of this table. Write an SQL query to report all customers who never order anything. You can return the result table in any order.
此表的主键列是 id。customerId 是 Customers 表中 ID 的外键。此表的每一行都列出了一个订单的 ID 和下订单的客户的 ID。编写一个 SQL 查询,用于报告所有从未订购任何东西的客户。您可以按任何顺序返回结果表。
Example:
示例:
Input: Customers table:
输入:Customers 表:
| id | name |
| 1 | Ram |
| 2 | Sachin |
| 3 | Rajat |
| 4 | Ankit |
| id | name |
|---|---|
| 1 | Ram |
| 2 | Sachin |
| 3 | Rajat |
| 4 | Ankit |
Orders table:
Orders 表:
| id | customeId |
| 1 | 2 |
| 2 | 1 |
| id | customeId |
|---|---|
| 1 | 2 |
| 2 | 1 |
Output
输出
| Customers |
| Rajat |
| Ankit |
| Customers |
|---|
| Rajat |
| Ankit |
Explanation: Here, the customers Sachin and Ram have placed an order having order id 1 and 2 respectively. Thus, the customers Rajat and Ankit have never placed an order. So, we print their names in the result set. - Approach 1:
解释:此处,客户 Sachin 和 Ram 分别下过订单,订单 ID 为 1 和 2。因此,客户 Rajat 和 Ankit 从未下过订单。所以,我们在结果集中输出他们的名字。- 方法 1:
In this approach, we first try to find the customers who have ordered at least once. After having found this, we find the customers whose customer Id is not present in the previously obtained result set. This gives us the customers who have not placed a single order yet. The SQL query for it can be written as follows
在这种方法中,我们首先尝试找到至少下过一次订单的客户。找到这些客户后,我们再找出其客户 ID 不在先前得到的结果集中的客户。这样就得到了尚未下过任何订单的客户。相应的 SQL 查询可以写成如下形式
select customers.name as 'Customers'
select customers.name as 'Customers'
from customers
from customers
where customers.id not in
where customers.id not in
(
select customerid from orders
select customerid from orders
);
- Approach 2:
In this approach, we use the concept of JOIN. We will LEFT JOIN the customer table with the order table based on the condition that id of the customer table must be equal to that of the customer id of the order table. Now, in our joined resultant table, we just need to find those customers whose order id is null. The SQL query for this can be written as follows:
在这种方法中,我们使用 JOIN 的概念。我们基于客户表的 id 必须等于订单表的 customer id 这一条件,将客户表与订单表进行 LEFT JOIN。现在,在连接后的结果表中,我们只需找出订单 id 为 null 的那些客户。相应的 SQL 查询可以写成如下形式:
select c.name as 'Customers' from Customers c
select c.name as 'Customers' from Customers c
left join Orders o ON (o.customerId = c.id)
left join Orders o ON (o.customerId = c.id)
where o.id is null
where o.id is null
Here, we first create aliases of the tables Customers and Orders with the name ‘c’ and ‘o’ respectively. Having done so, we join them with the condition that o.customerId = c.id. At last, we check for the customers whose o.id is null.
在这里,我们首先为表Customers和Orders分别创建别名为‘c’和‘o’的别名。完成后,我们通过条件o.customerId = c.id将它们连接起来。最后,我们检查那些o.id为null的客户。
277. Consider the following schema:
考虑以下模式:
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-query, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c6058d557c902bc7f1c | 官方: 否 | 付费: 否
答案:
Table: Users
表:Users
| Column Name
列名 | Type
类型 |
| account_number | int |
| name | varchar |
The account is the primary key for this table. Each row of this table contains the account number of each user in the bank. There will be no two users having the same name in the table.
account是该表的主键。该表的每一行都包含银行中每个用户的账号。表中不会有任何两个用户拥有相同的姓名。
Table: Transactions
表:Transactions
| Column Name
列名 | Type
类型 |
| trans_id | int |
| account_number | int |
| amount | int |
| transacted_on | date |
trans_id is the primary key for this table. Each row of this table contains all changes made to all accounts. The amount is positive if the user received money and negative if they transferred money. All accounts start with a balance of 0.
trans_id是该表的主键。该表的每一行都包含对所有账户所做的所有更改。如果用户收到钱,金额为正;如果转账出去,金额为负。所有账户的起始余额为0。
Construct a SQL query to display the names and balances of people who have a balance greater than $10,000. The balance of an account is equal to the sum of the amounts of all transactions involving that account. You can return the result table in any order.
构造一个SQL查询,以显示余额大于$10,000的人员的姓名和余额。账户的余额等于涉及该账户的所有交易金额的总和。你可以按任何顺序返回结果表。
Example:
示例:
Input: Users table:
输入:Users表:
| Account_number | name |
| 12300001 | Ram |
| 12300002 | Tim |
| 12300003 | Shyam |
| Account_number | name |
|---|---|
| 12300001 | Ram |
| 12300002 | Tim |
| 12300003 | Shyam |
Transactions table:
Transactions表:
| trans_id | account_number | amount | transacted_on |
| 1 | 12300001 | 8000 | 2022-03-01 |
| 2 | 12300001 | 8000 | 2022-03-01 |
| 3 | 12300001 | -3000 | 2022-03-02 |
| 4 | 12300002 | 4000 | 2022-03-12 |
| 5 | 12300003 | 7000 | 2022-02-07 |
| 6 | 12300003 | 7000 | 2022-03-07 |
| 7 | 12300003 | -4000 | 2022-03-11 |
| trans_id | account_number | amount | transacted_on |
|---|---|---|---|
| 1 | 12300001 | 8000 | 2022-03-01 |
| 2 | 12300001 | 8000 | 2022-03-01 |
| 3 | 12300001 | -3000 | 2022-03-02 |
| 4 | 12300002 | 4000 | 2022-03-12 |
| 5 | 12300003 | 7000 | 2022-02-07 |
| 6 | 12300003 | 7000 | 2022-03-07 |
| 7 | 12300003 | -4000 | 2022-03-11 |
Output:
输出:
| name | balance |
| Ram | 13000 |
| name | balance |
|---|---|
| Ram | 13000 |
Explanation: - Ram's balance is (8000 + 8000 - 3000) = 11000.
解释: - Ram的余额是(8000 + 8000 - 3000) = 11000。
- Tim's balance is 4000.
- Shyam's balance is (7000 + 7000 - 4000) = 10000.
Approach 1:
In this approach, we first create aliases of the given two tables' users and transactions. We can natural join the two tables and then group them by their account number. Next, we use the SUM operator to find the balance of each of the accounts after all the transactions have been processed. The SQL query for this can be written as follows:在这种方法中,我们首先为给定的两个表users和transactions创建别名。我们可以自然连接这两个表,然后按账号分组。接下来,我们使用SUM运算符在处理完所有交易后找出每个账户的余额。这个SQL查询可以写成如下:
SELECT u.name, SUM(t.amount) AS balance
SELECT u.name, SUM(t.amount) AS balance
FROM Users natural join Transactions t
FROM Users natural join Transactions t
GROUP BY t.account_number
GROUP BY t.account_number
HAVING balance> 10000;
HAVING balance> 10000;
278. Consider the following table schema:
考虑以下表结构:
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql-query, topic-specific, sql, database)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: fullstack
- id: 69b37c6058d557c902bc7f24 | 官方: 否 | 付费: 否
答案:
Construct an SQL query to retrieve duplicate records from the Employee table.
构造一个SQL查询,从Employee表中检索重复记录。
Table: Employee
表:Employee
| Column Name
列名 | Type
类型 |
| id | int |
| fname | varchar |
| lname | varchar |
| department | varchar |
| projectId | varchar |
| address | varchar |
| dateofbirth | varchar |
| gender | varchar |
Table: Salary
表:Salary
| Column Name
列名 | Type
类型 |
| id | int |
| position | varchar |
| dateofJoining | varchar |
| salary | varchar |
Now answer the following questions:
现在回答以下问题:
- Construct an SQL query that retrieves the fname in upper case from the Employee table and uses the ALIAS name as the EmployeeName in the result.
SELECT UPPER(fname) AS EmployeeName FROM Employee;
SELECT UPPER(fname) AS EmployeeName FROM Employee;
- Construct an SQL query to find out how many people work in the "HR" department
SELECT COUNT(*) FROM Employee WHERE department = 'HR';
SELECT COUNT(*) FROM Employee WHERE department = 'HR';
- Construct an SQL query to retrieve the first four characters of the ‘lname’ column from the Employee table.
SELECT SUBSTRING(lname, 1, 4) FROM Employee;
SELECT SUBSTRING(lname, 1, 4) FROM Employee;
- Construct a new table with data and structure that are copied from the existing table ‘Employee’ by writing a query. The name of the new table should be ‘SampleTable’.
SELECT * INTO SampleTable FROM Employee WHERE 1 = 0
SELECT * INTO SampleTable FROM Employee WHERE 1 = 0
- Construct an SQL query to find the names of employees whose first names start with "S".
SELECT * FROM Employee WHERE fname LIKE 'S%';
SELECT * FROM Employee WHERE fname LIKE 'S%';
- Construct an SQL query to count the number of employees grouped by gender whose dateOfBirth is between 01/03/1975 and 31/12/1976.
SELECT COUNT(*), gender FROM Employee WHERE dateOfBirth BETWEEN '01/03/1975 ' AND '31/12/1976' GROUP BY gender;
SELECT COUNT(*), gender FROM Employee WHERE dateOfBirth BETWEEN '01/03/1975 ' AND '31/12/1976' GROUP BY gender;
- Construct an SQL query to retrieve all employees who are also managers.
SELECT emp.fname, emp.lname, sal.position
SELECT emp.fname, emp.lname, sal.position
FROM Employee emp INNER JOIN Salary sal ON
FROM Employee emp INNER JOIN Salary sal ON
emp.id = sal.id AND sal.position IN ('Manager');
emp.id = sal.id AND sal.position IN ('Manager');
- Construct an SQL query to retrieve the employee count broken down by department and ordered by department count in ascending manner.
SELECT department, COUNT(id) AS DepartmentCount
SELECT department, COUNT(id) AS DepartmentCount
FROM Employee GROUP BY department
FROM Employee GROUP BY department
ORDER BY DepartmentCount ASC;
ORDER BY DepartmentCount ASC;
- Construct an SQL query to retrieve duplicate records from the Employee table.
SELECT id, fname, department, COUNT(*) as Count
SELECT id, fname, department, COUNT(*) as Count
FROM Employee GROUP BY id, fname, department
FROM Employee GROUP BY id, fname, department
HAVING COUNT(*) > 1;
HAVING COUNT(*) > 1;
279. What do you mean by SQL Correlated Subqueries?
你说的SQL相关子查询是什么意思?
- 知识点: 数据库 (标签: interviewbit, tcs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6a58d557c902bc84bc | 官方: 否 | 付费: 否
答案:
A correlated sub-query is a sub-query that is dependent on another query. Sub-queries that are executed for each row of an outer query are referred to as correlated sub-queries. For each row in the outer query, each sub-query is executed once.
相关子查询是依赖于另一个查询的子查询。对外部查询的每一行执行的子查询称为相关子查询。对于外部查询中的每一行,每个子查询都会执行一次。
Correlated sub-queries can alternatively be thought of as queries that the parent statement uses for row-by-row processing. The parent statement, in this case, might be SELECT, UPDATE, or DELETE.
相关子查询也可以被视为父语句用于逐行处理的查询。在这种情况下,父语句可能是SELECT、UPDATE或DELETE。
280. What is a checkpoint in a database management system, and when does it eventuate?
数据库管理系统中的检查点是什么,它何时发生?
- 知识点: 数据库 (标签: interviewbit, tcs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6a58d557c902bc84bf | 官方: 否 | 付费: 否
答案:
A checkpoint is a technique that removes all previous logs from the system and stores them permanently on the storage drive. Checkpoints are those locations in the transaction log record from which all committed data up to the point of the crash can be recovered.
检查点是一种从系统中删除所有先前的日志并将它们永久存储在存储驱动器上的技术。检查点是事务日志记录中的那些位置,从这些位置可以恢复截至崩溃点的所有已提交数据。
- Data Science
- All Events
- My Events
281. In a database management system, what are the two integrity rules?
在数据库管理系统中,有哪两条完整性规则?
- 知识点: 数据库 (标签: interviewbit, tcs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6a58d557c902bc84c2 | 官方: 否 | 付费: 否
答案:
Referential integrity rules and entity integrity rules are the two forms of integrity rules.
参照完整性规则和实体完整性规则是完整性规则的两种形式。
According to referential integrity requirements, if a primary key value is used as a foreign key in a child table, it cannot be changed. Let R and S be two different relations. Assume that R relates to the relation S through a set of attributes that serve as the Primary Key of S and as a Foreign Key in the relation R. The Foreign Key in a tuple in R must then be either equal to the Primary Key in a tuple in S or completely NULL.
根据参照完整性要求,如果一个主键值在子表中被用作外键,则它不能被更改。设R和S是两个不同的关系。假设R通过一组属性与关系S相关联,这些属性充当S的主键并在关系R中充当外键。那么,R中元组的外键必须要么等于S中元组的主键,要么完全为NULL。
The main key value cannot be null due to entity integrity. An attribute X of a relation R(R) cannot take null values if it is a Prime Attribute of R(R). A Prime Attribute is an attribute that is a part of a relation's Candidate Key.
由于实体完整性,主键值不能为空。如果关系R(R)的属性X是R(R)的主属性,则该属性X不能取空值。主属性是作为关系候选键一部分的属性。
282. What does a database schema imply? What are its types?
数据库模式意味着什么?它有哪些类型?
- 知识点: 数据库 (标签: interviewbit, tcs, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6a58d557c902bc84ef | 官方: 否 | 付费: 否
答案:
A "database schema" is a plan for how a database is built that describes how data is organized (divided into database tables in the case of relational databases). A database schema is formally defined as a series of formulas (sentences) known as integrity constraints that are imposed on a database.
“数据库模式”是构建数据库的计划,描述了数据如何组织(在关系数据库的情况下分为数据库表)。数据库模式被正式定义为一组称为完整性约束的公式(语句),这些约束被施加在数据库上。
Physical schema, logical schema, and view schema are the three types of schema.
物理模式、逻辑模式和视图模式是模式的三种类型。
The physical schema describes how the data contained in blocks of storage is characterized at the physical level of a database.
物理模式描述了存储在存储块中的数据在数据库物理层面上的特征。
The logical schema is the design of a database at the logical level; programmers and database administrators work at this level; data can be characterized as certain types of data records that are stored in data structures; however, internal details such as data structure implementation are obscured at this level (available at the physical level).
逻辑模式是数据库在逻辑层面上的设计;程序员和数据库管理员在这一层面工作;数据可以被描述为存储在数据结构中的某些类型的数据记录;然而,数据结构实现等内部细节在这一层面上被隐藏(在物理层面上可用)。
View schema is the design of a database at the view level. This term refers to how end-users interact with database systems.
视图模式是数据库在视图层面上的设计。这个术语指的是最终用户如何与数据库系统交互。
283. How do you optimize the performance of a database?
如何优化数据库的性能?
- 知识点: 数据库 (标签: interviewbit, tcs-digital, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6d58d557c902bc862e | 官方: 否 | 付费: 否
答案:
There are several techniques that you can use to optimize the performance of a database: - Indexing: Indexing is the process of creating a data structure that allows the database to access and retrieve data quickly thereby avoiding the need for searching and matching every row in the database. Indexes can be created on specific columns in a table to improve the performance of queries that filter or sort data based on those columns.
你可以使用几种技术来优化数据库的性能:- 索引:索引是创建一种数据结构的过程,使数据库能够快速访问和检索数据,从而避免搜索和匹配数据库中的每一行。可以在表中的特定列上创建索引,以提高基于这些列过滤或排序数据的查询性能。
- Partitioning: Partitioning is the process of dividing a table into smaller, more manageable pieces, called partitions. Partitioning can improve the performance of queries that access large amounts of data, as it allows the database to access the data in smaller, more efficient chunks.Partitioning can be done in two ways - vertical and horizontal. Vertical partitioning involves splitting a table into smaller parts based on columns, while horizontal partitioning involves splitting a table into smaller parts based on rows. Vertical partitioning can be useful for tables with many columns that are rarely accessed together, while horizontal partitioning can be useful for tables with a large number of rows that can be grouped based on specific criteria, such as date ranges or geographic regions.
In the above image, we see Vertical and Horizontal Partitioning. In Vertical Partitioning, we are distributing the table columns that separate the Customer Details with their favorite color.
在上面的图像中,我们看到垂直分区和水平分区。在垂直分区中,我们分布表列,将客户详情与其最喜欢的颜色分开。
And, in Horizontal Partitioning, we are minimizing the table size by removing entries from the table and creating a new table with that entry. - Caching: Caching is a technique used to improve the performance of accessing data by storing frequently accessed data in a cache. When a request is made for the data, the system first checks the cache to see if the data is already available. If it is, the system retrieves the data from the cache, rather than from the original source, which can be slower to access.
并且,在水平分区中,我们通过从表中移除条目并创建一个包含该条目的新表来最小化表大小。- 缓存:缓存是一种通过将频繁访问的数据存储在缓存中来提高访问数据性能的技术。当请求数据时,系统首先检查缓存以查看数据是否已经可用。如果是,系统从缓存中检索数据,而不是从原始源检索,原始源的访问可能更慢。
In the above image, we can see that the application is using the database to fetch some data. The application first searches the data into the cache, if the data is not present then it will request the database to provide the data. Once the data is returned by the database, the data is stored in the cache so that in the future, if the data is required, then it can be fetched directly from here.
在上面的图像中,我们可以看到应用程序正在使用数据库获取一些数据。应用程序首先在缓存中搜索数据,如果数据不存在,那么它将请求数据库提供数据。一旦数据库返回数据,数据就被存储在缓存中,以便将来如果需要数据,可以直接从这里获取。
By using caching, the system can access frequently used data more quickly, reducing the overall time it takes to retrieve and process the data. Caching can be particularly useful for large or complex data sets, as well as for systems that require frequent access to the same data. However, it's important to keep in mind that caching can also consume system resources and that the cache must be managed to ensure that it remains accurate and up-to-date.
通过使用缓存,系统可以更快地访问频繁使用的数据,减少检索和处理数据所需的总时间。缓存对于大型或复杂的数据集以及需要频繁访问相同数据的系统特别有用。然而,重要的是要记住,缓存也会消耗系统资源,并且必须管理缓存以确保其保持准确和最新。
Normalization: Normalization is the process of organizing data in a database in a way that minimizes redundancy and dependency. Normalization can improve the performance of the database by reducing the size of the data and improving the efficiency of queries. 2. Optimizing queries: Optimizing queries is the process of improving the performance of SQL statements by minimizing the amount of data that is accessed and processed. This can be done by writing efficient queries, using appropriate indexes, and minimizing the use of expensive operations such as sorts and joins. 3. Monitoring and tuning: Monitoring and tuning is the process of continuously monitoring the performance of the database and making adjustments to improve it. This can involve identifying and addressing bottlenecks, adjusting the configuration of the database, and optimizing the schema and queries.
- 规范化:规范化是在数据库中组织数据的过程,以最小化冗余和依赖性。规范化可以通过减少数据大小和提高查询效率来改善数据库的性能。 2. 优化查询:优化查询是通过最小化访问和处理的数据量来改善SQL语句性能的过程。这可以通过编写高效的查询、使用适当的索引以及最小化使用排序和连接等昂贵操作来实现。 3. 监控和调优:监控和调优是持续监控数据库性能并进行调整以改进它的过程。这可能涉及识别和解决瓶颈、调整数据库配置以及优化模式和查询。
There are several tools available to monitor and tune the performance of a database. Here are a few examples:
有多种工具可用于监控和调优数据库性能。以下是一些示例:
Profiling Tools: These tools can help identify performance bottlenecks by analyzing query execution times and resource usage. Examples include pgBadger, Query Profiler, and pgFouine. 2. Resource Monitoring Tools: These tools can help track resource usages, such as CPU, memory, and disk I/O, to identify performance issues. Examples include top, htop, and sar. 3. Database Administration Tools: These help monitor and tune database performance, including configuration management, query analysis, and schema optimization. Examples include pgAdmin, Oracle Enterprise Manager, and SQL Server Management Studio. 4. Load Testing Tools: These tools can simulate heavy loads on the database to measure its performance and identify bottlenecks. Examples include Apache JMeter, LoadRunner, and Gatling.
- 性能分析工具:这些工具可以通过分析查询执行时间和资源使用情况来帮助识别性能瓶颈。示例包括 pgBadger、Query Profiler 和 pgFouine。 2. 资源监控工具:这些工具可以帮助跟踪资源使用情况,如 CPU、内存和磁盘 I/O,以识别性能问题。示例包括 top、htop 和 sar。 3. 数据库管理工具:这些工具有助于监控和调优数据库性能,包括配置管理、查询分析和架构优化。示例包括 pgAdmin、Oracle Enterprise Manager 和 SQL Server Management Studio。 4. 负载测试工具:这些工具可以模拟数据库上的重负载,以衡量其性能并识别瓶颈。示例包括 Apache JMeter、LoadRunner 和 Gatling。
By using these techniques, database administrators can identify performance issues and make informed decisions on how to optimize the database to ensure it runs smoothly and efficiently.
通过使用这些技术,数据库管理员可以识别性能问题,并就如何优化数据库做出明智的决策,以确保其平稳高效地运行。
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
284. What is a database and how does it store and retrieve data?
什么是数据库,它如何存储和检索数据?
- 知识点: 数据库 (标签: interviewbit, tcs-digital, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6e58d557c902bc8686 | 官方: 否 | 付费: 否
答案:
A database is a collection of structured data that is stored and accessed electronically. Databases are used to store, organize, and retrieve data efficiently, and are an essential part of many computer systems and applications. - Relational Databases: These databases organize data into one or more tables with a predefined schema. They use SQL to query and manipulate data, and enforce ACID properties to ensure data consistency.
数据库是以电子方式存储和访问的结构化数据的集合。数据库用于高效地存储、组织和检索数据,是许多计算机系统和应用程序的重要组成部分。 - 关系型数据库:这些数据库将数据组织到一个或多个具有预定义模式的表中。它们使用 SQL 来查询和操作数据,并强制执行 ACID 属性以确保数据一致性。
- NoSQL databases: NoSQL databases are non-relational databases that store and retrieve data differently than traditional relational databases. Unlike relational databases, which use tables with rows and columns to organize and store data, NoSQL databases use different data models, such as document-based, key-value, column-family, and graph models, to store data in flexible, scalable, and distributed ways.NoSQL databases are designed to handle large amounts of unstructured, semi-structured, and even structured data that cannot be easily managed by traditional relational databases. They offer high availability, scalability, and performance, making them suitable for modern web applications and big data analytics.
- Document Databases: Document databases are a type of NoSQL database that stores data in the form of semi-structured documents, typically in JSON or BSON format. Each document can have its own unique structure and can include fields with varying data types.Document databases are flexible and scalable, allowing for easy data modelling and schema changes. They are well-suited for applications that require complex data structures, such as social media platforms, content management systems, and e-commerce websites.MongoDB is one of the most popular document databases, widely used in web applications for its ease of use, scalability, and high performance.
- Key-value stores: Key-value stores are a type of NoSQL database that stores data as a collection of key-value pairs, where each key is a unique identifier for a particular value. Key-value stores are typically used for caching and session management, as they can store large amounts of data in memory and retrieve it quickly.Key-value stores are simple and scalable, making them ideal for high-traffic web applications that require fast data access. They are also well-suited for distributed systems, as they can be easily partitioned and replicated across multiple nodes.Redis is a popular open-source key-value store, known for its high performance, support for multiple data types, and advanced features such as pub/sub messaging, Lua scripting, and transactions.
285. How do you design and implement database?
你如何设计和实现数据库?
- 知识点: 数据库 (标签: interviewbit, tcs-digital, company-specific)
- 类型: technical | 难度: easy | 子类型: coding
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c6e58d557c902bc8689 | 官方: 否 | 付费: 否
答案:
Databases are an essential part of many applications and are used to store and manage large amounts of data efficiently and effectively.
数据库是许多应用程序的重要组成部分,用于高效且有效地存储和管理大量数据。
To design a database, you need to determine the data that needs to be stored and the relationships between the data. This involves creating a schema, which is a blueprint for the structure of the database. The schema defines the tables, fields, and relationships in the database.
要设计数据库,你需要确定需要存储的数据以及数据之间的关系。这涉及创建模式,模式是数据库结构的蓝图。模式定义了数据库中的表、字段和关系。
Once the database design is complete, the next step is to implement the database. This involves creating the tables and fields in the database and populating the tables with data.
一旦数据库设计完成,下一步就是实现数据库。这涉及在数据库中创建表和字段,并向表中填充数据。
To implement a database, you can use a database management system (DBMS) such as MySQL, Oracle, or MongoDB. A DBMS is a software program that allows you to create and manage a database. It provides a set of tools and interfaces for creating, querying, and updating the database.
要实现数据库,你可以使用数据库管理系统(DBMS),例如 MySQL、Oracle 或 MongoDB。DBMS 是一个软件程序,允许你创建和管理数据库。它提供了一组用于创建、查询和更新数据库的工具和接口。
286. Explain ACID properties in DBMS?
解释DBMS中的ACID属性?
- 知识点: 数据库 (标签: interviewbit, tcs-ninja, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7258d557c902bc8838 | 官方: 否 | 付费: 否
答案:
In order for a database to maintain its integrity, all transactions must adhere to the ACID standard. The ACID acronym refers to atomicity, consistency, isolation, and durability, so let's discuss each of them in turn. - Atomicity: An atomic transaction data remains unchanged even after an operation is executed. This means that if an operation is undertaken on the data, either the operation must be completed or it must not be executed at all. A transaction operation should not be split between different parts or executed in stages. It must be completed entirely and not partially.
为了使数据库保持其完整性,所有事务都必须遵循ACID标准。ACID这一缩写指的是原子性、一致性、隔离性和持久性,因此让我们依次讨论它们。- 原子性:即使在执行操作之后,原子事务数据也保持不变。这意味着如果对数据执行了操作,那么该操作要么必须完成,要么根本不执行。事务操作不应被拆分到不同部分或分阶段执行。它必须完全完成,而不能只完成一部分。
- Consistency: The consistency property defines the level of how the data should be kept unchanged. By keeping the data consistent, the DBMS is not allowing any inconsistency in the data. An example of a level of consistency would be when one table contains the data on which the operation is performed while another table should contain the data before performing the operation.
- Isolation: When the transactions are running concurrently, the outcome should be the same as if the transactions were running serially; that is, the result should be the same as if there were no transactions at all.
- Durability: The data after an operation is successfully executed is permanent in a DBMS. To ensure the durability of data, the term durability is used. Even if the system fails or crashes, the database may survive. However, if it is lost, the responsibility of the recovery manager is to ensure its durability. Whenever we make changes to values, the COMMIT command must be used.
287. What is the DDL command in MySql explain Create and Alter command?
MySql中的DDL命令是什么,请解释Create和Alter命令?
- 知识点: 数据库 (标签: interviewbit, tcs-ninja, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7258d557c902bc883b | 官方: 否 | 付费: 否
答案:
The Data Definition Language is a set of SQL commands designed to structure databases. It handles database schema descriptions and constructs and modifies database objects' structures in databases. In addition to data, DDL refers to a set of SQL instructions for creating, modifying, and deleting database structures. It does not handle data. Database structures are created, modified, and deleted using DDL commands. All DDL commands are auto-committed, saving all database changes permanently. DDL commands that construct the database structure include: - CREATE: A database or one of its objects is created using this command (like tables, indexes, functions, views, stored procedures, and triggers). You can issue two kinds of SQL statements: one that creates a database and another that creates a table.
数据定义语言是一组用于构建数据库结构的SQL命令。它处理数据库模式描述,并在数据库中构造和修改数据库对象的结构。除了数据之外,DDL还指一组用于创建、修改和删除数据库结构的SQL指令。它不处理数据。数据库结构是通过DDL命令创建、修改和删除的。所有DDL命令都会自动提交,从而永久保存所有数据库更改。用于构造数据库结构的DDL命令包括:- CREATE:使用此命令创建数据库或其某个对象(如表、索引、函数、视图、存储过程和触发器)。你可以发出两种SQL语句:一种创建数据库,另一种创建表。
Syntax:
语法:
To create Database: CREATE DATABASE db_name;
创建数据库:CREATE DATABASE db_name;
Example: CREATE DATABASE store;
示例:CREATE DATABASE store;
To create Table:
创建表:
CREATE TABLE table_name(
CREATE TABLE table_name(
Column_name1 data_type(size),
Column_name1 data_type(size),
Column_name2 data_type(size),
Column_name2 data_type(size),
Column_name3 data_type(size),
Column_name3 data_type(size),
…..
);
Example:
示例:
CREATE TABLE product(
CREATE TABLE product(
Id int(10),
Id int(10),
Name varchar(100),
Name varchar(100),
Price varchar(10)
Price varchar(10)
);
- ALTER: The ALTER command in SQL lets us add, delete, and modify items in a table, view, or the whole database. We can also modify, add, and delete constraints, columns, and indexes using the ALTER command.
Command to add new Column:
添加新列的命令:
Syntax: ALTER TABLE table_name ADD column_name column-definition;
语法:ALTER TABLE table_name ADD column_name column-definition;
Example: ALTER TABLE product ADD category varchar(50);
示例:ALTER TABLE product ADD category varchar(50);
Command to modify a Column:
修改列的命令:
Syntax: ALTER TABLE table_name MODIFY (column-definition);
语法:ALTER TABLE table_name MODIFY (column-definition);
Example: ALTER TABLE product MODIFY (category varchar2(100));
示例:ALTER TABLE product MODIFY (category varchar2(100));
288. What is the Drop and Truncate command in SQL?
SQL 中的 Drop 和 Truncate 命令是什么?
- 知识点: 数据库 (标签: interviewbit, tcs-ninja, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7258d557c902bc883e | 官方: 否 | 付费: 否
答案:
- DROP: You may drop a whole database or a table by using the DROP statement. Existing objects such as databases, tables, indexes, and views are destroyed with the DROP command.
Syntax: To drop a table: DROP TABLE table_name;
语法:删除表:DROP TABLE table_name;
To drop a database: DROP DATABASE db_name;
删除数据库:DROP DATABASE db_name;
Example: To drop a table: DROP TABLE product;
示例:删除表:DROP TABLE product;
To drop a database: DROP DATABASE store; - TRUNCATE: Used to indicate the table’s extents for deallocation (empty for reuse). This method is quicker than the usual integrity checking procedures to remove all data from a table. This procedure was introduced in the SQL:2008 standard for the first time. It is somewhat equivalent to the delete command.
删除数据库:DROP DATABASE store; - TRUNCATE:用于指示表的区段进行释放(清空以供重用)。此方法比通常的完整性检查过程更快地从表中移除所有数据。此过程首次在 SQL:2008 标准中引入。它在某种程度上相当于 delete 命令。
Syntax: TRUNCATE TABLE table_name;
语法:TRUNCATE TABLE table_name;
Example: TRUNCATE TABLE product;
示例:TRUNCATE TABLE product;
289. Write an SQL Query to select all those entries from the table STUDENTS, whose name is “Rahul”.
编写一个 SQL 查询,从表 STUDENTS 中选择所有 name 为 “Rahul” 的条目。
- 知识点: 数据库 (标签: interviewbit, tcs-nqt, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7458d557c902bc8947 | 官方: 否 | 付费: 否
答案:
The SQL Query to do so is
执行此操作的 SQL 查询是
SELECT * FROM STUDENTS WHERE NAME = “Rahul”
SELECT * FROM STUDENTS WHERE NAME = “Rahul”
290. Write an SQL query to print the current date.
编写一个 SQL 查询来打印当前日期。
- 知识点: 数据库 (标签: interviewbit, tcs-nqt, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tata Consultancy Services
- id: 69b37c7458d557c902bc894a | 官方: 否 | 付费: 否
答案:
The SQL Query to print the current date is: GetDate()
打印当前日期的 SQL 查询是:GetDate()
291. State some of the advantages of a DataBase Management System.
列举数据库管理系统的一些优点。
- 知识点: 数据库 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b1f | 官方: 否 | 付费: 否
答案:
Some of the advantages of a DataBase Management System are as follows:
数据库管理系统的一些优点如下:
- It helps in controlling redundancy in the database.
- Unauthorized access is restricted by it.
- Multiple user interfaces are available.
- Backup and recovery services are available.
- Integrity limitations are enforced.
- Ensure that data is consistent.
- Easily accessible.
- Due to the usage of queries, data extraction and processing are simple.
292. What are ACID properties in Database Management Systems?
数据库管理系统中的 ACID 属性是什么?
- 知识点: 数据库 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b22 | 官方: 否 | 付费: 否
答案:
The term "ACID" is an acronym for Atomicity, Consistency, Isolation and Durability. A transaction is a logical unit of work that accesses and, in certain cases, updates the contents of a database. Read and write operations are used by transactions to access data. Certain properties are followed before and after a transaction in order to preserve consistency in a database. ACID characteristics are what they are called. Let us take a look at each of these characteristics in detail: - Atomicity: Atomicity means that either the complete transaction occurs at once or it does not occur at all. There is no middle ground, which means that transactions do not take place in stages. Each transaction is treated as a single entity that is either completed or not conducted at all. It entails the following two procedures.
术语"ACID"是原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持久性(Durability)的首字母缩写。事务是访问并在某些情况下更新数据库内容的逻辑工作单元。事务使用读和写操作来访问数据。为了保持数据库中的一致性,事务前后需要遵循某些属性。这些属性就被称为 ACID 特性。让我们详细看看每一个特性: - 原子性:原子性意味着要么整个事务一次性发生,要么根本不发生。没有中间状态,这意味着事务不会分阶段进行。每个事务被视为一个单一实体,要么完成,要么根本不执行。它包含以下两个过程。
Abort: If a transaction aborts, any database modifications are lost. Commit: When a transaction commits, the changes it contains become visible.
中止:如果事务中止,任何数据库修改都会丢失。提交:当事务提交时,其所包含的更改变得可见。
The 'All or nothing rule' is another name for atomicity.
"全有或全无规则"是原子性的另一个名称。
Consider the following transaction T, which consists of two transactions: T1 and T2. 100 dollars transferred from account X to account Y.
考虑以下事务 T,它由两个事务组成:T1 和 T2。从账户 X 向账户 Y 转移 100 美元。
If a transaction fails after T1 but before T2 (for example, after write(X) but before write(Y)), the amount deducted from X but not added to Y is deducted. As a result, the database is in an inconsistent condition. As a result, the transaction must be completed in its entirety to guarantee that the database state is valid. - Consistency: This means that integrity constraints must be maintained before and after the transaction to ensure that the database is consistent. It refers to a database's correctness. The entire amount before and after the transaction must be maintained, as shown in the example above.
如果事务在 T1 之后但在 T2 之前失败(例如,在 write(X) 之后但在 write(Y) 之前),则从 X 扣除的金额没有被添加到 Y。因此,数据库处于不一致状态。因此,事务必须完整完成以保证数据库状态有效。 - 一致性:这意味着在事务前后必须维护完整性约束,以确保数据库是一致的。它指的是数据库的正确性。如上面的例子所示,事务前后的总金额必须保持不变。
Before T, the total is 500 + 200 = 700. After T, the total is 400 + 300 = 700.
在 T 之前,总额是 500 + 200 = 700。在 T 之后,总额是 400 + 300 = 700。
As a result, the database is consistent. When T1 succeeds but T2 fails, there is inconsistency. As a result, T is not complete. - Isolation: This attribute assures that several transactions can take place at the same time without causing database state inconsistencies. Transactions take place in a non-interfering manner. Changes made in one transaction are not visible to other transactions until that transaction's update is written to memory or committed. This feature assures that concurrently executing transactions results in a state that is identical to the one attained if they were executed sequentially in some order.
因此,数据库是一致的。当 T1 成功但 T2 失败时,就存在不一致。因此,T 不完整。 - 隔离性:此属性确保多个事务可以同时发生而不会导致数据库状态不一致。事务以互不干扰的方式发生。在一个事务中所做的更改对其他事务不可见,直到该事务的更新被写入内存或提交。此特性确保并发执行的事务所产生的结果状态与按某种顺序顺序执行时所达到的状态相同。
Let us take an example to understand Isolation. Let X = 500 and Y = 500 and let there be two transactions T and T".
让我们举一个例子来理解隔离性。设 X = 500,Y = 500,并且有两个事务 T 和 T"。
Assume T has been running until Read (Y), at which point T" begins. As a result of this interleaving, T" reads the right value of X but the wrong value of Y, and the sum computed by T": (X+Y = 50, 000+500=50, 500) is inconsistent with the sum at the end of the transaction:
假设 T 一直运行到 Read (Y),此时 T" 开始。由于这种交错,T" 读取了 X 的正确值但读取了 Y 的错误值,并且 T" 计算的总和:(X+Y = 50, 000+500=50, 500) 与事务结束时的总和
T = 50, 000 + 450 = 50, 450 (X+Y = 50, 000 + 450 = 50, 450).
T = 50, 000 + 450 = 50, 450 (X+Y = 50, 000 + 450 = 50, 450)。
Due to the loss of 50 units, this causes database discrepancy. As a result, transactions must be performed in isolation, and changes should only be seen after they have been written to the main memory. - Durability: This attribute ensures that after the transaction has been completed, the database updates and modifications are saved and written to disc and that they survive even if the system fails. These changes are now saved in non-volatile memory and are permanent. The transaction's effects are never lost as a result of this.
由于丢失了 50 个单位,这导致数据库不一致。因此,事务必须隔离执行,并且只有在更改被写入主内存后才能看到这些更改。- 持久性:此属性确保在事务完成后,数据库的更新和修改会被保存并写入磁盘,即使系统发生故障也能存留下来。这些更改现在保存在非易失性内存中,并且是永久性的。因此,事务的影响永远不会丢失。
The ACID properties , taken together, provide a mechanism for ensuring the correctness and consistency of a database in such a way that each transaction is a group of operations that acts as a single unit, produces consistent results, is isolated from other operations, and the updates it makes are durably stored.
ACID 属性结合在一起,提供了一种确保数据库正确性和一致性的机制,使得每个事务都是一组作为单个单元运作的操作,产生一致的结果,与其他操作隔离,并且其所做的更新被持久存储。
293. What do you understand by a checkpoint in Database Management Systems?
在数据库管理系统中,你对检查点是如何理解的?
- 知识点: 数据库 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b25 | 官方: 否 | 付费: 否
答案:
The Checkpoint in Database Management Systems (DBMS) is a technique that removes all previous logs from the system and stores them permanently on the storage drive. Preserving the log of each transaction and maintaining shadow pages are two methods that can assist the DBMS in recovering and maintaining the ACID properties. When it comes to a log-based recovery system, checkpoints are necessary. Checkpoints are the minimal points from which the database engine can recover after a crash as a specified minimal point from which the transaction log record can be utilised to recover all committed data up to the moment of the crash.
数据库管理系统(DBMS)中的检查点是一种从系统中移除所有先前的日志并将它们永久存储在存储驱动器上的技术。保留每个事务的日志和维护影子页面是两种可以帮助 DBMS 恢复和维护 ACID 属性的方法。在基于日志的恢复系统中,检查点是必要的。检查点是数据库引擎在崩溃后可以恢复的最小点,作为指定的最小点,从该点可以使用事务日志记录来恢复直到崩溃时刻的所有已提交数据。
294. What are transparent Distributed Database Management Systems?
什么是透明分布式数据库管理系统?
- 知识点: 数据库 (标签: interviewbit, tech-mahindra, company-specific)
- 类型: technical | 难度: easy | 子类型: system-design
- 分类: general
- 公司: Tech Mahindra
- id: 69b37c7758d557c902bc8b28 | 官方: 否 | 付费: 否
答案:
The transparent Distributed Database Management System is a form of a database management system that conceals its physical structure from users. Physical structure, also known as physical storage structure, refers to the DDBMS's memory manager and explains how data is saved on a disc. Because of this, there is less abstraction. There are four types of transparencies in Distributed Database Management Systems (or DDBMS): - Transaction transparency
透明分布式数据库管理系统是一种向用户隐藏其物理结构的数据库管理系统形式。物理结构,也称为物理存储结构,指的是 DDBMS 的内存管理器,并解释了数据如何保存在磁盘上。因此,抽象程度较低。分布式数据库管理系统(或 DDBMS)中有四种透明性类型:- 事务透明性
- Performance transparency
- DBMS transparency
- Distribution transparency.
295. Explain ACID Property in DBMS.
解释 DBMS 中的 ACID 属性。
- 知识点: 数据库 (标签: interviewbit, virtusa, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Virtusa
- id: 69b37c8a58d557c902bc9448 | 官方: 否 | 付费: 否
答案:
ACID stands for the acronym "Atomicity, Consistency, Isolation, and Durability". Property of a database system that ensures consistency between the internal data of the database and the external data sources such as a file system. If a property is missing in one area, the data in all areas must be consistent. The ACID property can be expressed as
ACID 是“原子性、一致性、隔离性和持久性”的首字母缩写。数据库系统的一种属性,确保数据库内部数据与外部数据源(如文件系统)之间的一致性。如果某个区域缺少某个属性,所有区域中的数据必须保持一致。ACID 属性可以表示为
Atomicity - No changes are allowed to take place in the database system except those that are explicitly allowed by a transaction. 2. Consistency - The internal data of the database and the external data sources must be consistent. This is achieved by ensuring that no transactions attempt to update the same records at different times. 3. Isolation - Transactions should not interfere with each other. For example, if one transaction updates a record that another transaction is updating, both transactions are likely to fail. 4. Durability - All records must remain intact when they are written back to their original location after completion of a transaction.
- 原子性——数据库系统中不允许发生更改,除非这些更改是事务明确允许的。 2. 一致性——数据库的内部数据和外部数据源必须保持一致。这是通过确保没有事务尝试在不同时间更新相同记录来实现的。 3. 隔离性——事务之间不应相互干扰。例如,如果一个事务更新了另一个事务正在更新的记录,两个事务都可能失败。 4. 持久性——在事务完成后,所有记录在被写回其原始位置时必须保持完整。
296. Consider an SQL table which has name of employees and their salaries as an entry in each tuple. Find the employees who have the second highest salary.
考虑一个 SQL 表,其中每个元组都有一个条目包含员工姓名及其工资。找出工资第二高的员工。
- 知识点: 数据库 (标签: interviewbit, walmart, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 沃尔玛
- id: 69b37c8f58d557c902bc96ab | 官方: 否 | 付费: 否
答案:
There can be several approaches while writing an SQL query to a particular problem. Be sure that you explain your thinking as and when you are thinking about your approach. This will keep the interviewer engaged and present to him a clearer image of your thinking process.
在针对特定问题编写 SQL 查询时,可以有多种方法。请务必在思考你的方法时解释你的思路。这将使面试官保持参与,并向他更清晰地展示你的思考过程。
Approach 1:
方法一:
SELECT name, MAX(salary) AS salary
SELECT name, MAX(salary) AS salary
FROM employee
FROM employee
WHERE salary IN
WHERE salary IN
(SELECT salary FROM employee MINUS SELECT MAX(salary)
(SELECT salary FROM employee MINUS SELECT MAX(salary)
FROM employee);
FROM employee);
Here, we first find all the salaries which are not equal to the highest salary. Thus, the highest salary is eliminated by this process. Now, we need to find the employees having the highest salary in the remaining salaries.
这里,我们首先找出所有不等于最高工资的工资。因此,最高工资在这个流程中被排除。现在,我们需要在剩余的工资中找出拥有最高工资的员工。
Approach 2:
方法 2:
SELECT name, MAX(salary) AS salary
SELECT name, MAX(salary) AS salary
FROM employee
FROM employee
WHERE salary <> (SELECT MAX(salary)
WHERE salary <> (SELECT MAX(salary)
FROM employee);
FROM employee);
Here, we use the NOT operator. We run a nested query to first find the highest salary. Then, we find the highest salary in the outer query subject to the condition that it is not equal to the highest salary returned by the inner query.
这里,我们使用 NOT 运算符。我们运行一个嵌套查询来首先找出最高工资。然后,我们在外部查询中找出最高工资,条件是它不等于内部查询返回的最高工资。
Approach 3:
方法 3:
select * from employee
select * from employee
group by salary
group by salary
order by salary desc limit 1,1;
order by salary desc limit 1,1;
Here, we use the LIMIT operator. First of all, we order the tuples in the descending order of the salaries. Then we use the LIMIT operator and provide it with an offset value of 1. It implies that we will skip the first entry of the sorted order and limit our results to 1 entry of the remaining result. Here, we make an assumption that all the employees have unique salaries.
这里,我们使用 LIMIT 运算符。首先,我们按工资降序对元组进行排序。然后我们使用 LIMIT 运算符并为其提供偏移值 1。这意味着我们将跳过排序顺序中的第一条记录,并将结果限制为剩余结果中的 1 条记录。这里,我们假设所有员工都有唯一的工资。
297. What do you understand about the following in the context of DBMS: Primary key, Super key, Candidate key and Foreign key.
在 DBMS 的上下文中,你对以下内容有何理解:主键、超键、候选键和外键。
- 知识点: 数据库 (标签: interviewbit, walmart, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: 沃尔玛
- id: 69b37c9058d557c902bc96ba | 官方: 否 | 付费: 否
答案:
- Super Key: The Super Key is a collection of all the keys that help to uniquely identify rows in a table. This means that all columns in a table that are capable of uniquely identifying the table's other columns are called super keys.
- Candidate Key: An attribute or group of attributes that can uniquely identify a tuple such that no subset of it can uniquely identify a tuple, is known as a candidate key. A candidate key can be referred to as a subset of super keys. Among all the candidate keys, one key is chosen and referred to as the primary key.
- Primary Key: A primary key is basically one of the candidate keys. A primary key is a column or group of columns in a table that helps to uniquely identify each record in that table, such that no subset of it can uniquely identify each tuple. In a table, there can only be one primary key. In addition, the primary Key cannot have identical values in any two rows. A PRIMARY KEY (PK) constraint on a column or set of columns prevents null values or duplicates from appearing. There can only be one primary key constraint per table.
- Foreign key: The column in a table that points to the primary key of another table is known as a foreign key. For example - Every employee in a corporation is assigned to a specific department, and employee and department are two distinct entities. As a result, the department's information cannot be stored in the personnel table. That's why the primary key of one table is used to connect these two tables.
298. How do the commands DROP, TRUNCATE, and DELETE differ in SQL?
在 SQL 中,命令 DROP、TRUNCATE 和 DELETE 有何不同?
- 知识点: 数据库 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Wipro
- id: 69b37c9758d557c902bc9b59 | 官方: 否 | 付费: 否
答案:
| DROP | TRUNCATE | DELETE |
|---|---|---|
| DROP is used for deleting a database, table, or a view DROP 用于删除数据库、表或视图 | TRUNCATE is used for deleting all rows of a table TRUNCATE 用于删除表中的所有行 | DELETE can either delete all of the rows at once or one by one. i.e., we can use it according to our needs. DELETE 可以一次性删除所有行,也可以逐行删除。也就是说,我们可以根据需要使用它。 |
| No data can be rollbacked 数据无法回滚 | No data can be rollbacked 数据无法回滚 | Data can be rollbacked 数据可以回滚 |
| It is a Data Definition Language (DDL) command 它是数据定义语言(DDL)命令 | It is a Data Definition Language (DDL) command 它是数据定义语言(DDL)命令 | It is a Data Manipulation Language (DML) command. 它是数据操纵语言(DML)命令。 |
| It deletes the entire structure of the table. 它删除表的整个结构。 | It preserves the structure of the table. 它保留表的结构。 | It does not affect the structure of the table. 它不影响表的结构。 |
299. What is SQL Profiler?
什么是 SQL Profiler?
- 知识点: 数据库 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Wipro
- id: 69b37c9758d557c902bc9b5c | 官方: 否 | 付费: 否
答案:
SQL Server Profiler is a graphical user interface for SQL Trace (SQL Trace is a built-in SQL Server application that monitors and records database activity in SQL Server 6.5. This tool can show server activity, set filters to focus on the operations of specific users, applications, or workstations, and filter SQL commands) that helps in monitoring a Database Engine or Analysis Services instance. You can record and store information about each event to a file or table for subsequent analysis.
SQL Server Profiler 是 SQL Trace(SQL Trace 是 SQL Server 6.5 中内置的 SQL Server 应用程序,用于监视和记录数据库活动。此工具可以显示服务器活动、设置筛选器以聚焦特定用户、应用程序或工作站的操作,并筛选 SQL 命令)的图形用户界面,有助于监视数据库引擎或 Analysis Services 实例。你可以将每个事件的信息记录并存储到文件或表中,以便后续分析。
The SQL Profiler software allows us to track SQL Server connections and determine actions such as which SQL Scripts are executing, unsuccessful jobs, and so on. SQL databases and their environments are monitored, analyzed, troubleshooted, and tuned with this tool.
SQL Profiler 软件允许我们跟踪 SQL Server 连接并确定诸如正在执行哪些 SQL 脚本、失败的作业等操作。此工具用于监视、分析、排查和调优 SQL 数据库及其环境。
300. What are the advantages and disadvantages of indexing in DBMS?
在 DBMS 中索引的优缺点是什么?
- 知识点: 数据库 (标签: interviewbit, wipro, company-specific)
- 类型: technical | 难度: easy | 子类型: concept
- 分类: general
- 公司: Wipro
- id: 69b37c9858d557c902bc9b73 | 官方: 否 | 付费: 否
答案:
Indexing is a technique for improving the database performance by reducing the number of disc accesses needed when a query is run. It's a data structure strategy for finding and accessing data in a database rapidly.
索引是一种通过减少运行查询时所需的磁盘访问次数来提高数据库性能的技术。它是一种用于快速查找和访问数据库中数据的数据结构策略。
The following are some of the benefits of indexes: - An index allows data to be retrieved quickly.
以下是索引的一些优点: - 索引允许快速检索数据。
- When an index is used in a query, the performance usually improves dramatically.
- They're good for sorting. It is possible to eliminate the need for a post-fetch-sort procedure.
The index ensures that each record in the database is uniquely identified.
The cons of indexing are: - Inserts, updates, and deletes are all slowed down by indexes.索引的缺点如下: - 索引会减慢插入、更新和删除操作。
- Indexes take up a lot of space (this increases with the number of fields used and the length of the fields).
301. What is normalization, and why is it important in database design?
什么是规范化,为什么它在数据库设计中很重要?
- 知识点: 数据库
- 类型: technical | 难度: medium | 子类型:
- 分类: general
- 公司: Google
- id: 6964718ba9243c30c87060bb | 官方: 是 | 付费: 否
答案:
Normalization is the process of organizing data in a database to reduce redundancy and reliance. It entails dividing a huge table into smaller tables and building relationships between them to guarantee that each table represents a single entity and that each attribute in a table is reliant on the primary key of that table.
规范化是组织数据库中数据以减少冗余和依赖性的过程。它将一个巨大的表划分为较小的表,并在这些表之间建立关系,以确保每个表代表一个单一实体,并且表中的每个属性都依赖于该表的主键。
Normalization levels include the first normal form (1NF), the second normal form (2NF), the third normal form (3NF), and further levels of normalization. Each level of normalization builds on the one before it, intending to minimize redundancy and reliance while increasing data consistency and integrity. Normalization is a critical part of database design, and a thorough understanding of normalization principles is required for developing successful and efficient databases.
规范化级别包括第一范式(1NF)、第二范式(2NF)、第三范式(3NF)以及更高级别的规范化。每个规范化级别都建立在前一个级别的基础上,旨在最小化冗余和依赖性,同时提高数据的一致性和完整性。规范化是数据库设计的关键部分,深入理解规范化原则对于开发成功且高效的数据库是必需的。
302. MySQL 有哪些特性?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: MySQL, Features, Triggers, Cursors)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d980fa809e6d3885cbea | 官方: 是 | 付费: 否
答案:
答案MySQL 提供跨平台支持,提供多种用于应用编程的接口(API),并且有许多存储过程(stored procedure)(如触发器和游标),有助于数据库管理。
303. 系统的传统网络库(Traditional Network Library)是什么?
- 知识点: 数据库 / 操作系统与网络 / 系统设计/架构 / UI/UX 设计 (主题: networking, os, database;标签: Named Pipes, IPC, POSIX, Windows)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d980fa809e6d3885cbee | 官方: 是 | 付费: 否
答案:
答案在 Windows 或 POSIX 系统中,命名管道(named pipes)提供了一种进程间通信方式,用于连接运行在同一台机器上的不同进程。它免除了使用网络协议栈的必要,并且数据传输不会影响性能。服务器会建立命名管道来监听请求。客户端进程需要知道特定的管道名称才能发送请求。
304. DDL(Data Definition Language)、DML(Data Manipulation Language)、DCL(Data Control Language) 分别代表什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, mysql, database;标签: DDL, DML, DCL)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d980fa809e6d3885cbf6 | 官方: 是 | 付费: 否
答案:
答案DDL 是 Data Definition Language(数据定义语言)的缩写,用于处理数据库 schema(模式),以及描述数据如何存储在数据库中。例如 CREATE TABLE(创建表)命令。DML 表示 Data Manipulation Language(数据操作语言),包括 SELECT(查询)、INSERT(插入)等命令。DCL 表示 Data Control Language(数据控制语言),包括 GRANT(授权)、REVOKE(撤销)等命令。
305. MySQL(关系型数据库管理系统) 中的 join(连接)是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, sql, database;标签: Join, Inner Join, Left Join, Right Join, Full Join)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d980fa809e6d3885cbfa | 官方: 是 | 付费: 否
答案:
答案在 MySQL 中,join(连接) 用于从两个或多个表中查询数据。查询基于表中某些列之间的关系来完成。MySQL 中有四种 join(连接)。Inner join(内连接) 在两张表中至少有一个匹配时返回行。Left join(左连接) 即使右表没有匹配,也会返回左表的所有行。Right join(右连接) 即使左表没有匹配,也会返回右表的所有行。Full join(全连接) 会在表之间至少有一个匹配时返回行。
现在通过这个 SQL(结构化查询语言) 教程深入掌握 SQL(结构化查询语言) 概念!
306. 常见的 MySQL(关系型数据库管理系统) 函数有哪些?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, sql, database;标签: Functions, NOWO, CURRDATEO, CONCAT, DATEDIFF)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d980fa809e6d3885cc02 | 官方: 是 | 付费: 否
答案:
答案常见的 MySQL(关系型数据库管理系统) 函数如下:
NOWO(当前日期时间函数): 用于将当前日期和时间作为一个单一值返回的函数
CURRDATEO(当前日期函数): 用于返回当前日期或时间的函数
CONCAT (X, Y)(字符串拼接函数): 用于拼接两个字符串值并生成一个字符串输出的函数
DATEDIFF (X, Y)(日期差函数): 用于计算两个日期之间差值的函数
查看 Intellipaat 的博客以对 SQL(结构化查询语言) 优化技术有一个更清晰的理解!
307. CHAR(定长字符类型) 和 VARCHAR(变长字符类型) 的区别是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: CHAR, VARCHAR)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d980fa809e6d3885cc06 | 官方: 是 | 付费: 否
答案:
答案创建表时,CHAR(定长字符类型) 用于定义表和列的固定长度。长度值范围可以是 1–255。VARCHAR(变长字符类型) 命令用于根据需要调整列和表的长度。
308. 什么是 Heap Tables(堆表)?
- 知识点: 数据库 / 操作系统与网络 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: Heap Table, In-memory, AUTO INCREMENT)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d980fa809e6d3885cc0a | 官方: 是 | 付费: 否
答案:
答案基本上,Heap tables(堆表) 是内存表,用于高速临时存储。但其中不允许 TEXT(文本类型) 或 BLOB(二进制大对象) 字段。它们也不支持 AUTO INCREMENT(自动递增)。
309. 在 MySQL(MySQL)中拼接字符串(string)/表(table)的语法是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, sql;标签: CONCAT)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d980fa809e6d3885cc13 | 官方: 是 | 付费: 否
答案:
答案在 MySQL(MySQL)中用于拼接的语法是:
CONCAT (string 1, string 2, string 3)
CONCAT (string 1, string 2, string 3)
310. 一个表(table)最多可以创建多少个索引列(index column)?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database, index;标签: Index, Limit, 16)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d982fa809e6d3885cd12 | 官方: 是 | 付费: 否
答案:
答案任何表(table)最多可以创建的索引列(index column)数量上限是 16。
311. MySQL(MySQL)中数据库列(database column)可用的字符串类型(string type)有哪些?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: SET, BLOB, VARCHAR, TEXT, ENUM, CHAR)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d982fa809e6d3885cd1c | 官方: 是 | 付费: 否
答案:
答案在 MySQL(MySQL)中,数据库列(database column)可使用的不同字符串类型(string type)包括 SET(SET)、BLOB(BLOB)、VARCHAR(VARCHAR)、TEXT(TEXT)、ENUM(ENUM)和 CHAR(CHAR)。
312. 如何获取当前 SQL(SQL)(MySQL(MySQL))的版本?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, sql;标签: VERSION, SELECT)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d982fa809e6d3885cd20 | 官方: 是 | 付费: 否
答案:
答案获取当前 MySQL(MySQL)版本的语法:
SELECT VERSION ();
SELECT VERSION ();
313. 是否存在面向对象版本的 MySQL(MySQL)库函数(library function)?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 / 编程语言基础 (主题: mysql, php;标签: MySQLi, PHP, OOP)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d982fa809e6d3885cd2b | 官方: 是 | 付费: 否
答案:
答案是的。MySQLi(MySQLi)是 MySQL(MySQL)的面向对象版本,并且它在 PHP(PHP)中作为接口(interface)使用。
314. MySQL(MySQL)使用的存储引擎(storage engine)是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: Storage Engine, Indexing, Locking)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d982fa809e6d3885cd37 | 官方: 是 | 付费: 否
答案:
答案存储表(table)被称为表类型(table type)。数据存储在文件中,并使用多种技术,例如索引(index)、锁级别(lock level)、能力(capabilities)以及函数(function)等。
315. 主键(primary key)和候选键(candidate key)的区别是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: Primary Key, Candidate Key, Foreign Key)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d982fa809e6d3885cd3b | 官方: 是 | 付费: 否
答案:
答案MySQL(MySQL)中主键(primary key)用于唯一标识表中的每一行。对于一张表(table),只有一个主键(primary key)。候选键(candidate key)可用于引用外键(foreign key)。其中一个候选键(candidate key)就是主键(primary key)。
316. MySQL(MySQL)中有哪些不同类型的表(table)?
- 知识点: 数据库 / 算法与数据结构 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: MyISAM, Heap, InnoDB, BDB, Transactions)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d982fa809e6d3885cd48 | 官方: 是 | 付费: 否
答案:
答案MyISAM(MyISAM)是默认表(table),基于顺序访问方法(sequential access method)。
Heap(Heap)是用于快速数据访问的表,但如果表或系统崩溃,数据会丢失。
InnoDB(InnoDB)是支持事务的表,使用 COMMIT(COMMIT)和 ROLLBACK(ROLLBACK)命令。
BDB(BDB)可以支持类似 InnoDB(InnoDB)的事务,但执行更慢。
317. 可以在 Linux(Linux)操作系统上使用 MySQL(MySQL)吗?
- 知识点: 数据库 / 操作系统与网络 / 系统设计/架构 / UI/UX 设计 (主题: mysql, linux;标签: Linux, MySQL, Service)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965d982fa809e6d3885cd4c | 官方: 是 | 付费: 否
答案:
答案可以。使用 MySQL(MySQL)与 Linux(Linux)操作系统的语法如下:
etc/init.d/mysqlstart
etc/init.d/mysqlstart
318. MySQL(MySQL)中 ENUM(ENUM)的用途是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: ENUM, Constraints)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e852 | 官方: 是 | 付费: 否
答案:
答案ENUM(ENUM)的用途是限制可以进入表中的值。例如,用户可以创建一个表并指定只能使用特定的月份值,其他月份值将无法插入到该表中。
319. MySQL(MySQL)表中可以使用哪些 TRIGGER(TRIGGER)?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: Trigger, BEFORE, AFTER, INSERT, UPDATE, DELETE)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e856 | 官方: 是 | 付费: 否
答案:
答案MySQL(MySQL)允许使用如下 TRIGGER(TRIGGER):
BEFORE INSERT
BEFORE INSERT
AFTER INSERT
插入后
BEFORE UPDATE
更新前
AFTER UPDATE
更新后
BEFORE DELETE
删除前
AFTER DELETE
删除后
320. MySQL(MySQL)中 LIKE(LIKE)和 REGEXP(REGEXP)操作符有什么区别?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, sql;标签: LIKE, REGEXP, Pattern Matching)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e85a | 官方: 是 | 付费: 否
答案:
答案LIKE(LIKE)使用 ‘%’ 符号表示。例如:
SELECT * FROM user WHERE user name LIKE “%NAME”另一方面,REGEXP(REGEXP)的用法如下:
SELECT * FROM user WHERE username REGEXP “^NAME”;
SELECT * FROM user WHERE username REGEXP “^NAME”;
321. 如何使用 MySQL(MySQL)慢查询日志(slow query log(slow query log))?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, performance;标签: Slow Query Log, pt-query-digest)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e85e | 官方: 是 | 付费: 否
答案:
答案慢查询日志(slow query log(slow query log))中提供的信息可能非常大,某个查询也可能被列出上千次。为了以更有信息量的方式对慢查询日志(slow query log(slow query log))进行汇总,可以使用第三方工具 ‘pt-query-digest’(pt-query-digest)。
322. 如何在 MySQL(MySQL)中进行增量备份(incremental backup(incremental backup))?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, backup;标签: Incremental Backup, Percona XtraBackup)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e862 | 官方: 是 | 付费: 否
答案:
答案用户可以使用 Percona XtraBackup(Percona XtraBackup)在 MySQL(MySQL)中进行增量备份。
323. MySQL 中 DELETE TABLE 和 TRUNCATE TABLE 命令有什么区别?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, sql;标签: DELETE, TRUNCATE, Logging, Rollback)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e86e | 官方: 是 | 付费: 否
答案:
答案基本上,DELETE TABLE 是记录日志(logged)的操作,每一行被删除都会被记录,因此通常较慢。TRUNCATE TABLE 也会删除表中的行,但不会记录被删除的每一行,因此更快。TRUNCATE TABLE 可以回滚,并且在功能上类似于没有 WHERE 子句的 DELETE 语句。
324. MySQL 中有哪些 join 类型?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, sql;标签: Join, Inner Join, Left Join, Right Join, Full Join)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e873 | 官方: 是 | 付费: 否
答案:
答案MySQL 中有四种 join。Inner join 在两张表中至少有一个匹配时返回行。Left join 即使右表没有匹配,也会返回左表的所有行。Right join 即使左表没有匹配,也会返回右表的所有行。Full join 会在表之间至少有一个匹配时返回行。
325. 主键(primary key)和唯一键(unique key)有什么区别?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database, index;标签: Primary Key, Unique Key, Clustered Index, Non-clustered Index, NULL)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e87f | 官方: 是 | 付费: 否
答案:
答案两者都用于强制列的唯一性。主键会创建聚簇索引(clustered index),而唯一键会在该列上创建非聚簇索引(non-clustered index)。主键不允许 ‘NULL’,而唯一键允许。
326. 什么是事务(transaction)?ACID 特性是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database, transactions;标签: Transaction, ACID, Atomicity, Consistency, Isolation, Durability)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e883 | 官方: 是 | 付费: 否
答案:
答案事务是一个逻辑工作单元,其中所有步骤要么全部执行,要么全部不执行。ACID 是 Atomicity(原子性)、Consistency(一致性)、Isolation(隔离性)和 Durability(持久性)的缩写,它们是任何事务的属性。
327. BLOB 和 TEXT 有什么区别?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database;标签: BLOB, TEXT, TINYBLOB, LONGBLOB, MEDIUMTEXT, LONGTEXT)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e88d | 官方: 是 | 付费: 否
答案:
答案BLOB 是用于保存大量数据的二进制大对象。BLOB 有四种类型:TINYBLOB、BLOB、MEDIBLOB 和 LONGBLOB。TEXT 是大小写敏感的 BLOB。TEXT 有四种类型:TINY TEXT、TEXT、MEDIUMTEXT 和 LONG TEXT。
328. MySQL 的基本架构是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: mysql, database, architecture;标签: Connection Manager, Query Optimizer, Pluggable Engines)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e89b | 官方: 是 | 付费: 否
答案:
答案MySQL 的逻辑架构由 ‘connection manager’(连接管理器)、‘query optimizer’(查询优化器)以及 ‘pluggable engines’(可插拔引擎)构成。
329. 列出 5 个应该遵循的 JDBC 最佳实践
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 / 编程语言基础 (主题: java, jdbc, database;标签: JDBC, batch, connection pool, column name)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965de58fa809e6d38865125 | 官方: 是 | 付费: 否
答案:
答案有很多的最佳实践,你可以根据你的喜好来例举。下面是一些更通用的原则:
a)使用批量的操作来插入和更新数据
c)使用数据库连接池
d)通过列名(column name)来获取结果集(result set),不要使用列的下标(index)来获取。
330. 如何保证同一时间只有一个线程(thread)可以建立数据库连接(database connection)?
- 知识点: 数据库 / 操作系统与网络 / 编程语言基础 (主题: java;标签: synchronized, Database)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965f734fa809e6d38891edb | 官方: 是 | 付费: 否
答案:
答案可以使用同步(synchronization)机制来实现。将数据库相关代码放入使用 synchronized 关键字修饰的方法中,这样同一时间只有一个线程可以访问该方法。
331. 你对 Cloud Computing(云计算)的理解是什么?
- 知识点: 数据库 / DevOps/云 (主题: cloud-computing, compute, storage, databases;标签: Intermediate, Q5, SaaS)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6965fe98fa809e6d3889d95e | 官方: 是 | 付费: 否
答案:
答案云计算指通过互联网使用远程服务器(remote server)来存储、管理与处理数据,并运行应用程序,而不是依赖本地硬盘或自建机房。企业无需购买、搭建并维护物理数据中心(data center),就能按需获取计算、存储、数据库等能力,做到弹性扩展(elastic scaling)与成本可控。
- 典型场景:数据备份、灾难恢复、邮箱服务、开发/测试环境、网络服务与面向客户的 Web 应用等。
- 例如医疗行业可通过云服务更便捷地访问患者病史,并支持更个性化的治疗与紧急情况下的信息共享。
332. EJB容器(EJB container)提供的服务
- 知识点: 数据库 / DevOps/云 / 安全 / 编程语言基础 (主题: java, ejb, j2ee;标签: EJB Container, Lifecycle, Transactions, Security)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696700d8fa809e6d389eba74 | 官方: 是 | 付费: 否
答案:
答案主要提供声明周期管理(lifecycle management)、代码产生(code generation)、持续性管理(persistence management)、安全(security)、事务管理(transaction management)、锁(locking)和并发行管理(concurrency management)等服务。
333. 如何避免 SQL 注入(SQL injection)?
- 知识点: 数据库 / 安全 / 编程语言基础 (主题: java, security, sql;标签: SQL Injection, PreparedStatement)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69673753fa809e6d38a4054b | 官方: 是 | 付费: 否
答案:
答案- 使用预处理 PreparedStatement(prepared statement)。
- 使用正则表达式过滤掉字符串中的特殊字符。
334. 什么是缓存穿透(cache penetration)?怎么解决?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: redis, cache;标签: Redis, 缓存穿透, 空值缓存, TTL)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696753ecfa809e6d38a738cf | 官方: 是 | 付费: 否
答案:
答案
缓存穿透:指查询一个一定不存在的数据,由于缓存是不命中时需要从数据库查询,查不到数据则不写入缓存,这样导致这个不存在的数据每次请求都要到数据库去查询,造成缓存穿透。
解决方案:最简单粗暴的方法如果一个查询返回的数据为空(不管是数据不存在,还是系统故障),我们就把这个空结果进行缓存,但它的过期时间(expiration time)会很短,最长不超过五分钟。
335. 怎么保证缓存(cache)和数据库(database)数据的一致性(consistency)?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: redis, database, cache;标签: 缓存一致性, Redis, 事务, 过期时间)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696753edfa809e6d38a73a0f | 官方: 是 | 付费: 否
答案:
答案
- 合理设置缓存的过期时间。
- 新增、更改、删除数据库操作时同步更新 Redis,可以使用事务机制来保证数据的一致性。
336. Redis 怎么实现分布式锁(distributed lock)?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: redis, distributed systems;标签: Redis, 分布式锁, setnx)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696753edfa809e6d38a73a22 | 官方: 是 | 付费: 否
答案:
答案
Redis 分布式锁其实就是在系统里面占一个“坑”,其他程序也要占“坑”的时候,占用成功了就可以继续执行,失败了就只能放弃或者稍后重试。
占坑一般使用 setnx(set if not exists) 指令,只允许被一个程序占有,使用完调用 del 释放锁(release lock)。
337. Redis 分布式锁(Distributed Lock)有什么缺陷?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: redis, distributed systems;标签: Redis, 分布式锁, 超时缺陷)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696753edfa809e6d38a73a2d | 官方: 是 | 付费: 否
答案:
答案
Redis 分布式锁(Distributed Lock)不能解决超时(Timeout)的问题,分布式锁有一个超时时间(Timeout),程序的执行如果超出了锁的超时时间就会出现问题。
338. 请问人工神经网络(Artificial Neural Network, ANN)中为什么ReLu要好于Tanh和sigmoid function(Sigmoid函数)?函数图形如下:
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: deep-learning, activation-function, relu, batch-normalization;标签: ReLU, Sigmoid, Tanh, BatchNorm, Saturation, Sparsity)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69688529bc0b9904d6b56540 | 官方: 是 | 付费: 否
答案:
答案第一,采用sigmoid等函数,激活函数(Activation Function)时(指数运算),计算量大,反向传播(Backpropagation)求误差梯度(Error Gradient)时,求导涉及除法和指数运算,计算量相对大,而采用Relu激活函数,整个过程的计算量省很多。
第二,对于深层网络,sigmoid函数反向传播时,很容易就会出现梯度消失(Gradient Vanishing)的情况(在sigmoid接近饱和区时,变换太缓慢,导数趋于0,这种情况会造成信息丢失),这种现象称为饱和(Saturation),从而无法完成深层网络的训练,而ReLu就不会有饱和问题,不会有特别小的梯度出现。
第三,Relu会使一部分神经元的输出为0,这样就造成了网络的稀疏性(Sparsity),并且减少了参数的相互依存关系,缓解了过拟合(Overfitting)问题的发生(以及一些人的生物解释balabala)。当然现在也有一些对relu的改进,比如prelu(Parametric ReLU),random relu(Random ReLU)等,在不同的数据集上会有一些训练速度上或者准确率上的改进,具体的大可以找相关的paper看一看。多加一句哈,现在主流的做法,会多做一步batch normalization(批归一化,Batch Normalization),尽可能保证每一层网络的输入具有相同的分布[1]。而最新的paper[2],他们在加入bypass connection(旁路连接)之后,发现把改变batch normalization的位置会有更好的效果。
339. 如何解决梯度消失(Gradient Vanishing)和梯度膨胀(Gradient Exploding)?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: deep-learning, vanishing-gradient, exploding-gradient, batch-normalization, relu;标签: Vanishing Gradient, Exploding Gradient, ReLU, BatchNorm)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6968852fbc0b9904d6b56a46 | 官方: 是 | 付费: 否
答案:
答案(1)梯度消失(Gradient Vanishing):根据链式法则(Chain Rule),如果每一层神经元对上一层的输出的偏导乘上权重结果都小于1的话,那么即使这个结果是0.99,在经过足够多层传播之后,误差对输入层的偏导会趋于0。可以采用ReLU激活函数(Activation Function)有效的解决梯度消失的情况,也可以用Batch Normalization(批归一化)解决这个问题。关于深度学习中Batch Normalization为什么效果好?(2)梯度膨胀(Gradient Exploding)根据链式法则,如果每一层神经元对上一层的输出的偏导乘上权重结果都大于1的话,在经过足够多层传播之后,误差对输入层的偏导会趋于无穷大可以通过激活函数来解决,或用Batch Normalization解决这个问题。
340. 为什么排行榜常用 Redis Sorted Set(有序集合)?它的关键性能特征是什么?
- 知识点: 数据库 / 算法与数据结构 / 系统设计/架构 / UI/UX 设计 (主题: system-design, redis, data-structures;标签: redis, sorted set, leaderboard)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696dd4b1e6ae93548e94773f | 官方: 是 | 付费: 否
答案:
答案Sorted Set(有序集合)天然维护“元素 + 分数”的有序集合,更新(upsert)会自动按分数排序;获取某个玩家排名、获取Top N、获取某段区间都很直接。其核心优势是内存访问带来的低延迟(Low Latency),并且常见操作能在对数复杂度(Logarithmic Complexity)O(log n)完成,适合百万级玩家的实时榜单读取与更新。
341. 为什么还要把分数/榜单记录落到关系型数据库(Relational Database)?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: system-design, redis, database;标签: persistence, analytics, leaderboard)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696dd4b3e6ae93548e9479cd | 官方: 是 | 付费: 否
答案:
答案Redis更偏实时与快速查询,但对复杂分析查询、审计与长期存储不友好且成本高。将分数与榜单记录持久化到关系型数据库(Relational Database)(如 PostgreSQL)可以支持历史查询、报表分析、离线计算与数据一致性追溯;同时 Redis 作为热数据层提供实时榜单展示,两者分工明确。
342. 在关系型数据库(Relational Database)里,排行榜涉及哪些核心表?它们之间的关系如何?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: system-design, database, schema-design;标签: schema, friends leaderboard, ERD)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696dd4b8e6ae93548e947d80 | 官方: 是 | 付费: 否
答案:
答案核心表包括 Players、Games、Leaderboards、Friends。Games 与 Players 通常是 1:N(一个游戏有很多玩家记录);Games 与 Leaderboards 是 1:N(一个游戏可有多种榜单维度/周期);Players 与 Leaderboards 也是 1:N(玩家在多个榜单/周期产生记录);Friends 作为关联表描述玩家之间的关注/好友关系,用于好友圈榜单。
343. 写出 SQL(结构化查询语言,SQL):统计某个玩家本月累计得分。
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, database, analytics;标签: SQL, aggregation, leaderboard)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696dd4b8e6ae93548e947d92 | 官方: 是 | 付费: 否
答案:
答案原文给出的示例:SELECT sum(score) FROM leaderboards WHERE player_id = '42' and created_at >= "2025-03-10";
344. 写出 SQL(Structured Query Language):计算 Top 10 玩家(按总分排序)。
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, database, ranking;标签: SQL, topN, leaderboard)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696dd4b8e6ae93548e947d96 | 官方: 是 | 付费: 否
答案:
答案原文给出的示例:SELECT player_id, SUM(score) AS total FROM leaderboards GROUP BY player_id ORDER BY total DESC LIMIT 10;
345. 系统设计面试(System Design Interview)里数据库设计(Database Design)要怎么讲?包含哪些步骤与要点?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 / 编程语言基础 (主题: system-design, architecture, scalability, reliability;标签: database, schema, index, sharding, access-patterns)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696ddc00e6ae93548e957e1d | 官方: 是 | 付费: 否
答案:
答案数据库设计要围绕“数据模型(Data Model) + 访问模式(Access Pattern)”来讲:先确定实体(Entity),再确定关系(Relationship)与查询,再决定存储类型(Storage Type)与优化手段。
建议按 4 步走- 数据建模(Data Modeling):列出核心实体(用户/内容/订单等)、属性(Attribute)、主键(Primary Key),关系(一对多(One-to-Many)/多对多(Many-to-Many))。
- 选存储:结构化强一致→SQL;海量写入/灵活 schema→NoSQL;必要时混合存储。
- 设计 Schema:表/集合、字段类型、索引(按查询条件与排序字段建)、必要的外键/约束。
- 定义访问模式:列出最常见读写接口,决定是否需要反范式、预聚合、分区/分片、读写分离。
最后补一句“如何扩展”:数据增长后怎么做分片策略(Sharding Strategy)(按用户/时间/地理),以及如何做备份(Backup)、迁移(Migration)与数据一致性保证(Data Consistency Guarantee)。
346. 什么是分布式计数器(Distributed Counter)?常见应用场景有哪些?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: distributed-systems, redis, crdt;标签: distributed counter, real-time)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de47be6ae93548e966abb | 官方: 是 | 付费: 否
答案:
答案分布式计数器是在多节点(Multi-Node)环境下对同一计数值进行并发更新(Concurrent Update)与读取的系统能力,常用于“近实时展示数量”的场景。典型例子包括:页面/帖子正在浏览人数、点赞/反应数、关注者数、评论数、监控事件计数、风控/反欺诈近期行为计数、限流访问次数、推荐系统的浏览/购买计数、全站PV(Page View)与热门页面统计、网约车可用车辆数、实时投票计数等。计数通常允许最终一致(Eventual Consistency),但需要高可用(High Availability)、低延迟(Low Latency)和可扩展(Scalability)。
347. 分布式计数器在数据存储层面,SQL(Structured Query Language)与 NoSQL(Not Only SQL)的 schema(架构模式)有什么典型区别?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, nosql, cassandra, redis;标签: schema)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de486e6ae93548e9675e5 | 官方: 是 | 付费: 否
答案:
答案在关系型数据库(Relational Database)里通常是规范化建模(Normalized Modeling):users、pages、counter 等表,通过 JOIN(连接)关联;好处是冗余少、易表达关系,缺点是读路径可能更重、在高并发写入下容易成为瓶颈。NoSQL(如 Cassandra(分布式数据库))更偏向反规范化(Denormalization):以 page_id 为主键把计数与必要元数据放在同一行/同一分区(Partition)里,读写路径更短、更易横向扩展(Horizontal Scaling),但会增加冗余与一致性处理成本。Redis(远程字典服务)则常用 hash(哈希)结构把 page_id -> count 存在内存中追求极低延迟。
348. 为什么概率型数据结构(如 HyperLogLog、Count-Min Sketch)不适合用来做“准确”的分布式计数器?
- 知识点: 数据库 / 算法与数据结构 / 系统设计/架构 / UI/UX 设计 (主题: redis, data-structures;标签: HyperLogLog, Count-Min Sketch)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de486e6ae93548e9675e8 | 官方: 是 | 付费: 否
答案:
答案概率型结构(Probabilistic Data Structure)的核心优势是省空间,但以“可控误差”换取压缩。例如 HyperLogLog 适合估算基数(Cardinality)且通常不支持删除;Count-Min Sketch 适合频次估计但会高估且难以精确递减。对于题目要求“计数必须准确、可递增也可递减”的在线人数/浏览数等场景,它们会引入误差或无法正确处理退出/撤销,因此不应作为主方案。
349. 用单机关系型数据库 + 锁(mutex(互斥锁))实现计数器有什么优缺点?
- 知识点: 数据库 / 操作系统与网络 / 系统设计/架构 / UI/UX 设计 (主题: sql, concurrency;标签: mutex, locking)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de486e6ae93548e9675eb | 官方: 是 | 付费: 否
答案:
答案优点是实现简单、强一致性(Strong Consistency)容易保证:每次更新先加锁再递增/递减。缺点也很明显:在极高并发写入下锁竞争严重,吞吐(Throughput)与延迟会快速恶化;单库还存在容量与可用性上限。即使用读写锁(Read-Write Lock)降低读锁粒度,写密集场景仍难扩展到互联网级并发。
350. 在关系型数据库方案中,“本地聚合(Local Aggregation) + 批量写入(batch update)”能解决什么问题?又会带来什么代价?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, caching;标签: batching, optimistic locking)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de486e6ae93548e9675ee | 官方: 是 | 付费: 否
答案:
答案本地内存先聚合计数事件、再周期性批量写入,可以显著降低数据库写入频率,降低锁冲突,提升吞吐并节省存储写放大(Write Amplification)。但代价是计数更新会有延迟,导致展示不够准确;同时容错变差:若服务在落库前崩溃,聚合中的增量可能丢失;高并发下仍可能需要乐观锁(Optimistic Lock)/幂等控制(Idempotency Control)来处理并发与重放。
351. 把每次计数更新写成“独立记录”(append-only)为什么更适合高并发写(high-concurrency writes)?读会怎么优化?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, event-sourcing, caching;标签: append-only, event log)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de486e6ae93548e9675f1 | 官方: 是 | 付费: 否
答案:
答案将每次更新写成一条独立事件记录(event record),可以避免对同一行加锁,天然支持极高并发写入(concurrent writes)。缺点是读取最新计数可能需要聚合(aggregation)或全表扫描(full table scan),读变慢且存储成本(storage cost)上升。常见优化是为 updated_at(或版本号(version number))建立索引(index)、或维护物化视图(materialized view)/汇总表(summary table),甚至把“最新值”放到缓存层(cache layer),事件表只做审计(audit)与回放(replay)。
352. 为什么“关系型数据库(relational database)+ leader-follower 复制(replication)”在互联网级分布式计数器(distributed counter)上容易出现写拥塞(write congestion)?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: sql, replication, distributed-systems;标签: leader-follower, write bottleneck)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de486e6ae93548e9675f7 | 官方: 是 | 付费: 否
答案:
答案计数器是强写密集(write-intensive)且高并发更新(high-concurrency update)的场景,leader-follower 拓扑(topology)下写入集中到 leader,容易在磁盘 IO、锁(locking)与事务日志(transaction log)上形成拥塞;跨地域复制(geo-replication)还会带来复制延迟(replication lag),使多机房写入更难。为了避免单点故障(SPOF)可能引入 leader-leader,但又需要额外冲突解决(conflict resolution)与幂等保障(idempotency guarantee),而计数器对事务能力(transactional capability)需求并不强,通常更偏向选择更适合高并发写与冲突合并的存储(如 CRDT/内存计数(in-memory counter)/专用计数服务(dedicated counting service))。
353. 如果题目要求“准确且低存储”,你会如何在“去重(deduplication)、幂等(idempotency)、退出递减”之间做设计?
- 知识点: 数据库 / 操作系统与网络 / 系统设计/架构 / UI/UX 设计 (主题: redis, idempotency, websocket;标签: dedup, TTL)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de48be6ae93548e9679d3 | 官方: 是 | 付费: 否
答案:
答案核心是把“进入/退出”建模为可去重的事件(deduplicable event):为每个会话(session)生成 sessionId,并对 enter/exit 事件赋予幂等键(idempotency key)(pageId+sessionId+eventType)。存储层保存最新计数(整数或分片整数)即可;为防止重复递增/递减,引入短期去重表(dedup table)(可用 Redis set/bitmap+TTL)记录已处理事件,TTL 覆盖可能的重试窗口(retry window)。退出递减依赖显式 exit 或心跳超时(heartbeat timeout)回收;这样既能保持准确,又避免为每个用户永久存一条在线记录。
354. LSM Tree 对计数器读写性能有什么影响?为什么“写快读慢”会成为痛点?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: distributed-systems, cassandra, storage;标签: LSM, read amplification, performance)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de6ae623565038f404ba9 | 官方: 是 | 付费: 否
答案:
答案LSM Tree 通过顺序写入(sequential write)与合并压缩(compaction)来换取高吞吐写入,非常适合写多场景;但读取往往需要查多层 SSTable、Bloom Filter、合并多个段(segment),遇到高频读取(例如页面实时在线人数)时会产生更多磁盘访问与放大效应(amplification effect),导致读延迟(read latency)抖动。计数器通常是写多也读多,如果读路径频繁触盘,就会把“实时展示”拖慢,因此会引入 Redis 之类缓存层(cache layer)来减轻读压力。
355. 给 Cassandra 前面加 Redis 做 cache-aside,为什么可能让计数更不准?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: distributed-systems, redis, cassandra, caching;标签: cache-aside, consistency, stale reads)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de6ae623565038f404bac | 官方: 是 | 付费: 否
答案:
答案cache-aside 需要在写入数据库后(或前)同步刷新缓存,但在分布式环境(distributed environment)里“DB 写成功、缓存更新失败/延迟”是常见故障模式(failure mode)。计数器的值对用户展示敏感:如果读优先命中缓存,就会读到旧值;如果又叠加重试机制(retry mechanism),缓存与数据库的状态更容易出现短暂分叉。由于该方案本质上是弱一致(weak consistency)并且对更新链路的成功与顺序很敏感,准确计数的风险反而更高。
356. 什么是计数器系统里的 Push Model 与 Pull Model?各自的优缺点是什么?
- 知识点: 数据库 / 算法与数据结构 / 系统设计/架构 / UI/UX 设计 (主题: distributed-systems, messaging, databases;标签: push model, pull model, queue)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696de6ae623565038f404bb0 | 官方: 是 | 付费: 否
答案:
答案Push model(推送模型):每次计数变化都直接写数据库,延迟低、实时性强、实现简单,但在超高写入并发下数据库容易成为瓶颈。Pull model(拉取模型):客户端/网关把更新事件先写入消息队列(message queue),后台按批次周期性消费并落库,能削峰填谷、减少跨机房带宽、降低 DB 压力,并可配 DLQ(死信队列)提升容错;缺点是链路更复杂、处理异步导致短时间不准,而且队列很难保证严格 exactly-once(精确一次),从而影响准确性。
357. 什么是数据库规范化(Normalization)?它为什么重要?
- 知识点: 数据库 (主题: databases;标签: normalization, database, schema, sql)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f113f120fcc1591159293 | 官方: 是 | 付费: 否
答案:
答案规范化通过拆表与建立关系减少冗余、避免更新异常(update anomaly),提高一致性与可维护性;常见 1NF/2NF/3NF 逐步消除不合理依赖。代价是更多 JOIN 可能影响读性能,因此要结合索引、缓存或适度反规范化(denormalization)做权衡。
358. BatchNorm(BN,批归一化)和 LayerNorm(LN,层归一化)有什么区别?各自适用场景?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: deep-learning, normalization;标签: BatchNorm, LayerNorm, Transformer, CNN)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f13d5120fcc159115c5b2 | 官方: 是 | 付费: 否
答案:
答案BN 与 LN 的区别主要在“归一化的维度”和“是否依赖 batch 统计”。BN 按特征维度跨 batch 归一化,适合卷积网络(CNN)等 batch 较大、分布稳定的场景;LN 按样本内部各层归一化,不依赖 batch 大小(batch size),适合循环网络(RNN/Transformer)等序列或小 batch 场景,在分布式训练(distributed training)中也更稳定。
- BN:对每个通道/特征在 batch 维度上做均值方差归一化;训练依赖 batch 统计,推理用滑动平均。适合 CNN、batch 较大且分布稳定的场景。
- LN:对单个样本在特征维度上归一化,不依赖 batch 大小;对小 batch 更稳,Transformer/序列模型常用 LN。
工程上:小 batch、分布变化大、序列任务优先 LN(Layer Normalization);大 batch 的视觉任务 BN(Batch Normalization)往往效果好。
359. 数据独立性有哪些类型?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: dbms, data-modeling;标签: 逻辑独立性, 物理独立性, schema演进)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6ce0 | 官方: 是 | 付费: 否
答案:
答案两类:①逻辑数据独立性——改变逻辑结构(表、字段、关系)对应用影响尽可能小,例如新增表或字段不破坏既有功能;②物理数据独立性——改变物理存储(索引、分区、存储介质、文件组织方式)不影响逻辑层与应用访问方式。一般来说,物理独立性更容易实现,逻辑独立性更难。
360. 解释 DBMS(Database Management System)的 ACID 特性。
- 知识点: 数据库 (主题: dbms, transactions;标签: ACID, 并发控制, 持久化)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d3b | 官方: 是 | 付费: 否
答案:
答案ACID:①原子性(Atomicity)——事务要么全做要么全不做;②一致性(Consistency)——事务前后都满足约束与业务规则;③隔离性(Isolation)——并发事务互不干扰,中间状态不被其他事务看到(通过隔离级别/锁/MVCC(Multi-Version Concurrency Control)等实现);④持久性(Durability)——一旦提交,结果可在故障后恢复(日志/WAL(Write-Ahead Logging)/刷盘机制)。
361. DBMS(Database Management System)中自连接(Self Join)有什么用途?
- 知识点: 数据库 (主题: dbms, sql;标签: Self Join, 层级关系, 表别名)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d54 | 官方: 是 | 付费: 否
答案:
答案自连接是同一张表与自己进行JOIN(通过别名区分),用于表达表内的层级或关联关系,例如“员工-经理”同表结构、树形父子关系、同类对象的配对比较等。关键点是:必须使用表别名,明确连接条件,避免把整表做笛卡尔积。
362. 解释 1NF(First Normal Form)、2NF(Second Normal Form)、3NF(Third Normal Form)。
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: dbms, data-modeling;标签: 1NF, 2NF, 3NF)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d5d | 官方: 是 | 付费: 否
答案:
答案1NF(First Normal Form):字段原子性,每列不可再拆、无重复组;2NF(Second Normal Form):在1NF基础上,非主属性完全依赖于“整个主键”(消除对复合主键的部分依赖);3NF(Third Normal Form):在2NF基础上,非主属性不依赖于其他非主属性(消除传递依赖)。实战上常用3NF保证一致性,再按查询需求做适度反规范化或引入维度模型。
363. DROP 和 TRUNCATE 有什么区别?
- 知识点: 数据库 (主题: dbms, sql;标签: DROP, TRUNCATE, DDL/DML)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d65 | 官方: 是 | 付费: 否
答案:
答案DROP 删除数据库对象本身(如表/视图),结构与数据都被移除;TRUNCATE 仅清空表数据但保留表结构,通常更快且会重置自增计数(依数据库实现)。TRUNCATE 往往是DDL级操作,回滚与日志行为也可能与DELETE不同,面试可补充:DELETE 是逐行删除可带WHERE,TRUNCATE 通常不能带WHERE。
364. DBMS(Database Management System)中 intension 和 extension 分别是什么意思?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: dbms, data-modeling;标签: schema, metadata, data instances)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d6d | 官方: 是 | 付费: 否
答案:
答案Intension(内涵)指数据库的模式/元数据/设计蓝图:表结构、约束、关系、数据类型等;Extension(外延)指某一时刻数据库中真实存储的数据实例(具体记录集合)。内涵相对稳定,外延会随插入、更新、删除不断变化。面试时用“schema vs data”类比最直观。
365. SQL(Structured Query Language)中如何进行模式匹配(pattern matching)?
- 知识点: 数据库 (主题: dbms, sql;标签: LIKE, 通配符, 查询性能)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 696f3cde120fcc15911c6d76 | 官方: 是 | 付费: 否
答案:
答案常用 LIKE 进行模式匹配:% 表示任意长度字符(含0个),_ 表示任意单个字符,例如 name LIKE 'A%'; code LIKE '12_4'。进阶可提:使用 ESCAPE 处理通配符本身;某些数据库支持正则(REGEXP)实现更强匹配。注意:LIKE 在大表上可能无法走索引(尤其前缀为%),需结合索引策略或全文检索。
366. 什么是 DBMS(Database Management System)?相比传统文件系统它有什么优势?
- 知识点: 数据库 (主题: database;标签: DBMS)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- id: 696f4e72120fcc15911fb568 | 官方: 是 | 付费: 否
答案:
A database management system (DBMS) is a computerized data storage system that enables users to perform operations such as data manipulation and database structure maintenance.
数据库管理系统(DBMS)是一种计算机化数据存储系统,使用户能够执行数据操作和数据库结构维护等操作。
Benefits over traditional file systems:
相对于传统文件系统的优势:
- Better data management: better-managed access and updates.
- Data security: stronger privacy/security controls.
- Reduced data inconsistency: minimizes multiple conflicting copies.
- Faster data access: improves query response and accuracy for large datasets.
367. 解释数据库事务(Transaction)的 ACID 特性。
- 知识点: 数据库 (主题: database, sql;标签: ACID)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- id: 696f4e72120fcc15911fb570 | 官方: 是 | 付费: 否
答案:
ACID properties:
ACID属性:
- Atomicity: all-or-nothing; transaction either fully completes or aborts.
- Consistency: integrity constraints must hold before and after the transaction.
- Isolation: concurrent transactions do not interfere; intermediate changes aren't visible until committed.
- Durability: once committed, changes persist even after system failures (stored in non-volatile memory).
368. 数据建模(Data Modeling)与数据库设计(Database Design)有什么不同?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: data-modeling, database)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 697035b6120fcc15912ebd77 | 官方: 是 | 付费: 否
答案:
答案数据建模(Data Modeling):可以把它看作数据库设计的第一步。数据建模会基于不同数据模型(Data Model)之间的关系,创建一个概念模型(Conceptual Model)。该过程通常从概念阶段逐步过渡到逻辑模型(Logical Model),再到物理模式(Schema)。它强调使用系统化的方法来应用数据建模技术。
数据库设计(Database Design):指设计数据库的过程。数据库设计会产出数据库的详细数据模型。严格来说,数据库设计包含数据库的详细逻辑模型(Logical Model),但也可能包括物理设计选择与存储参数(Storage Parameter)。
369. 说明 HAVING 子句(HAVING Clause)与 WHERE 子句(WHERE Clause)之间的区别。
- 知识点: 数据库 (主题: sql;标签: SQL, WHERE, HAVING, GROUP BY)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69718912120fcc1591508068 | 官方: 是 | 付费: 否
答案:
答案WHERE 与 HAVING 的区别(将表格内容转为文字描述):
- Implemented in(执行层面):WHERE:行级操作(Row operations);HAVING:列级操作(Column operations)。
- Applied to(作用对象):WHERE:单行数据(A single row);HAVING:汇总后的行或分组(The summarized row or groups)。
- Used for(用途):WHERE:按给定条件从特定行中获取特定数据(Fetching specific data from specific rows according to the given condition);HAVING:获取汇总后的整体数据,并按给定条件进行筛选/分离(Fetching the entire data and separating according to the given condition)。
- Aggregate functions(聚合函数):WHERE:不能使用聚合函数(Cannot have them);HAVING:可以使用聚合函数(Can have them)。
- Statements(可用于的语句):WHERE:可用于 SELECT、UPDATE、DELETE(Can be used with SELECT, UPDATE, and DELETE);HAVING:离开 SELECT 语句无法使用(Cannot be used without a SELECT statement)。
- GROUP BY clause(与 GROUP BY 的关系):WHERE:GROUP BY 在 WHERE 之后(Comes after the WHERE clause);HAVING:GROUP BY 在 HAVING 之前(Comes before the HAVING clause)。
370. 解释 SQL 命令(SQL Command)的不同类型。
- 知识点: 数据库 (主题: sql;标签: SQL, DDL, DML, DCL, TCL)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69718eee120fcc15915153ae | 官方: 是 | 付费: 否
答案:
答案思维导图(转为文字描述):SQL Language 可分为 DML(Data Manipulation Language)(Select、Insert、Update、Delete)、DDL(Data Definition Language)(Create、Alter、Drop)、DCL(Data Control Language)(Grant、Revoke)以及 TCL(Transaction Control Language)(Begin、Tran、Commit、Rollback)。
- 数据定义语言(DDL):数据定义语言(DDL):DDL 是 SQL 中用于定义数据库数据结构的部分,通常在数据库即将创建的初始阶段使用。它主要用于创建和重构数据库对象。DDL 中的命令包括:Create table、Alter table、Drop table。
- 数据操纵语言(DML):数据操纵语言(DML):DML 用于操作数据库中已经存在的数据。也就是说,它帮助用户检索并处理数据。它可用于执行如下操作:通过 insert 命令向数据库插入数据,通过 update 命令更新数据,以及通过 delete 命令从数据库中删除数据。
- 数据控制语言(DCL):数据控制语言(DCL):DCL 用于控制对数据库中数据的访问。DCL 命令通常用于创建与用户访问相关的对象,并控制用户之间权限(privileges)的分配。DCL 中使用的命令是 Grant 和 Revoke。
- 事务控制语言(TCL):事务控制语言(TCL):它用于控制由 DML 命令所带来的更改。它也用于授权将多条语句组合在一起,形成逻辑事务。TCL 中使用的命令包括 Commit、Rollback、Savepoint、Begin 和 Transaction。
371. 什么是默认约束(Default Constraint)?
- 知识点: 数据库 (主题: sql;标签: constraints, default constraint)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69719059120fcc15915176db | 官方: 是 | 付费: 否
答案:
答案约束(Constraint)用于为数据处理指定一些规则,并限制可以进入表中的数据类型。现在,让我们来理解默认约束(Default Constraint)。
默认约束(Default Constraint):用于为某一列定义一个默认值,这样当插入新记录且未指定该列的其他值时,就会自动为该列填充默认值。例如,如果我们为下面示例表中的 E_salary 列设置默认约束,并将默认值设为 85000,那么在插入数据时只要没有为该列指定其他值,该列的所有记录都会使用默认值 85000。
示例表(文字描述):列为 E_id、E_name、E_salary、E_gender、E_dept;数据行:1) (1, Sam, 85000, Male, Analytics);2) (2, Anne, 85000, Male, Analytics);3) (3, Julia, 85000, Female, Analytics)。
现在,让我们看看如何设置默认约束。我们将从创建一个新表开始,并在其中一列上添加默认约束。
Code:
代码:
create table stu1(s_id int, s_name varchar(20), s_marks int default 50)
create table stu1(s_id int, s_name varchar(20), s_marks int default 50)
select *stu1Output(文字描述):输出表头为 s_id、s_name、s_marks。
现在,我们将插入记录。
Code:
代码:
insert into stu1(s_id,s_name) values(1,'Sam')
insert into stu1(s_id,s_name) values(1,'Sam')
insert into stu1(s_id,s_name) values(2,'Bob')
insert into stu1(s_id,s_name) values(2,'Bob')
insert into stu1(s_id,s_name) values(3,'Matt')
insert into stu1(s_id,s_name) values(3,'Matt')
select *from stu1Output(文字描述):列为 s_id、s_name、s_marks;数据行:1) (1, Sam, 50);2) (2, Bob, 50);3) (3, Matt, 50)。
372. 如何从下表(table)中找到第二高的薪资(salary)?
- 知识点: 数据库 (主题: sql;标签: SQL, Aggregate, Second Highest Salary)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971bd741f88a3acd71090af | 官方: 是 | 付费: 否
答案:
答案employee 表(table)(示例数据(sample data)):
| e_id | e_name | E_salary | e_age | e_gender | e_dept |
|---|---|---|---|---|---|
| 1 | Sam | 95000 | 45 | Male | Operations |
| 2 | Bob | 80000 | 21 | Male | Support |
| 3 | Anne | 125000 | 25 | Female | Analytics |
| 4 | Julia | 73000 | 30 | Female | Analytics |
| 5 | Matt | 159000 | 33 | Male | Sales |
| 6 | Jeff | 112000 | 27 | Male | Operations |
| 代码(code): |
select * from employee
select * from employee
select max(e_salary) from employee where e_salary not in (select max(e_salary) from employee)输出(output):
(No column name)
(无列名)
125000
373. 什么是唯一约束(UNIQUE constraint)?
- 知识点: 数据库 (主题: sql;标签: SQL, Constraint, UNIQUE)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971bf431f88a3acd710b2c6 | 官方: 是 | 付费: 否
答案:
答案唯一约束(UNIQUE constraint)确保某一列中的所有值都彼此不同。例如,如果我们在下面表格中的 e_name 列上添加唯一约束(UNIQUE constraint),那么该列中的每一条记录都必须是唯一值(unique value)。
示例表(table)(employee):
| e_id | e_name | E_salary | e_age | e_gender | e_dept |
|---|---|---|---|---|---|
| 1 | Sam | 95000 | 45 | Male | Operations |
| 2 | Bob | 80000 | 21 | Male | Support |
| 3 | Anne | 125000 | 25 | Female | Analytics |
| 4 | Julia | 73000 | 30 | Female | Analytics |
| 5 | Matt | 159000 | 33 | Male | Sales |
| 6 | Jeff | 112000 | 27 | Male | Operations |
| 首先,我们将创建一张表(table)。 |
create table stu2(s_id int unique, s_name varchar(20))现在,我们将插入记录(record)。
insert into stu2 values(1,’Julia’)
insert into stu2 values(1,’Julia’)
insert into stu2 values(2,’Matt’)
insert into stu2 values(2,’Matt’)
insert into stu2 values(3,’Anne’)输出(output):
| s_id | s_name |
| 1 | Julia |
| 2 | Matt |
| 3 | Anne |
374. 什么是索引(Index)?
- 知识点: 数据库 (主题: sql, database;标签: index, performance, where clause)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971c5261f88a3acd711c2f9 | 官方: 是 | 付费: 否
答案:
答案索引(Index)可以帮助加快数据库(database)中的搜索速度。如果在 WHERE 子句(WHERE clause)所涉及的列上没有索引(Index),SQL Server 就必须扫描整张表(table)并逐行检查以找到匹配项,这在大数据量场景下可能导致操作变慢。
索引(Index)用于先定位与某些列条件匹配的行集合,然后仅在这些数据子集上进行扫描与匹配。
语法(Syntax):
CREATE INDEX INDEX_NAME ON TABLE_NAME (COLUMN)
CREATE INDEX INDEX_NAME ON TABLE_NAME (COLUMN)
375. 解释索引(Index)的类型。
- 知识点: 数据库 (主题: sql, database;标签: index, single-column, composite, unique)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971c5261f88a3acd711c2fe | 官方: 是 | 付费: 否
答案:
答案索引(Index)的类型包括:
- 单列索引(Single-column Index)
- 复合索引(Composite-column Index)
唯一索引(Unique Index)
单列索引(Single-Column Index):单列索引只针对表中的一个列创建。
语法(Syntax):
CREATE INDEX index_nameCREATE INDEX index_name
ON table_name(column_name);复合索引(Composite Index):复合索引是针对表中的两个或多个列创建的索引。
语法(Syntax):
CREATE INDEX index_name
CREATE INDEX index_name
ON table_name (column1, column2)唯一索引(Unique Index):唯一索引用于维护表的数据完整性,它不允许向表中插入重复值。
语法(Syntax):
CREATE UNIQUE INDEX index
CREATE UNIQUE INDEX index
ON table_name(column_name)Now, let's move on to the next question in this ‘Top SQL Interview Questions’ blog.
ON table_name(column_name)现在,让我们继续这个“顶级SQL面试问题”博客中的下一个问题。
376. 什么是外键(Foreign Key)?
- 知识点: 数据库 / UI/UX 设计 (主题: sql, database;标签: foreign key, sql constraint, database design)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971cd3b1f88a3acd712a90a | 官方: 是 | 付费: 否
答案:
答案外键(Foreign Key)是一个属性或一组属性,用于引用另一张表中的主键(Primary Key)。本质上,外键用于将两张表关联起来。
下面通过示例来说明外键的作用。
Persons 表(示例数据):
| PersonID | LastName | FirstName | Age |
|---|---|---|---|
| 1 | Rehman | Sayeedul | 30 |
| 2 | Soni | Anand | 23 |
| 3 | Singh | Abhishek | 20 |
Orders 表(示例数据):
| OrderID | OrderNumber | PersonID |
|---|---|---|
| 1 | 90000 | 3 |
| 2 | 135000 | 3 |
| 3 | 77000 | 2 |
| 4 | 154000 | 1 |
在 Orders 表中,PersonID 列作为外键(Foreign Key),引用 Persons 表中的 PersonID 主键(Primary Key)。
创建包含外键的表的 SQL 示例:
CREATE TABLE Orders (
CREATE TABLE Orders (
OrderID INT NOT NULL,
OrderID INT NOT NULL,
OrderNumber INT NOT NULL,
OrderNumber INT NOT NULL,
PersonID INT,
PersonID INT,
PRIMARY KEY (OrderID),
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
377. 请说明聚簇索引(Clustered Index)与非聚簇索引(Non-clustered Index)的区别。
- 知识点: 数据库 (主题: sql, database, index;标签: SQL, Index, Clustered Index, Non-clustered Index)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971ceca1f88a3acd712ddba | 官方: 是 | 付费: 否
答案:
答案聚簇索引(Clustered Index):它用于按照键值对数据行进行排序。聚簇索引就像电话簿的目录:我们可以翻到“David”(例如 David, Thompson)那一页,并且找到所有 David 的信息都紧挨着排列。由于数据在物理上彼此相邻,它对基于范围(Range-based)的查询获取数据非常有帮助。另外,聚簇索引与数据的存储方式密切相关;一张表只能有一个聚簇索引,因为每张表只能按一种方式进行物理排序。
非聚簇索引(Non-clustered Index):它将数据存放在一个位置,而索引存放在另一个位置。索引中包含指针,用于指向数据所在的位置。由于非聚簇索引的索引结构与数据行分开存储,所以一张表可以有多个非聚簇索引。
下面是聚簇索引(Clustered Index)与非聚簇索引(Non-Clustered Index)的主要差异:
| Parameters 参数 | Clustered Index 聚集索引 | Non-clustered Index 非聚集索引 |
|---|---|---|
| Used for 用途 | Sorting and storing records physically in memory 在内存中物理排序和存储记录 | Creating a logical order for data rows. Pointers are used for physical data files 为数据行创建逻辑顺序。使用指针指向物理数据文件 |
| Methods for storing 存储方法 | Stores data in the leaf nodes of the index 在索引的叶节点中存储数据 | Never stores data in the leaf nodes of the index 从不在索引的叶节点中存储数据 |
| Size 大小 | Quite large 相当大 | Comparatively, small 相对较小 |
| Data accessing 数据访问 | Fast 快速 | Slow 慢速 |
| Additional disk space 额外磁盘空间 | Not required 不需要 | Required to store indexes separately 需要单独存储索引 |
| Type of key 键类型 | By default, the primary key of a table is a clustered index 默认情况下,表的主键是聚集索引 | It can be used with the unique constraint on the table that acts as a composite key 可用于表上的唯一约束,作为复合键 |
| Main feature 主要特性 | Improves the performance of data retrieval 提高数据检索性能 | Should be created on columns used in Joins 应创建在用于连接(Joins)的列上 |
378. 请说明 SQL(Structured Query Language)和 PL/SQL(Procedural Language/Structured Query Language)的区别。
- 知识点: 数据库 (主题: sql, plsql, database;标签: SQL, PL/SQL, Comparison)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971d2bf1f88a3acd7135b31 | 官方: 是 | 付费: 否
答案:
答案SQL(Structured Query Language)和 PL/SQL(Procedural Language/Structured Query Language)之间主要有以下区别:
首先,SQL(Structured Query Language)是一种用于数据库的结构化查询语言,而 PL/SQL(Procedural Language/Structured Query Language)是一种基于 SQL 的数据库编程语言。
其次,SQL 通常以单条语句的形式存在,主要用于执行 DML(Data Manipulation Language)(如 SELECT、INSERT、UPDATE、DELETE)和 DDL(Data Definition Language)(如 CREATE、ALTER、DROP)命令;而 PL/SQL 是由代码块组成的,可以用于编写完整的存储过程(Procedure)或函数(Function)。
在语言特性方面,SQL 是一种声明式、面向数据的语言,关注的是“要什么结果”;而 PL/SQL 是一种过程式、面向应用的语言,关注的是“如何一步步实现逻辑”。
在使用场景上,SQL 主要用于对数据库中的数据进行操作和查询,而 PL/SQL 通常用于创建数据库应用程序和复杂的业务逻辑。
另外,SQL 直接与数据库服务器交互,而 PL/SQL 本身并不直接提供这种交互能力,它是运行在数据库内部的程序单元。
最后,SQL 语句中不能包含 PL/SQL 代码;而 PL/SQL 可以包含 SQL 语句,因为 PL/SQL 本质上是 SQL 的扩展。
379. DELETE 和 TRUNCATE(TRUNCATE TABLE)命令有什么区别?
- 知识点: 数据库 (主题: sql;标签: dml, ddl, delete, truncate)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971d9241f88a3acd7144f39 | 官方: 是 | 付费: 否
答案:
答案DELETE:该查询用于删除或移除一个或多个已存在的表。
TRUNCATE(TRUNCATE TABLE):该语句会删除表中的所有数据。
DELETE 和 TRUNCATE(TRUNCATE TABLE)的区别如下:
- TRUNCATE 是 DDL 命令,DELETE 是 DML 命令。
- TRUNCATE 不能真正执行并触发 trigger,而 DELETE 可以触发 trigger。
如果某表被外键约束引用,TRUNCATE 无法工作。因此,如果存在外键,就必须使用 DELETE 命令。
DELETE 命令语法:
DELETE FROM table_nameDELETE FROM table_name
[WHERE condition];示例:
select * from stu输出:
| s_id | s_name | s_marks |1 Sam 50 2 Bob 50 3 Julia 50 delete from stu where s_name='Bob'输出:
| s_id | s_name | s_marks |
|---|---|---|
| 1 | Sam | 50 |
| 3 | Julia | 50 |
| TRUNCATE 命令(Command)语法: |
TRUNCATE TABLE
TRUNCATE TABLE
Table_name;示例:
select * from stu1输出:
| s_id | s_name | s_marks |
| 1 | Sam | 50 |
|---|---|---|
| 2 | Bob | 50 |
| 3 | Matt | 50 |
| truncate table stu1输出: | ||
| s_id | s_name | s_marks |
| This deletes all the records from the table. |
380. 你如何理解数据库的规范化(Normalization)与反规范化(Denormalization)?
- 知识点: 数据库 (主题: sql, database;标签: Normalization, Denormalization)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971dd2e1f88a3acd714df65 | 官方: 是 | 付费: 否
答案:
答案Normalization:用于通过在数据库中组织字段和表来减少数据冗余(Data Redundancy)与依赖(Dependency)。它涉及构建表并根据某些规则为这些表建立关系。通过这些规则可以去除冗余和不一致的依赖,使其更灵活。
Denormalization:与规范化相反。在这种情况下,我们基本上通过添加冗余数据来加快涉及多个表 join(连接)的复杂查询(Query)。这里我们尝试通过添加冗余数据或对数据进行分组来优化数据库的读取性能(Read Performance)。
381. 下面给出的 SQL 查询(SQL Query)有什么问题?
- 知识点: 数据库 (主题: sql, database;标签: GROUP BY, HAVING, WHERE, Aggregate)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971dd2e1f88a3acd714df8c | 官方: 是 | 付费: 否
答案:
答案SQL Query:
SELECT gender, AVG(age) FROM employee WHERE AVG(age)>30 GROUP BY genderWhen we execute this command, we get the following error:
当执行此命令时,我们会得到以下错误:
Msg 147, Level 16, State 1, Line 1
消息147,级别16,状态1,第1行
Aggregation may not appear in the WHERE clause unless it is in a subquery
聚合函数不得出现在WHERE子句中,除非它位于子查询中
contained in a HAVING clause or a select list, the column being aggregated is
包含在HAVING子句或选择列表中,被聚合的列是
an outer reference.
外部引用。
Msg 147, Level 16, State 1, Line 1
消息147,级别16,状态1,第1行
Invalid column name 'gender'.说明:当我们在使用聚合函数(Aggregate Function)并且使用 GROUP BY 时,不能使用 WHERE 子句(Clause)来过滤聚合结果。因此,应该用 HAVING 子句替代 WHERE。
另外,当我们使用 HAVING 子句时,GROUP BY 应该先出现,HAVING 应该在其后。
Correct query example:
正确查询示例:
select e_gender, avg(e_age) from employee group by e_gender having avg(e_age)>30Output(示例):
| e_gender | (No column name)
(无列名) |
| Male 男 | 31 |
382. 你了解 stuff() 函数(Function)吗?
- 知识点: 数据库 / 算法与数据结构 (主题: sql, database;标签: String Function, STUFF)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971dd2e1f88a3acd714df91 | 官方: 是 | 付费: 否
答案:
答案stuff 函数会删除字符串的一部分,然后从指定位置开始把另一部分插入到字符串中。
Syntax:
语法:
STUFF(String1, Position, Length, String2)这里,String1 是将被覆盖的字符串。Position 表示覆盖开始的位置。Length 是被替换子串的长度,String2 是用来覆盖 String1 的字符串。
Example:
示例:
select stuff('SQL Tutorial',1,3,'Python')这会把 ‘SQL Tutorial’ 改成 ‘Python Tutorial’。
Output:
输出:
Python Tutorial
Python教程
383. 什么是视图(Views)?请举例说明。
- 知识点: 数据库 (主题: sql, database;标签: View, SQL Views)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971dd2e1f88a3acd714df96 | 官方: 是 | 付费: 否
答案:
答案Views 是虚拟表(Virtual Table),用于限制我们想要显示的表,并且它们只是 SQL 语句的结果,本身没有与之关联的实体对象。由于视图并非真正存在,因此占用更少的存储空间。
Let’s consider an example. 在下面的 employee 表中,假设我们想对性别为 ‘Female’ 的记录执行多次操作。我们可以从整个 employee 表中创建一个仅包含女性员工记录的 view-only 表。现在我们在 SQL server 上实现它。
Below is our employee table:
以下是我们的员工表:
select * from employeeemployee(示例数据):
| e_id | e_name | e_salary | e_age | e_gender | e_dept |
| 1 | Sam | 95000 | 45 | Male | Operations |
| 2 | Bob | 80000 | 21 | Male | Support |
| 3 | Anne | 125000 | 25 | Female | Analytics |
| 4 | Julia | 112000 | 30 | Female | Analytics |
| 5 | Matt | 159000 | 33 | Male | Sales |
| 6 | Jeff | 112000 | 27 | Male | Operations |
| Now, we will write the syntax for view. |
Syntax:
语法:
create view female_employee as select * from employee where e_gender='Female'
create view female_employee as select * from employee where e_gender='Female'
select * from female_employeeOutput:
select * from female_employee
| e_id | e_name | e_salary | e_age | e_gender | e_dept |
输出:
| 3 | Anne | 125000 | 25 | Female | Analytics |
| 4 | Julia | 112000 | 30 | Female | Analytics |
384. 什么是存储过程(Stored Procedure)?请举例说明。
- 知识点: 数据库 (主题: sql, database;标签: Stored Procedure, Procedure)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971dd2e1f88a3acd714df9b | 官方: 是 | 付费: 否
答案:
答案存储过程是一段可保存并复用的预编译 SQL 代码。换句话说,我们可以将存储过程视为一个由多条 SQL 语句组成的函数,用于访问数据库系统。我们可以将多条 SQL 语句整合到一个存储过程中,并在需要的任何时候执行它们。
存储过程可以作为模块化编程的一种方式,即:创建一次存储过程、保存,然后按需多次调用。与执行多个查询相比,这也支持更快的执行。
Syntax:
语法:
CREATE PROCEDURE procedure_name
CREATE PROCEDURE procedure_name
AS
AS
Sql_statement
要执行,我们将使用:
GO;
GO;
To execute we will use this:
示例:
EXEC procedure_nameExample:
我们将创建一个存储过程,用于提取员工的年龄。
We are going to create a stored procedure that will help extract the age of the employees.
create procedure employee_age
create procedure employee_age
创建存储过程 employee_age
as
作为
select e_age from employee
从员工表中选择e_age
go
执行
Now, we will execute it.
现在,我们将执行它。
exec employee_ageOutput:
执行employee_age员工年龄输出:
| e_age |
| 45 |
| 21 |
| 25 |
| 30 |
| 33 |
| 27 |
385. 你对 SQL 的 JOIN 了解多少?请定义不同类型的 JOIN。
- 知识点: 数据库 (主题: sql, database;标签: sql, join)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971e3201f88a3acd715efea | 官方: 是 | 付费: 否
答案:
答案JOIN 子句用于基于两个或多个表之间的相关列,将它们的行组合在一起。JOIN 的类型取决于表之间的关系,不同类型的 JOIN 可用于检索数据。
JOIN 主要有四种类型:
- Inner Join(内连接):返回在两张表中都有匹配值的记录。
- Left Join(左连接):返回两张表共有的行,以及左表(left-hand-side table)的所有行;即使右表没有匹配,也会返回左表的所有行。
- Right Join(右连接):返回两张表共有的行,以及右表(right-hand-side table)的所有行;即使左表没有匹配,也会返回右表的所有行。
- Full Join(全连接):返回左表的所有行以及右表的所有行。
386. 解释什么是 Inner Join(内连接)。
- 知识点: 数据库 (主题: sql, database;标签: sql, inner-join)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971e3201f88a3acd715efee | 官方: 是 | 付费: 否
答案:
答案Inner Join 基本上会返回两张表中具有匹配值的记录。
假设我们有两张表 Table A 和 Table B。当我们对这两张表使用 Inner Join 时,我们只会得到同时存在于 Table A 和 Table B 的公共记录。
Syntax:
语法:
SELECT columns
SELECT columns
FROM table1
FROM table1
INNER JOIN table2
INNER JOIN table2
ON table1.column_x=table2.column_y;Example:
基于表1.column_x=表2.column_y;示例:
select * from employee
select * from employee
select * from departmentOutput:
从部门表中选择所有列输出:
| d_id | d_name | d_location |
| 1 | Content 内容 | New York 纽约 |
| 2 | Support 支持 | Chicago 芝加哥 |
| 3 | Analytics 分析 | New York 纽约 |
| 4 | Sales 销售 | Boston 波士顿 |
| 5 | Tech | Dallas |
| 6 | Finance | Chicago |
| 现在,我们会对这两张表进行 Inner Join,其中 employee 表中的 ‘e_dept’ 列等于 department 表中的 ‘d_name’ 列。 |
Syntax:
语法:
select employee.e_name, employee.e_dept, department.d_name,
select employee.e_name, employee.e_dept, department.d_name,
department.d_location
department.d_location
from employee inner join department
from employee inner join department
on
on
employee.e_dept=department.d_nameOutput:
employee.e_dept=department.d_nameOutput:
| e_name | e_dept | d_name | d_location |
| Bob | Support | Support | Chicago |
| Anne | Analytics | Analytics | New York |
| Julia | Analytics | Analytics | New York |
| Matt | Sales | Sales | Boston |
| 在 Inner Join 之后,我们只会保留两张表中 department 能匹配上的记录。可以看到,匹配到的部门是 Support、Analytics 和 Sales。 |
387. 说明 Views(视图)和 Tables(表)之间的区别。
- 知识点: 数据库 (主题: sql, database;标签: sql, view, table)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971e3201f88a3acd715eff1 | 官方: 是 | 付费: 否
答案:
答案| Views | Tables |
| It is a virtual table that is extracted from a database. 它是一个从数据库中提取出来的虚拟表。 | A table is structured with a set number of columns and a boundless number of rows. 表是由固定数量的列和无限数量的行构成的。 |
|---|---|
| Views do not hold data themselves. 视图本身不保存数据。 | Table contains data and stores the data in databases. 表包含数据并将数据存储在数据库中。 |
| A view is also utilized to query certain information contained in a few distinct tables. 视图还用于查询一些分布在几个不同表中的特定信息。 | A table holds fundamental client information and the cases of a characterized object. 表保存着基础客户信息以及一个已定义对象的实例。 |
| In a view, we will get frequently queried information. 在视图中,我们会获取到频繁查询的信息。 | In a table, changing the information in the database changes the information that appears in the view 在表中,更改数据库中的信息会改变视图中显示的信息。 |
388. 你对 Temporary Table(临时表)有什么理解?写一条创建临时表的查询。
- 知识点: 数据库 (主题: sql, database;标签: sql, temporary-table)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971e3201f88a3acd715eff4 | 官方: 是 | 付费: 否
答案:
答案临时表用于存储并处理中间结果。临时表创建后,在不再使用时可以自动删除。它们在需要存储临时数据的场景中非常有用。
Syntax:
语法:
CREATE TABLE #table_name();下面的查询将创建一个临时表:
create table #book(b_id int, b_cost int)
create table #book(b_id int, b_cost int)
Now, we will insert the records.
现在,我们将插入记录。
insert into #book values(1,100)
insert into #book values(1,100)
insert into #book values(2,232)
insert into #book values(2,232)
select * from #bookOutput:
select * from #book输出:
| b_id | b_cost |
| 1 | 100 |
| 2 | 232 |
389. 解释 OLTP 和 OLAP 之间的区别。
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: sql, database, data-warehouse;标签: oltp, olap)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6971e3201f88a3acd715eff8 | 官方: 是 | 付费: 否
答案:
答案OLTP: 它基本上代表 Online Transaction Processing(在线事务处理),可以认为是一类用于支持面向事务程序的软件应用类别。OLTP 系统的重要属性之一是能够保持一致性(consistency)。
OLTP 系统通常遵循去中心化规划(decentralized planning),以避免单点故障。该系统通常面向大量终端用户执行短事务。此类数据库中的查询一般较简单,需要快速响应时间;相比之下,它只返回少量记录。因此,每秒事务数(transactions per second)可以作为衡量这些系统的有效指标。
OLAP: OLAP 代表 Online Analytical Processing(在线分析处理),是一类在线事务频率相对较低的软件程序类别。对于 OLAP 系统,其计算效率在很大程度上依赖响应时间。因此,这类系统通常用于数据挖掘或维护聚合的历史数据,并且通常用于多维(multi-dimensional)模式中。
390. 什么是自连接(Self Join)?
- 知识点: 数据库 (主题: sql, database;标签: Self Join, JOIN)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6972d0b21f88a3acd7251e5d | 官方: 是 | 付费: 否
答案:
答案Self Join 在 SQL 中用于把一张表与它自身进行连接(join)。在这种连接方式里,表会根据某些条件,让表中的每一行与自身或与表中的其他行进行匹配与连接。
Syntax:
语法:
SELECT a.column_name, b.column_name
SELECT a.column_name, b.column_name
FROM table a, table b
FROM table a, table b
WHERE conditionExample:
WHERE condition示例:
Consider the customer table given below.
考虑下面给出的客户表。
| ID | Name
姓名 | Age
年龄 | Address
地址 | Salary
工资 |
| 1 | Anand | 32 | Ahmedabad | 2,000.00 |
| 2 | Abhishek | 25 | Delhi | 1,500.00 |
| 3 | Shivam | 23 | Kota | 2,000.00 |
| 4 | Vishal | 25 | Mumbai | 6,500.00 |
| 5 | Sayeedul | 27 | Bhopal | 8,500.00 |
| 6 | Amir | 22 | MP | 4,500.00 |
| 7 | Arpit | 24 | Indore | 10,000.00 |
| We will now join the table using Self-Join: 现在我们将使用自连接来连接该表: |
SQL> SELECT a.ID, b.NAME, a.SALARY
SQL> SELECT a.ID, b.NAME, a.SALARY
FROM CUSTOMERS a, CUSTOMERS b
FROM CUSTOMERS a, CUSTOMERS b
WHERE a.SALARY < b.SALARY;Output:
WHERE a.SALARY < b.SALARY;输出:
| ID | Name | Salary |
| 2 | Anand | 1,500.00 |
| 2 | Abhishek | 1,500.00 |
| 1 | Vishal | 2,000.00 |
| 2 | Vishal | 1,500.00 |
| 3 | Vishal | 2,000.00 |
| 6 | Vishal | 4,500.00 |
| 1 | Sayeedul | 2,000.00 |
| 2 | Sayeedul | 1,500.00 |
| 3 | Sayeedul | 2,000.00 |
| 4 | Sayeedul | 6,500.00 |
| 6 | Sayeedul | 4,500.00 |
| 1 | Amir | 2,000.00 |
| 2 | Amir | 1,500.00 |
| 3 | Amir | 2,000.00 |
| 1 | Arpit | 2,000.00 |
| 2 | Arpit | 1,500.00 |
| 3 | Arpit | 2,000.00 |
| 4 | Arpit | 6,500.00 |
| 5 | Arpit | 8,500.00 |
| 6 | Arpit | 4,500.00 |
391. UNION 和 UNION ALL 运算符有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: UNION, UNION ALL)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6972d0b21f88a3acd7251e61 | 官方: 是 | 付费: 否
答案:
答案Union operator 用于合并两个或多个 SELECT 语句的结果集。另外,如果两张表中存在相同记录,最终结果中只会保留一条(去重)。
Syntax:
语法:
SELECT column_list FROM table1
SELECT column_list FROM table1
Union:
联合:
SELECT column_list FROM table2Now, we will execute it in the SQL server. These are the two tables in which we will use the Union operator.
SELECT column_list FROM table2现在,我们将在SQL服务器中执行它。这是我们将使用Union操作符的两张表。
-- student_details1
-- student_details1
| s_id | s_name | s_marks |
| 1 | Sam | 45 |
| 2 | Bob | 87 |
| 3 | Anne | 73 |
| 4 | Julia | 92 |
-- student_details2
-- student_details2
| s_id | s_name | s_marks |
| 3 | Anne | 73 |
| 4 | Julia | 92 |
| 5 | Matt | 65 |
| select * from student_details1 |
Union:
联合:
select * from student_details2Output(UNION):
select * from student_details2Output(UNION):
| s_id | s_name | s_marks |
| 1 | Sam | 45 |
| 2 | Bob | 87 |
| 3 | Anne | 73 |
| 4 | Julia | 92 |
| 5 | Matt | 65 |
| Union All 会返回两张表中的所有记录,包含重复记录(不去重)。 |
select * from student_details1
select * from student_details1
Union All:
Union All:
select * from student_details2Output(UNION ALL):
select * from student_details2输出(UNION ALL):
| s_id | s_name | s_marks |
| 1 | Sam | 45 |
| 2 | Bob | 87 |
| 3 | Anne | 73 |
| 4 | Julia | 92 |
| 3 | Anne | 73 |
| 4 | Julia | 92 |
| 5 | Matt | 65 |
392. Intersect 运算符有什么用途?
- 知识点: 数据库 (主题: sql, database;标签: SQL, Set Operators, INTERSECT)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6972d30e1f88a3acd7256016 | 官方: 是 | 付费: 否
答案:
答案INTERSECT 运算符用于组合两个 SELECT 语句,并且只返回两个 SELECT 语句结果集中共同的记录。因此,当我们对 Table A 和 Table B 执行 SELECT 并使用 INTERSECT 运算符时,只会得到两者结果中共同的记录。
语法(Syntax):
SELECT column_list FROM table1
SELECT column_list FROM table1
INTERSECT
INTERSECT
SELECT column_list FROM table2现在,我们来看一个 INTERSECT(交集)运算符(Operator)的例子。
select * from student_details1
select * from student_details1
select * from student_details1Output:
select * from student_details1输出:
| s_id | s_name | s_marks |
| 1 | Sam | 45 |
| 2 | Bob | 87 |
| 3 | Anne | 73 |
| 4 | Julia | 92 | s_id | s_name | s_marks | |
|---|---|---|---|---|---|---|
| 3 | Anne | 73 | ||||
| 4 | Julia | 92 | ||||
| 5 | Matt | 65 | select * from student_details1 |
intersect
intersect
select * from student_details2Output:
select * from student_details2输出:
| s_id | s_name | s_marks |
| 3 | Anne | 73 |
| 4 | Julia | 92 |
393. 如何将一个表的数据复制到另一个表?
- 知识点: 数据库 (主题: sql, database;标签: SQL, INSERT INTO SELECT, Copy Data)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6972d3121f88a3acd725639b | 官方: 是 | 付费: 否
答案:
答案这里我们有 employee(员工)表。我们需要把这些数据复制到另一张表中。为此,我们可以使用 INSERT INTO SELECT(插入选择)运算符。在继续之前,我们需要先创建一张结构与上述表相同的表。
employee(员工)表(示例数据):
| e_id | e_name | E_salary | e_age | e_gender | e_dept |
|---|---|---|---|---|---|
| 1 | Sam | 95000 | 45 | Male | Operations |
| 2 | Bob | 80000 | 21 | Male | Support |
| 3 | Anne | 125000 | 25 | Female | Analytics |
| 4 | Julia | 73000 | 30 | Female | Analytics |
| 5 | Matt | 159000 | 33 | Male | Sales |
| 6 | Jeff | 112000 | 27 | Male | Operations |
| Syntax: 语法: |
create table employee_duplicate(
create table employee_duplicate(
e_id int,
e_id int,
e_name varchar(20),
e_name varchar(20),
e_salary int,
e_salary int,
e_age int,
e_age int,
e_gender varchar(20)
e_gender varchar(20)
e_dept varchar(20)
e_dept varchar(20)
)为了复制数据,我们会使用如下查询:
insert into employee_duplicate select * from employees
insert into employee_duplicate select * from employees
Let us have a glance at the copied table.
让我们看一下复制后的表。
select * from employee_duplicateOutput:
select * from employee_duplicate输出:
| e_id | e_name | e_salary | e_age | e_gender | e_dept |
| 1 | Sam | 95000 | 45 | Male | Operations |
| 2 | Bob | 80000 | 21 | Male | Support |
| 3 | Anne | 125000 | 25 | Female | Analytics |
| 4 | Julia | 112000 | 30 | Female | Analytics |
| 5 | Matt | 159000 | 33 | Male | Sales |
| 6 | Jeff | 112000 | 27 | Male | Operations |
394. SQL(结构化查询语言)中 TRUNCATE(截断)和 DELETE(删除)有什么区别?
- 知识点: 数据库 (主题: sql, transactions;标签: TRUNCATE, DELETE, Rollback)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6977264ba39c9c5c3a89f663 | 官方: 是 | 付费: 否
答案:
答案DELETE(删除)按条件删除行(可用 WHERE(条件)),通常逐行记录日志,支持回滚;TRUNCATE(截断)通常用于快速清空整表数据(一般不带 WHERE(条件)),操作更接近重置数据页/高水位线,速度更快但回滚能力取决于数据库实现与事务设置。两者对触发器、外键约束的影响也可能不同,需要结合具体 DB(数据库)规则判断。
395. 什么是聚集索引(Clustered Index)?它与非聚集索引(Non-clustered Index)有何不同?
- 知识点: 数据库 (主题: sql, indexing;标签: Clustered Index, Non-clustered Index)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6977264ba39c9c5c3a89f686 | 官方: 是 | 付费: 否
答案:
答案聚集索引(Clustered Index)决定表数据在磁盘/存储中的物理(或逻辑)排序方式,数据行按索引键顺序组织;因此一个表通常只能有一个聚集索引(Clustered Index)。非聚集索引(Non-clustered Index)是独立结构,保存键值与指向数据行的定位信息,可在多个列上创建多个索引。聚集索引(Clustered Index)适合范围查询与排序,非聚集索引(Non-clustered Index)适合多维检索与覆盖查询场景。
396. 什么是 SQL(结构化查询语言)触发器(Trigger)?它们如何工作?
- 知识点: 数据库 (主题: sql, database;标签: Trigger, Audit, Constraints)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6977264ba39c9c5c3a89f68a | 官方: 是 | 付费: 否
答案:
答案SQL(结构化查询语言)触发器(Trigger)是绑定在表/视图上的数据库对象,会在 INSERT(插入)/UPDATE(更新)/DELETE(删除)等事件发生时自动执行预定义逻辑。触发器(Trigger)可用于强制业务规则、审计记录变更、做数据校验或衍生计算,通常可配置为 BEFORE(之前)/AFTER(之后)触发。使用时需谨慎控制复杂度与副作用,避免递归触发与性能问题。
397. 什么是数据仓库中的事实表(Fact Table)?它通常包含什么?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: data-warehouse, bi, sql;标签: Fact Table, Star Schema, Measures)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69772661a39c9c5c3a89fe35 | 官方: 是 | 付费: 否
答案:
答案事实表(Fact Table)是数据仓库星型/雪花模型的核心表,用于存放可度量的业务事件数据(如销售额、订单数、点击量等),通常包含度量指标(measures)以及指向维度表的外键(如日期、客户、产品、地区)。事实表(Fact Table)便于做聚合分析(SUM/COUNT/AVG)与多维切片,是报表与 BI(商业智能)分析的主要数据来源。
398. 什么是聚簇索引(Clustered Index)?
- 知识点: 数据库 (主题: databases, sql, indexing;标签: Clustered Index, Non-clustered, Performance)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 697729f6a39c9c5c3a8ab201 | 官方: 是 | 付费: 否
答案:
答案聚簇索引(Clustered Index)决定表中数据行的物理存储顺序(或最接近的存储组织方式):数据本身按索引键排序存放,因此基于该键的范围查询与排序通常更快。多数数据库中一张表通常只能有一个聚簇索引(Clustered Index)(因为物理顺序只能有一种),而非聚簇索引(Non-clustered Index)则是独立结构保存键与指向数据行的指针/RowID(行标识符)。是否“主键一定是聚簇索引(Clustered Index)”取决于具体数据库实现与配置,不是绝对规则。
399. 什么是 SQL Trigger(触发器)?
- 知识点: 数据库 (主题: databases, sql;标签: Trigger, Audit, Business Rules)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 697729f6a39c9c5c3a8ab206 | 官方: 是 | 付费: 否
答案:
答案SQL 触发器(Trigger)是绑定在表或视图上的数据库对象(Database Object),会在特定事件发生时自动执行(如 INSERT/UPDATE/DELETE,部分数据库也支持 DDL 触发)。触发器常用于审计记录变更、强制业务规则、维护派生字段或同步数据。但它也可能带来隐式逻辑、调试困难与性能风险,因此需要控制复杂度、避免长事务,并配合清晰的文档与测试。
400. 数据库规范化的目的是什么,它的规范形式是什么?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: databases, data-modeling;标签: Normalization, 1NF, 2NF, 3NF)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69772f9ea39c9c5c3a8bc71e | 官方: 是 | 付费: 否
答案:
答案规范化(Normalization)通过拆分表结构来减少冗余、避免更新异常并提升一致性与数据完整性。常见范式(Normal Form):1NF 消除重复组、字段原子化;2NF 消除对复合主键的部分依赖;3NF 消除传递依赖;更高范式(BCNF/4NF)进一步处理依赖与多值依赖。实际工程会在规范化与性能之间权衡,读多写少场景可能适度反规范化(Denormalization)。
401. 解释嵌套查询,并举例说明。
- 知识点: 数据库 (主题: sql, databases;标签: Subquery, IN, EXISTS, Join)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6977328fa39c9c5c3a8d798e | 官方: 是 | 付费: 否
答案:
答案嵌套查询(Nested Query / Subquery)是把一个查询写在另一个查询内部,用子查询的结果作为外层查询的条件或数据来源。常见用法:IN/EXISTS、标量子查询(Scalar Subquery)、派生表(Derived Table)。例如:查询工资高于公司平均工资的员工:SELECT * FROM Employee e WHERE e.salary > (SELECT AVG(salary) FROM Employee)。实际优化要关注子查询是否可改写为 JOIN、是否有索引支撑与执行计划表现。
402. 什么是数据库规范化(normalisation)、连接(joins)和键(keys)?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: databases, sql, data-modeling;标签: Normalization, Joins, Keys)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 6977336da39c9c5c3a8da702 | 官方: 是 | 付费: 否
答案:
答案规范化(Normalization)是按范式(1NF/2NF/3NF 等)组织表结构,减少冗余并避免更新异常,提高一致性;连接(JOIN)是按关联列把多表数据组合成一个结果集(如 inner/left/right/full);键(Key)是用于唯一标识或建立关系的字段集合,如主键(Primary Key)唯一标识记录,外键(Foreign Key)引用其他表主键。实践中要在“规范化一致性”和“查询性能/易用性”之间平衡。
403. 技术面(technical round)通常考察什么?如何准备?
- 知识点: 数据库 / 操作系统与网络 / 编程语言基础 (主题: os, databases, networking, oop;标签: Technical Round, Concepts, Project Examples)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69773446a39c9c5c3a8dc2c6 | 官方: 是 | 付费: 否
答案:
答案技术面通常考察主观技术理解与表达,常见主题包括操作系统、DBMS、网络、OOP,以及你选择的两门编程语言与项目实践。准备时建议:用“知识树”梳理每个主题的核心概念、常见追问与对比题(如锁 vs MVCC、进程 vs 线程、TCP vs UDP),并用项目案例把概念落地;同时练习口头讲解,把答案控制在结构化的 1-2 分钟内。
404. 数据库中的主键(Primary Key)和外键(Foreign Key)有什么区别?
- 知识点: 数据库 (主题: databases, sql;标签: wipro, freshers, primary-key, foreign-key)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69781f33a39c9c5c3ab3c97c | 官方: 是 | 付费: 否
答案:
答案主键(Primary Key)用于唯一标识表中的每一条记录,必须唯一且通常不为空,用来保证实体的唯一性。外键(Foreign Key)是表中用于引用另一张表主键(或唯一键)的字段,通过这种引用建立表与表之间的关系,并强制参照完整性,避免出现“孤儿数据”。简而言之:主键负责“唯一标识”,外键负责“建立关联”。
405. 解释 SQL 和 NoSQL 数据库之间的区别。
- 知识点: 数据库 (主题: databases, sql, nosql;标签: wipro, freshers, sql, nosql)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 69781f33a39c9c5c3ab3c982 | 官方: 是 | 付费: 否
答案:
答案SQL 数据库以关系模型(Relational Model)为核心,使用表结构与预定义 Schema,擅长复杂查询与事务处理,通常遵循 ACID 保障强一致性。NoSQL 数据库更强调灵活的数据模型(键值、文档、列族、图等),通常采用弱 Schema 或无 Schema 设计,优先追求水平扩展、高吞吐与高可用,部分场景以最终一致性换取可扩展性。选择取决于数据结构、查询模式、事务一致性与扩展需求。
406. DBMS 中的检查点(Checkpoint)是什么?
- 知识点: 数据库 (主题: dbms;标签: checkpoint, recovery)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 697825c0a39c9c5c3ab58c4b | 官方: 是 | 付费: 否
答案:
答案DBMS 的检查点(Checkpoint)用于把当前的事务状态与日志信息安全地刷写到磁盘,从而缩短崩溃恢复时间。发生故障时,系统可从最近一次检查点开始重做(redo)/回滚(undo),而无需从头扫描所有日志。检查点并非简单“删除日志”,而是标记一个一致性恢复起点。
407. 什么是数据库规范化(Normalization)?
- 知识点: 数据库 (主题: databases, dbms;标签: normalization, normal-forms)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 697825c0a39c9c5c3ab58c50 | 官方: 是 | 付费: 否
答案:
答案规范化(Normalization)是根据函数依赖(Functional Dependency)把关系模式(Relational Schema)拆分到更合适的范式(Normal Form,如 1NF/2NF/3NF/BCNF),以减少数据冗余(Data Redundancy)、避免更新异常(Update Anomaly,插入/删除/修改异常)并提升一致性(Consistency)。代价可能是增加表数量与查询 join(Join)成本,因此需在一致性与性能之间权衡。
408. TikTok 新毕业生的在线编程测试(Online Coding Test)通常是什么形式?有哪些注意事项?
- 知识点: 数据库 / 算法与数据结构 / 编程语言基础 (主题: hackerrank, sql, data-structures, algorithms, oop;标签: tiktok, online-assessment, newgrad)
- 类型: technical | 难度: medium | 子类型:
- 分类: fullstack
- id: 697887f9a39c9c5c3ad69513 | 官方: 是 | 付费: 否
答案:
答案新毕业生常见在线测评一般在 HackerRank 等平台进行:收到邀请后通常有 5–7 天提交窗口;开始作答后一般限时约 120 分钟;并可能要求开启摄像头。题型反馈较多样:可能是 3 道中等 DS&A(Data Structures and Algorithms);也可能是 5 道混合题(含 SQL、数组、字符串);或包含选择题与编码题(算法/OOP)。即使部分人能绕过测评,仍建议按“会考”的标准准备。
409. What is meant by normalization and denormalization?
规范化和反规范化是什么意思?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6716 | 官方: 否 | 付费: 否
答案:
Normalization is a process of reducing redundancy by organizing the data into multiple tables. Normalization leads to better usage of disk spaces and makes it easier to maintain the integrity of the database.
规范化是通过将数据组织到多个表中来减少冗余的过程。规范化有助于更好地利用磁盘空间,并使维护数据库完整性更加容易。
Denormalization is the reverse process of normalization as it combines the tables which have been normalized into a single table so that data retrieval becomes faster. JOIN operation allows us to create a denormalized form of the data by reversing the normalization.
反规范化是规范化的逆过程,因为它将已经规范化的表合并为一个表,从而使数据检索变得更快。JOIN操作允许通过逆转规范化来创建数据的反规范化形式。
410. What is a lock. Explain the major difference between a shared lock and an exclusive lock during a transaction in a database.
什么是锁?解释数据库中事务期间共享锁和排他锁之间的主要区别。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6719 | 官方: 否 | 付费: 否
答案:
A database lock is a mechanism to protect a shared piece of data from getting updated by two or more database users at the same time. When a single database user or session has acquired a lock then no other database user or session can modify that data until the lock is released. - Shared Lock: A shared lock is required for reading a data item and many transactions may hold a lock on the same data item in a shared lock. Multiple transactions are allowed to read the data items in a shared lock.
数据库锁是一种机制,用于保护共享数据不被两个或更多数据库用户同时更新。当单个数据库用户或会话获得锁时,其他数据库用户或会话不能修改该数据,直到锁被释放。- 共享锁:共享锁是读取数据项所必需的,多个事务可以以共享锁的方式持有同一数据项的锁。允许多个事务在共享锁下读取数据项。
- Exclusive lock: An exclusive lock is a lock on any transaction that is about to perform a write operation. This type of lock doesn’t allow more than one transaction and hence prevents any inconsistency in the database.
411. Explain different levels of data abstraction in a DBMS.
解释DBMS中数据抽象的不同级别。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba671f | 官方: 否 | 付费: 否
答案:
The process of hiding irrelevant details from users is known as data abstraction. Data abstraction can be divided into 3 levels:
从用户那里隐藏无关细节的过程称为数据抽象。数据抽象可以分为3个级别:
- Physical Level: it is the lowest level and is managed by DBMS. This level consists of data storage descriptions and the details of this level are typically hidden from system admins, developers, and users.
- Conceptual or Logical level: it is the level on which developers and system admins work and it determines what data is stored in the database and what is the relationship between the data points.
- External or View level: it is the level that describes only part of the database and hides the details of the table schema and its physical storage from the users. The result of a query is an example of View level data abstraction. A view is a virtual table created by selecting fields from one or more tables present in the database.
412. What is meant by an entity-relationship (E-R) model? Explain the terms Entity, Entity Type, and Entity Set in DBMS.
实体-关系(E-R)模型是什么意思?解释DBMS中的实体、实体类型和实体集这些术语。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6722 | 官方: 否 | 付费: 否
答案:
An entity-relationship model is a diagrammatic approach to a database design where real-world objects are represented as entities and relationships between them are mentioned.
实体-关系模型是一种数据库设计的图示方法,其中现实世界的对象被表示为实体,并提及它们之间的关系。
- Entity: An entity is defined as a real-world object having attributes that represent characteristics of that particular object. For example, a student, an employee, or a teacher represents an entity.
- Entity Type: An entity type is defined as a collection of entities that have the same attributes. One or more related tables in a database represent an entity type. Entity type or attributes can be understood as a characteristic which uniquely identifies the entity. For example, a student represents an entity that has attributes such as student_id, student_name, etc.
- Entity Set: An entity set can be defined as a set of all the entities present in a specific entity type in a database. For example, a set of all the students, employees, teachers, etc. represent an entity set.
413. Explain different types of relationships amongst tables in a DBMS.
解释DBMS中表之间不同类型的关系。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6725 | 官方: 否 | 付费: 否
答案:
Following are different types of relationship amongst tables in a DBMS system: - One to One Relationship: This type of relationship is applied when a particular row in table X is linked to a singular row in table Y.
以下是DBMS系统中表之间不同类型的关系:- 一对一关系:当表X中的特定行与表Y中的单一行相关联时,应用这种类型的关系。
- One to Many Relationship: This type of relationship is applied when a single row in table X is related to many rows in table Y.
- Many to Many Relationship: This type of relationship is applied when multiple rows in table X can be linked to multiple rows in table Y.
- Self Referencing Relationship: This type of relationship is applied when a particular row in table X is associated with the same table.
414. Explain the difference between intension and extension in a database.
解释数据库中内涵和外延之间的区别。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6728 | 官方: 否 | 付费: 否
答案:
Following is the major difference between intension and extension in a database: - Intension: Intension or popularly known as database schema is used to define the description of the database and is specified during the design of the database and mostly remains unchanged.
以下是数据库中内涵和外延之间的主要区别:- 内涵:内涵或通常称为数据库模式,用于定义数据库的描述,并在数据库设计期间指定,且大多保持不变。
- Extension: Extension on the other hand is the measure of the number of tuples present in the database at any given point in time. The extension of a database is also referred to as the snapshot of the database and its value keeps changing as and when the tuples are created, updated, or destroyed in a database.
415. Explain the difference between the DELETE and TRUNCATE command in a DBMS.
解释数据库管理系统中DELETE和TRUNCATE命令的区别。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba672f | 官方: 否 | 付费: 否
答案:
DELETE command: this command is needed to delete rows from a table based on the condition provided by the WHERE clause. - It deletes only the rows which are specified by the WHERE clause.
DELETE命令:此命令用于根据WHERE子句提供的条件从表中删除行。- 它仅删除WHERE子句指定的行。
- It can be rolled back if required.
It maintains a log to lock the row of the table before deleting it and hence it’s slow.
TRUNCATE command: this command is needed to remove complete data from a table in a database. It is like a DELETE command which has no WHERE clause. - It removes complete data from a table in a database.TRUNCATE命令:此命令用于移除数据库中表中的全部数据。它类似于没有WHERE子句的DELETE命令。- 它移除数据库中表中的全部数据。
- It can't be rolled back even if required. ( truncate can be rolled back in some databases depending on their version but it can be tricky and can lead to data loss). Check this link for more details
- It doesn’t maintain a log and deletes the whole table at once and hence it’s fast.
416. Difference between WHERE and HAVING
WHERE和HAVING的区别
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6774 | 官方: 否 | 付费: 否
答案:
WHERE is used to filter rows before any grouping or aggregation happens in the query. It works on individual records and cannot use aggregate functions like COUNT, SUM, or AVG. HAVING is applied after GROUP BY and is meant for filtering aggregated results. For example, filtering orders by status goes in WHERE, but filtering customers with total orders greater than 5 goes in HAVING. Using HAVING instead of WHERE usually makes queries slower and harder to read. A good rule is to filter early using WHERE whenever possible.
WHERE用于在查询中发生任何分组或聚合之前过滤行。它作用于单个记录,不能使用COUNT、SUM或AVG等聚合函数。HAVING在GROUP BY之后应用,用于过滤聚合结果。例如,按状态过滤订单应使用WHERE,但过滤总订单数大于5的客户应使用HAVING。使用HAVING代替WHERE通常会使查询变慢且更难阅读。一个好的经验法则是尽可能早地使用WHERE进行过滤。
417. INNER JOIN vs LEFT JOIN and when LEFT JOIN behaves like INNER JOIN
INNER JOIN与LEFT JOIN,以及LEFT JOIN何时表现得像INNER JOIN
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6777 | 官方: 否 | 付费: 否
答案:
An INNER JOIN returns only rows that exist in both tables. A LEFT JOIN returns all rows from the left table, even if there is no matching row on the right side. However, a LEFT JOIN can accidentally behave like an INNER JOIN if you add conditions on the right table in the WHERE clause. This removes rows where the right table values are NULL. To avoid this issue, conditions related to the right table should be written inside the ON clause. This mistake is very common in real production queries.
INNER JOIN仅返回两个表中都存在的行。LEFT JOIN返回左表中的所有行,即使右侧没有匹配的行。然而,如果在WHERE子句中添加右表的条件,LEFT JOIN可能会意外表现得像INNER JOIN。这会移除右表值为NULL的行。为避免此问题,与右表相关的条件应写在ON子句内。这个错误在生产查询中非常常见。
418. What causes duplicate rows after a JOIN, and how to fix it
JOIN后出现重复行的原因及如何修复
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba677a | 官方: 否 | 付费: 否
答案:
Duplicate rows usually appear when one row in a table matches multiple rows in another table. This often happens in one-to-many relationships, like customers and orders. SQL is doing the correct thing, but the result may look wrong if you are not expecting multiple matches. To fix this, you can aggregate the data before joining or ensure you are joining on the correct keys. Sometimes DISTINCT helps, but it can hide real data issues. Understanding the data structure is more important than forcing uniqueness.
当一个表中的一行匹配另一个表中的多行时,通常会出现重复行。这常发生在一对多关系中,例如客户和订单。SQL正在做正确的事情,但如果您未预期多个匹配,结果可能会看似错误。要修复此问题,可以在连接前聚合数据,或确保在正确的键上进行连接。有时DISTINCT有帮助,但它可能掩盖真实的数据问题。理解数据结构比强制唯一性更重要。
419. What is a correlated subquery, and when is slower than a JOIN
什么是相关子查询,以及何时比JOIN慢
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba677d | 官方: 否 | 付费: 否
答案:
A correlated subquery is a subquery that depends on values from the outer query. It runs once for each row returned by the main query. Because of this repeated execution, it can be slow on large datasets. In many cases, the same logic can be written using a JOIN, which executes more efficiently. Correlated subqueries are easier to write for simple logic, but can cause performance issues. They are best avoided in high-volume production queries.
相关子查询是依赖外部查询值的子查询。它针对主查询返回的每一行运行一次。由于这种重复执行,它在大数据集上可能很慢。在许多情况下,相同的逻辑可以用JOIN编写,后者执行效率更高。相关子查询适用于简单逻辑的编写,但可能导致性能问题。在高吞吐量的生产查询中最好避免使用。
420. UNION vs UNION ALL from a performance viewpoint
从性能角度看UNION与UNION ALL
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6780 | 官方: 否 | 付费: 否
答案:
UNION combines results from multiple queries and removes duplicate rows from the final output. To do this, the database has to sort and compare rows, which takes extra time. UNION ALL simply appends the results without checking for duplicates. Because of this, UNION ALL is faster and uses fewer resources. If you are sure that the datasets do not overlap, UNION ALL should always be preferred. In real-world systems, UNION ALL is commonly used for better performance.
UNION合并多个查询的结果,并从最终输出中移除重复行。为此,数据库必须排序和比较行,这需要额外时间。UNION ALL只是追加结果而不检查重复。因此,UNION ALL更快且使用更少资源。如果您确定数据集不重叠,应始终优先使用UNION ALL。在真实系统中,为获得更好的性能通常使用UNION ALL。
421. How to write Top-N per group queries
如何编写每组Top-N查询
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6783 | 官方: 否 | 付费: 否
答案:
One common approach is using window functions like ROW_NUMBER() with PARTITION BY. This allows ranking rows within each group and then filtering the top N rows. Another approach is using a correlated subquery that compares values within the same group. Older databases often rely on subqueries, while modern systems prefer window functions. Window functions are clearer, faster, and easier to maintain. The best approach depends on database support and data size.
一种常见方法是使用窗口函数(如ROW_NUMBER()与PARTITION BY)。这允许对每组内的行进行排名,然后过滤前N行。另一种方法是使用相关子查询来比较同一组内的值。较旧的数据库通常依赖子查询,而现代系统更偏好窗口函数。窗口函数更清晰、更快且更易维护。最佳方法取决于数据库支持和数据大小。
422. What is a CTE and how it differs from a subquery
什么是CTE,以及它与子查询的区别
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6786 | 官方: 否 | 付费: 否
答案:
A CTE, written using the WITH clause, is a temporary named result set used within a query. It makes complex queries easier to read and understand compared to nested subqueries. CTEs can be referenced multiple times in the same query, which improves clarity. Recursive CTEs are used to handle hierarchical data like employee reporting structures. Some databases materialize CTEs, which can impact performance. CTEs are mainly a readability and maintainability feature.
CTE(公用表表达式)使用WITH子句编写,是查询中使用的临时命名结果集。与嵌套子查询相比,它使复杂查询更易于阅读和理解。CTE可以在同一查询中多次引用,从而提高清晰度。递归CTE用于处理诸如员工汇报结构之类的层级数据。某些数据库会物化CTE,这可能会影响性能。CTE主要是一个提高可读性和可维护性的功能。
423. What is a VIEW and when should you avoid it
什么是视图,以及何时应避免使用它
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6789 | 官方: 否 | 付费: 否
答案:
A view is a stored SQL query that behaves like a virtual table. It is used to simplify complex queries and provide consistent access to data. Views do not store data, so the underlying query runs every time the view is accessed. This can cause performance issues for large or complex queries. Views can also hide inefficient SQL, making debugging harder. Avoid using views for heavy calculations or frequently accessed large datasets.
视图是存储的SQL查询,行为类似于虚拟表。它用于简化复杂查询并提供一致的数据访问。视图不存储数据,因此每次访问视图时都会运行底层查询。对于大型或复杂查询,这可能导致性能问题。视图也可能掩盖低效SQL,使调试更加困难。避免对繁重计算或频繁访问的大型数据集使用视图。
424. What is a materialized view and its trade-offs
什么是物化视图及其权衡
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba678c | 官方: 否 | 付费: 否
答案:
A materialized view stores the actual result of a query instead of recalculating it every time. This makes read operations very fast and is useful for reporting and analytics. The main drawback is that the data can become stale. Materialized views need to be refreshed, either manually or on a schedule. Refreshing them can be expensive and impact write performance. They are best used when fast reads are more important than real-time accuracy.
物化视图存储查询的实际结果,而不是每次重新计算。这使得读操作非常快速,对报表和分析很有用。主要缺点是数据可能会过期。物化视图需要手动或按计划刷新。刷新可能成本高昂并影响写入性能。当快速读取比实时准确性更重要时,它们最适用。
Replication, Sharding & Distributed DB Concepts
425. What is partitioning or sharding and when should you shard?
什么是分区或分片,以及何时应分片?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba678f | 官方: 否 | 付费: 否
答案:
Sharding splits data across multiple databases based on a key. It is used when a single database can no longer handle the load or data size. Sharding improves scalability by distributing reads and writes. However, it increases system complexity. Queries across shards become harder. Teams usually shard only after vertical scaling is no longer enough.
分片根据键将数据拆分到多个数据库。当单个数据库无法再处理负载或数据规模时使用。分片通过分散读写来提高可扩展性。然而,它增加了系统复杂性。跨分片查询变得更加困难。团队通常仅在垂直扩展不再足够时才进行分片。
426. What is replication lag and how should apps handle it?
什么是复制延迟,以及应用应如何处理它?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6792 | 官方: 否 | 付费: 否
答案:
Replication lag is the delay between when data is written on the primary and when it appears on replicas. It can be detected using timestamps, log positions, or monitoring tools. Apps must not assume replicas are always up to date. Critical reads should go to the primary database. Less critical reads can tolerate some delay. Handling lag correctly avoids user-facing inconsistencies.
复制延迟是数据写入主库的时间与出现在副本上的时间之间的延迟。可以使用时间戳、日志位置或监控工具进行检测。应用不得假设副本始终是最新的。关键读取应流向主数据库。不太关键的读取可以容忍一些延迟。正确处理延迟可避免面向用户的不一致性。
427. Leader–follower vs multi-leader replication
主从复制与多主复制
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6795 | 官方: 否 | 付费: 否
答案:
In leader–follower replication, one node handles writes and others only replicate changes. It is simpler and safer but has a single write bottleneck. Multi-leader replication allows writes on multiple nodes. This improves write availability but introduces conflict risks. Resolving conflicts adds complexity and can cause data inconsistencies. Most teams prefer leader–follower unless multi-region writes are required.
在主从复制中,一个节点处理写入,其他节点仅复制更改。这更简单、更安全,但存在单写入瓶颈。多主复制允许多个节点写入。这提高了写入可用性,但引入了冲突风险。解决冲突增加了复杂性,并可能导致数据不一致。除非需要多区域写入,否则大多数团队偏好主从复制。
428. What is replication, and why do teams add read replicas?
什么是复制,以及团队为什么添加读副本?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6798 | 官方: 否 | 付费: 否
答案:
Replication means copying data from one database to one or more other databases. The main reason teams add read replicas is to scale read traffic. Reads can be sent to replicas while writes go to the primary database. This reduces load on the main system. Replicas also help with availability if the primary has issues.
复制意味着将数据从一个数据库复制到一个或多个其他数据库。团队添加读副本的主要原因是为了扩展读取流量。读取可以发送到副本,而写入则进入主数据库。这减少了主系统上的负载。如果主数据库出现问题,副本也有助于可用性。
429. Hash-based vs range-based sharding
基于哈希的分片与基于范围的分片
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba679b | 官方: 否 | 付费: 否
答案:
Hash-based sharding distributes data evenly using a hash function. It avoids hot spots but makes range queries harder. Range-based sharding groups data by value ranges like date or ID. This is good for range queries but can cause uneven load. The choice depends on query patterns. Workload characteristics should guide the sharding strategy.
基于哈希的分片使用哈希函数均匀分布数据。它避免热点了,但使范围查询更困难。基于范围的分片按值范围(如日期或ID)对数据进行分组。这适合范围查询,但可能导致负载不均。选择取决于查询模式。工作负载特征应指导分片策略。
430. What is a hot shard or partition and how do you mitigate it?
什么是热分片或热分区,以及如何缓解?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba679e | 官方: 否 | 付费: 否
答案:
A hot shard occurs when too much traffic hits a single shard. This usually happens due to skewed data or popular keys. Hot shards cause performance issues and uneven load. Mitigation includes better shard keys, adding randomness, or splitting hot shards. Caching hot data also helps. Monitoring is key to early detection.
热分片发生在过多流量命中单个分片时。这通常是由于数据倾斜或热门键导致的。热分片会引起性能问题和负载不均。缓解措施包括更好的分片键、增加随机性或拆分热分片。缓存热点数据也有帮助。监控是早期发现的关键。
431. What is eventual consistency in simple terms?
用简单的话说,什么是最终一致性?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67a1 | 官方: 否 | 付费: 否
答案:
Eventual consistency means data will become consistent over time, not immediately. Different nodes may temporarily show different values. This happens because updates take time to propagate. The system prioritizes availability and performance over immediate accuracy. Eventual consistency works well for social feeds or analytics. It is not suitable for financial transactions.
最终一致性意味着数据会随着时间变得一致,而不是立即一致。不同节点可能暂时显示不同的值。这是因为更新需要时间传播。系统优先考虑可用性和性能,而不是即时准确性。最终一致性适用于社交信息流或分析场景。它不适合金融交易。
432. Strong reads vs stale reads and when to use stale reads
强读取与陈旧读取,以及何时使用陈旧读取
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67a4 | 官方: 否 | 付费: 否
答案:
Strong reads always return the latest committed data. They usually go to the primary database. Stale reads may return slightly outdated data from replicas. Stale reads are faster and more scalable. They are acceptable for non-critical data like dashboards. Choosing the right type depends on business correctness needs.
强读取总是返回最新提交的数据。它们通常指向主数据库。陈旧读取可能从副本返回稍微过时的数据。陈旧读取更快且更具可扩展性。它们适合仪表盘等非关键数据。选择正确的类型取决于业务正确性需求。
433. Why are distributed transactions hard and how do teams avoid them?
为什么分布式事务很困难,团队如何避免它们?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: system-design
- 分类: fullstack
- id: 69b37a6c58d557c902ba67a7 | 官方: 否 | 付费: 否
答案:
Distributed transactions span multiple databases or services. They require coordination and can fail partially. This makes error handling and recovery complex. Two-phase commit is slow and fragile at scale. Teams avoid distributed transactions by redesigning workflows. Event-driven systems and eventual consistency are common alternatives.
分布式事务跨越多个数据库或服务。它们需要协调,并可能部分失败。这使错误处理和恢复变得复杂。两阶段提交在大规模下既慢又脆弱。团队通过重新设计工作流来避免分布式事务。事件驱动系统和最终一致性是常见的替代方案。
434. Designing a DB setup for multi-region high availability
为多区域高可用性设计数据库设置
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: system-design
- 分类: fullstack
- id: 69b37a6c58d557c902ba67aa | 官方: 否 | 付费: 否
答案:
Multi-region setups replicate data across geographic locations. One region usually acts as the primary for writes. Others serve reads and act as failover targets. Automated failover and health checks are critical. Latency and replication lag must be handled at the app level. The design balances availability, consistency, and cost.
多区域设置将数据复制到多个地理位置。一个区域通常作为写入的主要区域。其他区域提供读取服务并作为故障转移目标。自动化故障转移和健康检查至关重要。延迟和复制滞后必须在应用层面处理。设计在可用性、一致性和成本之间取得平衡。
Storage, Logging & Recovery
435. How do you design safe schema migrations with minimal downtime?
如何设计安全且停机时间最小的模式迁移?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67ad | 官方: 否 | 付费: 否
答案:
Safe migrations avoid locking tables for long periods. Changes are broken into small, backward-compatible steps. New columns are added first, then code is updated, and old columns are removed later. Migrations are tested on production-like data before rollout. This approach reduces downtime and rollback risk.
安全迁移避免长时间锁定表。更改被分解为小的、向后兼容的步骤。首先添加新列,然后更新代码,最后移除旧列。迁移在推出前在类似生产的数据上进行测试。这种方法减少了停机时间和回滚风险。
436. What are RPO and RTO and why interviewers ask them?
什么是RPO和RTO,为什么面试官会问它们?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67b0 | 官方: 否 | 付费: 否
答案:
RPO defines how much data loss is acceptable in a failure. RTO defines how long the system can stay down. These metrics connect database design to business requirements. Interviewers ask this to check real-world thinking. It shows you understand backups, recovery, and system reliability. Databases are not just about queries.
RPO定义了在故障中可接受的数据丢失量。RTO定义了系统可以停机多长时间。这些指标将数据库设计与业务需求联系起来。面试官问这个是为了检查真实世界的思维。它表明你理解备份、恢复和系统可靠性。数据库不仅仅是关于查询。
437. Difference between replication and backup
复制与备份的区别
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67b3 | 官方: 否 | 付费: 否
答案:
Replication copies data continuously to another system, usually for availability. It helps keep systems running if one node fails. Backups are snapshots taken at intervals for recovery purposes. Replication does not protect against bad data changes. Backups allow restoring old correct data. Both are needed but serve different goals.
复制将数据持续复制到另一个系统,通常是为了可用性。它帮助在一个节点失败时保持系统运行。备份是定期拍摄的快照,用于恢复目的。复制不能防止错误的数据更改。备份允许恢复旧的正确数据。两者都需要,但服务于不同目标。
438. What happens during crash recovery (high-level steps)?
崩溃恢复过程中会发生什么(高层次的步骤)?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67b6 | 官方: 否 | 付费: 否
答案:
When a crash occurs, the database starts by reading the transaction logs. It redoes committed transactions that were not written to disk. Then it undoes uncommitted transactions to remove partial changes. This process restores the database to a consistent state. Recovery happens automatically when the database restarts.
当发生崩溃时,数据库首先读取事务日志。它会重做那些尚未写入磁盘的已提交事务。然后回滚未提交的事务以移除部分更改。此过程将数据库恢复到一致状态。恢复在数据库重启时自动进行。
439. Redo log vs undo log (conceptual difference)
重做日志与撤销日志(概念性区别)
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67b9 | 官方: 否 | 付费: 否
答案:
Redo logs record changes that need to be reapplied after a crash. They help complete committed transactions during recovery. Undo logs store old values so changes can be rolled back. They are used when transactions fail or are aborted. Redo ensures durability, while undo ensures consistency. Both work together to keep data correct.
重做日志记录崩溃后需要重新应用更改。它们有助于在恢复期间完成已提交的事务。撤销日志存储旧值,以便更改可以回滚。当事务失败或被中止时使用它们。重做确保持久性,而撤销确保一致性。两者协同工作以保持数据的正确性。
440. What are checkpoints and how do they reduce recovery time?
什么是检查点,它们如何减少恢复时间?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67bc | 官方: 否 | 付费: 否
答案:
Checkpoints flush modified data from memory to disk at regular intervals. This reduces the amount of log data needed during recovery. After a crash, the database starts recovery from the last checkpoint instead of the beginning. This significantly shortens startup time. Frequent checkpoints improve recovery speed but can add overhead.
检查点定期将修改后的数据从内存刷新到磁盘。这减少了恢复期间所需的日志数据量。崩溃后,数据库从最后一个检查点开始恢复,而不是从头开始。这显著缩短了启动时间。频繁的检查点提高了恢复速度,但可能增加开销。
441. What is Point-in-Time Recovery (PITR)?
什么是时间点恢复(PITR)?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67bf | 官方: 否 | 付费: 否
答案:
Point-in-Time Recovery allows restoring the database to an exact moment in the past. It uses a full backup along with transaction logs like WAL. This is useful when data is accidentally deleted or corrupted. Instead of restoring to the last backup, you recover just before the mistake happened. PITR is essential for real-world failure recovery.
时间点恢复允许将数据库恢复到过去的某个精确时刻。它使用完整备份以及诸如WAL之类的事务日志。这在数据被意外删除或损坏时非常有用。无需恢复到上次备份,而是恢复到位错误发生之前的时刻。PITR对于现实世界的故障恢复至关重要。
442. Full vs incremental backups and when to use each
完整备份与增量备份及各自的适用场景
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67c2 | 官方: 否 | 付费: 否
答案:
A full backup captures the entire database at a specific point in time. It is simple to restore but takes more time and storage. Incremental backups store only the changes since the last backup. They are faster and smaller but require multiple steps to restore. Full backups are used periodically, while incremental backups are taken frequently. Most production systems use a mix of both.
完整备份在特定时间点捕获整个数据库。它易于恢复,但需要更多的时间和存储空间。增量备份仅存储自上次备份以来的更改。它们更快且更小,但恢复时需多个步骤。完整备份定期进行,而增量备份则频繁执行。大多数生产系统同时使用两者。
443. Difference between logical backup and physical backup
逻辑备份与物理备份的区别
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67c5 | 官方: 否 | 付费: 否
答案:
A logical backup stores data as SQL statements or logical records, like tables and rows. It is portable and can be restored on different systems or versions. A physical backup copies raw database files as they are on disk. Physical backups are much faster to restore but less flexible. Logical backups are easier to inspect, while physical backups are better for large databases.
逻辑备份将数据存储为SQL语句或逻辑记录,如表和行。它具有可移植性,能在不同系统或版本上恢复。物理备份复制磁盘上的原始数据库文件。物理备份恢复速度更快,但灵活性较低。逻辑备份更易于检查,而物理备份更适合大型数据库。
444. What is Write-Ahead Logging (WAL) and why is it critical for durability?
什么是预写日志(WAL),为什么它对持久性至关重要?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67c8 | 官方: 否 | 付费: 否
答案:
Write-Ahead Logging means all changes are first written to a log before being applied to the actual data files. This ensures that even if the system crashes, the database knows what changes were intended. During recovery, the database replays the log to restore consistency. WAL is critical because it guarantees committed data is not lost. Without WAL, crashes could corrupt data permanently.
预写日志意味着在应用于实际数据文件之前,所有更改首先写入日志。这确保了即使系统崩溃,数据库也知道预期的更改。在恢复期间,数据库重放日志以恢复一致性。WAL至关重要,因为它保证已提交的数据不会丢失。没有WAL,崩溃可能永久损坏数据。
Transactions, Isolation & Concurrency
445. When should you use a read-only transaction or snapshot?
何时应使用只读事务或快照?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67cb | 官方: 否 | 付费: 否
答案:
Read-only transactions are useful when you need consistent data for reports. Snapshot reads show data as it existed at a specific time. They prevent data changes from affecting long-running reads. Writers are not blocked during these operations. This improves concurrency and consistency.
当需要一致的报告数据时,只读事务很有用。快照读取显示数据在特定时间点的状态。它们防止数据更改影响长时间运行的读取。在这些操作期间,写入者不会受到阻塞。这提高了并发性和一致性。
446. What is a transaction and what does autocommit mean?
什么是事务,autocommit(自动提交)意味着什么?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67ce | 官方: 否 | 付费: 否
答案:
A transaction is a set of database operations treated as one logical unit. All changes succeed together or are rolled back together. Autocommit means each statement is automatically committed as soon as it runs. In this mode, every query acts like its own transaction. For multi-step operations, autocommit is usually turned off.
事务是一组被视为一个逻辑单元的数据库操作。所有更改要么同时成功,要么一起回滚。自动提交意味着每条语句在运行时立即自动提交。在此模式下,每个查询都像自己的事务一样。对于多步骤操作,通常关闭自动提交。
447. Explain the four isolation levels
解释四种隔离级别
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67d1 | 官方: 否 | 付费: 否
答案:
Read Uncommitted allows reading uncommitted data and can give incorrect results. Read Committed ensures only committed data is visible, but values can change between reads. Repeatable Read guarantees that rows already read won’t change during the transaction. Serializable is the strictest and behaves as if transactions run one by one. Higher isolation reduces concurrency but improves consistency.
读未提交允许读取未提交的数据,可能产生错误结果。读已提交确保只可见已提交的数据,但读取之间值可能变化。可重复读保证事务中已读取的行不会改变。可串行化是最严格的,表现为事务逐个运行。更高的隔离级别降低并发性但提升一致性。
448. Dirty read, non-repeatable read, and phantom read
脏读、不可重复读和幻读
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67d4 | 官方: 否 | 付费: 否
答案:
A dirty read happens when a transaction reads uncommitted data that may be rolled back. A non-repeatable read occurs when the same row shows different values within a transaction. Phantom reads happen when new rows appear in repeated queries with the same condition. These issues occur due to concurrent data access. Isolation levels exist to control these problems.
脏读发生在事务读取可能回滚的未提交数据时。不可重复读发生在同一事务中相同行显示不同值时。幻读发生在相同条件的重复查询中出现新行时。这些问题因并发数据访问而产生。隔离级别用于控制这些问题。
449. What is a lost update and how do you prevent it?
什么是丢失更新,如何防止?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67d7 | 官方: 否 | 付费: 否
答案:
A lost update happens when two transactions update the same data based on an old value. The second update overwrites the first without any warning. This usually occurs under low isolation. It can be prevented using proper isolation levels or version checks. Optimistic locking is a common solution.
丢失更新发生在两个事务基于旧值更新相同数据时。第二个更新覆盖第一个而不发出警告。这通常发生在低隔离级别下。可以通过适当的隔离级别或版本检查来防止。乐观锁是常见解决方案。
450. Optimistic locking vs pessimistic locking
乐观锁与悲观锁
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67da | 官方: 否 | 付费: 否
答案:
Optimistic locking assumes conflicts are rare and checks for changes before committing. It usually relies on a version number or timestamp. Pessimistic locking locks data upfront to block other transactions. This avoids conflicts but reduces concurrency. Optimistic locking suits read-heavy systems.
乐观锁假设冲突罕见,并在提交前检查变化。它通常依赖版本号或时间戳。悲观锁预先锁定数据以阻止其他事务。这避免冲突但降低并发性。乐观锁适合读密集型系统。
451. What is MVCC and how does it improve read concurrency?
什么是MVCC,它如何提高读并发性?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67e0 | 官方: 否 | 付费: 否
答案:
MVCC allows multiple versions of data to exist at the same time. Readers see a consistent snapshot without blocking writers. Writers create new versions instead of modifying existing rows. This greatly improves performance under heavy read load. Old versions are cleaned up later.
MVCC允许同时存在多个数据版本。读者看到一致的快照而不阻塞写者。写者创建新版本而不是修改现有行。这在高读负载下大幅提升性能。旧版本稍后被清理。
452. What is a deadlock and how do databases resolve it?
什么是死锁,数据库如何解决?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67e8 | 官方: 否 | 付费: 否
答案:
A deadlock happens when transactions wait on each other’s locks indefinitely. Each transaction holds a lock the other needs. Databases detect deadlocks by checking for wait cycles. One transaction is rolled back to resolve the issue. The rolled-back transaction can be retried.
死锁发生在事务无限期地相互等待对方的锁时。每个事务持有另一个需要的锁。数据库通过检查等待循环来检测死锁。一个事务被回滚以解决问题。回滚的事务可以重试。
453. What is lock escalation and why can it slow systems down?
什么是锁升级,为什么它会拖慢系统?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67eb | 官方: 否 | 付费: 否
答案:
Lock escalation replaces many small locks with a larger lock. For example, row-level locks may become a table-level lock. This reduces lock overhead but blocks more queries. As a result, system-wide slowdown can occur. It usually happens under heavy load.
锁升级将许多小锁替换为一个更大的锁。例如,行级锁可能变成表级锁。这减少锁开销但阻塞更多查询。结果,可能出现系统范围的减速。这通常发生在高负载下。
454. What is write skew and why is it tricky?
什么是写偏斜,为什么它棘手?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba67ee | 官方: 否 | 付费: 否
答案:
Write skew occurs when two transactions read the same data and update different rows. Each transaction sees valid data, but the final result breaks a rule. This can happen even under Repeatable Read isolation. Since rows aren’t directly updated, locks don’t prevent it. Serializable isolation is usually required.
写偏斜发生在两个事务读取相同数据但更新不同行时。每个事务看到的数据都是有效的,但最终结果违反了某一规则。即使在可重复读隔离级别下也可能发生这种情况。由于行未被直接更新,锁无法阻止它。通常需要可序列化隔离。
455. What are DDL and DML commands in SQL?
SQL 中的 DDL 和 DML 命令是什么?
- 知识点: 数据库 (标签: interviewbit, infosys, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Infosys
- id: 69b37b5758d557c902baf35e | 官方: 否 | 付费: 否
答案:
- DDL refers to Data Definition Language. DDL commands are used to define database schema i.e., to create and modify the database object structure in the database. Examples are CREATE, ALTER, DROP, TRUNCATE, etc.
- DML refers to Data Manipulation Language. DML commands are used to manipulate the data within the database. Examples are: INSERT, UPDATE, DELETE.
456. Why indexing in SQL is useful ?
为什么 SQL 中的索引很有用?
- 知识点: 数据库 (标签: interviewbit, infosys, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Infosys
- id: 69b37b5758d557c902baf368 | 官方: 否 | 付费: 否
答案:
A SQL index is a quick lookup table that helps to find records that are frequently searched by a user. An index is fast, small, and optimized for quick look-ups. It is useful for establishing a connection between the relational tables, searching large tables, and fast retrieval of data from a database.
SQL 索引是一种快速查找表,有助于查找用户经常搜索的记录。索引快速、小巧,并针对快速查找进行了优化。它对于建立关系表之间的连接、搜索大型表以及从数据库中快速检索数据非常有用。
457. What is the left outer join and the right outer join in SQL?
SQL 中的左外连接和右外连接是什么?
- 知识点: 数据库 (标签: interviewbit, infosys, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Infosys
- id: 69b37b5858d557c902baf383 | 官方: 否 | 付费: 否
答案:
- Left outer join: It returns an entire set of records from the left table along with the matched records from the right table.
- Right outer join: It returns an entire set of records from the right table along with the matched records from the left table.
458. How is Querying done in MongoDB?
MongoDB中如何进行查询?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd458d557c902bb4d00 | 官方: 否 | 付费: 否
答案:
The find method is used to perform queries in MongoDB. Querying returns a subset of documents in a collection, from no documents at all to the entire collection. Which documents get returned is determined by the first argument to find, which is a document specifying the query criteria.
在MongoDB中,使用find方法执行查询。查询返回集合中的文档子集,范围可以从零个文档到整个集合。哪些文档被返回由find的第一个参数决定,该参数是一个指定查询条件的文档。
For example: If we have a string we want to match, such as a "username" key with the value "alice", we use that key/value pair instead:
例如:如果我们有一个要匹配的字符串,比如一个值为"alice"的"username"键,我们使用该键/值对代替:
db.users.find({"username" : "alice"})
459. Explain the SET Modifier in MongoDB?
解释MongoDB中的SET修饰符?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd558d557c902bb4d03 | 官方: 否 | 付费: 否
答案:
If the value of a field does not yet exist, the "$set" sets the value. This can be useful for updating schemas or adding user-defined keys.
如果字段的值尚不存在,"$set"会设置该值。这对于更新模式或添加用户自定义键非常有用。
Example:
示例:
db.users.findOne()
{
"_id" : ObjectId("4b253b067525f35f94b60a31"),
"_id" : ObjectId("4b253b067525f35f94b60a31"),
"name" : "alice",
"name" : "alice",
"age" : 23,
"age" : 23,
"sex" : "female",
"sex" : "female",
"location" : "India"
"location" : "India"
}
To add a field to this, we use “$set”:
要为此添加字段,我们使用"$set":db.users.updateOne({"_id" :
ObjectId("4b253b067525f35f94b60a31")},
ObjectId("4b253b067525f35f94b60a31")},
... {"$set" : {"favorite book" : "Start with Why"}})
... {"$set" : {"favorite book" : "Start with Why"}})
460. Explain the process of Sharding.
解释分片(Sharding)的过程。
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd558d557c902bb4d06 | 官方: 否 | 付费: 否
答案:
Sharding is the process of splitting data up across machines. We also use the term “partitioning” sometimes to describe this concept. We can store more data and handle more load without requiring larger or more powerful machines, by putting a subset of data on each machine. In the figure below, RS0 and RS1 are shards. MongoDB’s sharding allows you to create a cluster of many machines (shards) and break up a collection across them, putting a subset of data on each shard. This allows your application to grow beyond the resource limits of a standalone server or replica set.
分片是将数据拆分到多台机器上的过程。我们有时也用“分区”一词来描述这一概念。通过将数据子集放在每台机器上,我们可以存储更多数据并处理更多负载,而无需更大或更强大的机器。在下图中,RS0和RS1是分片。MongoDB的分片允许您创建由多台机器(分片)组成的集群,并将集合拆分到这些机器上,将数据子集放在每个分片上。这使您的应用程序能够超越独立服务器或副本集的资源限制而扩展。
Sharded Client Connection
分片客户端连接
Non Sharded Client Connection
非分片客户端连接
461. What are Geospatial Indexes in MongoDB?
什么是MongoDB中的地理空间索引?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd558d557c902bb4d09 | 官方: 否 | 付费: 否
答案:
MongoDB has two types of geospatial indexes: 2dsphere and 2d. 2dsphere indexes work with spherical geometries that model the surface of the earth based on the WGS84 datum. This datum model the surface of the earth as an oblate spheroid, meaning that there is some flattening at the poles. Distance calculations using 2sphere indexes, therefore, take the shape of the earth into account and provide a more accurate treatment of distance between, for example, two cities, than do 2d indexes. Use 2d indexes for points stored on a two-dimensional plane.
MongoDB有两种类型的地理空间索引:2dsphere和2d。2dsphere索引适用于基于WGS84基准模拟地球表面的球面几何。该基准将地球表面建模为扁球体,这意味着两极处有一些扁平化。因此,使用2dsphere索引进行距离计算会考虑地球的形状,并提供比2d索引更准确的两地之间距离处理。对于存储在二维平面上的点,请使用2d索引。
2dsphere allows you to specify geometries for points, lines, and polygons in the GeoJSON format. A point is given by a two-element array, representing [longitude, latitude]:
2dsphere允许您以GeoJSON格式为点、线和多边形指定几何。点由两个元素数组给出,表示[经度, 纬度]:
{
"name" : "New York City",
"name" : "纽约市",
"loc" : {
"loc" : {
"type" : "Point",
"type" : "Point",
"coordinates" : [50, 2]
"coordinates" : [50, 2]
}
}
A line is given by an array of points:
一条线由点数组给出:
{
"name" : "Hudson River",
"name" : "哈德逊河",
"loc" : {
"loc" : {
"type" : "LineString",
"type" : "LineString",
"coordinates" : [[0,1], [0,2], [1,2]]
"coordinates" : [[0,1], [0,2], [1,2]]
}
}
462. Explain the term “Indexing” in MongoDB.
解释MongoDB中的术语“索引”。
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd558d557c902bb4d0c | 官方: 否 | 付费: 否
答案:
In MongoDB, indexes help in efficiently resolving queries. What an Index does is that it stores a small part of the data set in a form that is easy to traverse. The index stores the value of the specific field or set of fields, ordered by the value of the field as specified in the index. MongoDB’s indexes work almost identically to typical relational database indexes.
在MongoDB中,索引有助于高效地解析查询。索引的作用是存储数据集的一小部分,以便于遍历。索引存储特定字段或字段集的值,并按索引中指定的字段值排序。MongoDB的索引与典型的关系型数据库索引工作方式几乎相同。
Indexes look at an ordered list with references to the content. These in turn allow MongoDB to query orders of magnitude faster. To create an index, use the createIndex collection method.
索引查看一个有序列表,其中包含对内容的引用。这反过来使MongoDB能够以数量级更快的速度查询。要创建索引,请使用createIndex集合方法。
For example:
例如:
db.users.find({"username": "user101"}).explain("executionStats")
Here, executionStats mode helps us understand the effect of using an index to satisfy queries.
在这里,executionStats模式帮助我们理解使用索引满足查询的效果。
463. What are the types of relationships used in MySQL?
MySQL中使用的关系类型有哪些?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb5006 | 官方: 否 | 付费: 否
答案:
There are three categories of relationships in MySQL: - One-to-One: Usually, when two items have a one-to-one relationship, you just include them as columns in the same table.
MySQL中有三种关系类别:- 一对一:通常,当两个项目具有一对一关系时,你会将它们作为同一表中的列包含。
- One-to-Many: One-to-many (or many-to-one) relationships occur when one row in one table is linked to many rows in another table.
- Many-to-Many: In a many-to-many relationship, many rows in one table are linked to many rows in another table. To create this relationship, add a third table containing the same key column from each of the other tables
464. What are the MySQL clients and utilities?
MySQL客户端和实用程序有哪些?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb5009 | 官方: 否 | 付费: 否
答案:
Several MySQL programs are available to help you communicate with the server. For administrative tasks, some of the most important ones are listed here:
有多个 MySQL 程序可帮助您与服务器通信。对于管理任务,这里列出了一些最重要的程序:
• mysql —An interactive program that enables you to send SQL statements to the server and to view the results. You can also use mysql to execute batch scripts (text files containing SQL statements).
• mysql — 一个交互式程序,使您能够向服务器发送 SQL 语句并查看结果。您还可以使用 mysql 执行批处理脚本(包含 SQL 语句的文本文件)。
• mysqladmin —An administrative program for performing tasks such as shutting down the server, checking its configuration, or monitoring its status if it appears not to be functioning properly.
• mysqladmin — 一个管理程序,用于执行关闭服务器、检查其配置或在其似乎运行不正常时监控其状态等任务。
• mysqldump —A tool for backing up your databases or copying databases to another server.
• mysqldump — 一个用于备份数据库或将数据库复制到另一台服务器的工具。
• mysqlcheck and myisamchk —Programs that help you perform table checking, analysis, and optimization, as well as repairs if tables become damaged. mysqlcheck works with MyISAM tables and to some extent with tables for other storage engines. myisamchk is for use only with MyISAM tables.
• mysqlcheck 和 myisamchk — 帮助您执行表检查、分析和优化,以及在表损坏时进行修复的程序。mysqlcheck 适用于 MyISAM 表,并在一定程度上适用于其他存储引擎的表。myisamchk 仅用于 MyISAM 表。
465. What is the MySQL server?
什么是 MySQL 服务器?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb500c | 官方: 否 | 付费: 否
答案:
The server, mysqld, is the hub of a MySQL installation; it performs all manipulation of databases and tables.
服务器 mysqld 是 MySQL 安装的核心;它执行对数据库和表的所有操作。
466. How many Triggers are possible in MySQL?
MySQL 中可能有多少个触发器?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb5010 | 官方: 否 | 付费: 否
答案:
There are six Triggers allowed to use in the MySQL database: - Before Insert
MySQL 数据库允许使用六个触发器:- 插入前
- After Insert
- Before Update
- After Update
- Before Delete
- After Delete
467. What are MySQL Triggers?
什么是 MySQL 触发器?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb5013 | 官方: 否 | 付费: 否
答案:
A trigger is a task that executes in response to some predefined database event, such as after a new row is added to a particular table. Specifically, this event involves inserting, modifying, or deleting table data, and the task can occur either prior to or immediately following any such event. Triggers have many purposes, including: - Audit Trails
触发器是响应某些预定义数据库事件而执行的任务,例如向特定表添加新行之后。具体来说,该事件涉及插入、修改或删除表数据,任务可以在任何此类事件之前或紧随其后发生。触发器有多种用途,包括:- 审计跟踪
- Validation
- Referential integrity enforcement
468. How do you create and execute views in MySQL?
如何在 MySQL 中创建和执行视图?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb5016 | 官方: 否 | 付费: 否
答案:
Creating a view is accomplished with the CREATE VIEW statement. As an example:
创建视图通过 CREATE VIEW 语句完成。例如:
CREATE
CREATE
[OR REPLACE]
[OR REPLACE]
[ALGORITHM = {MERGE | TEMPTABLE | UNDEFINED }]
[ALGORITHM = {MERGE | TEMPTABLE | UNDEFINED }]
[DEFINER = { user | CURRENT_USER }]
[DEFINER = { user | CURRENT_USER }]
[SQL SECURITY { DEFINER | INVOKER }]
[SQL SECURITY { DEFINER | INVOKER }]
VIEW view_name [(column_list)]
VIEW view_name [(column_list)]
AS select_statement
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
[WITH [CASCADED | LOCAL] CHECK OPTION]
469. What are MySQL “Views”?
什么是MySQL“视图”?
- 知识点: 数据库 (主题: mysql, sql, database;标签: interviewbit, mysql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37bd958d557c902bb501c | 官方: 否 | 付费: 否
答案:
In MySQL, a view consists of a set of rows that is returned if a particular query is executed. This is also known as a ‘virtual table’. Views make it easy to retrieve the way of making the query available via an alias. The advantages of views are: - Simplicity
在MySQL中,视图由一组行组成,当执行特定查询时会返回这些行。这也被称为“虚拟表”。视图使得通过别名获取查询结果变得容易。视图的优点包括:- 简单性
- Security
- Maintainability
470. Write a query to find out the student with the 2nd rank from the table STUDENTS_DETAILS.
编写一个查询,从表 STUDENTS_DETAILS 中找出排名第 2 的学生。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c26 | 官方: 否 | 付费: 否
答案:
Written below is a query to find out the student with the 2nd rank from the table STUDENTS_DETAILS:-
下面编写的是一个查询,用于从表 STUDENTS_DETAILS 中找出排名第 2 的学生:-
SELECT TOP 1 rank FROM (SELECT TOP 2 rank FROM STUDENT_DETAILS ORDER BY rank DESC) AS STUDENT ORDER BY rank ASC;
SELECT TOP 1 rank FROM (SELECT TOP 2 rank FROM STUDENT_DETAILS ORDER BY rank DESC) AS STUDENT ORDER BY rank ASC;
471. State the usage of the ROWS option in the IMP command.
说明 IMP 命令中 ROWS 选项的用法。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c29 | 官方: 否 | 付费: 否
答案:
The ROWS option in the IMP command can be used to indicate whether the table rows should be imported or not.
IMP 命令中的 ROWS 选项可用于指示是否应导入表行。
472. State the usage of the IGNORE option in the IMP command.
说明 IMP 命令中 IGNORE 选项的用法。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c30 | 官方: 否 | 付费: 否
答案:
The IGNORE option in the IMP command can be used to understand how object creation errors should be handled.
IMP 命令中的 IGNORE 选项可用于理解应如何处理对象创建错误。
- Data Science
- All Events
- My Events
473. State the usage of the INDEXES option in the IMP command.
说明 IMP 命令中 INDEXES 选项的用法。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c33 | 官方: 否 | 付费: 否
答案:
The INDEXES option in the IMP command can be used to determine whether indexes are imported or not.
IMP 命令中的 INDEXES 选项可用于确定是否导入索引。
474. Give an example to convert a date to a char in Oracle.
给出一个在 Oracle 中将日期转换为字符的示例。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c36 | 官方: 否 | 付费: 否
答案:
The INDEXES option in the IMP command can be used to determine whether indexes are imported or not.
IMP 命令中的 INDEXES 选项可用于确定是否导入索引。
475. Give an example to convert a string to a date in Oracle
举一个在 Oracle 中将字符串转换为日期的例子
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c3d | 官方: 否 | 付费: 否
答案:
SELECT to_date ('2021-07-12', 'YYYY/MM/DD') FROM dual;
SELECT to_date ('2021-07-12', 'YYYY/MM/DD') FROM dual;
As we can see from the above example, the to_date() function can be used to convert a string to a date in Oracle.
从上面的例子可以看出,to_date() 函数可用于在 Oracle 中将字符串转换为日期。
476. Which function can be used to find the current date and time of the operating system on which the Oracle database is running?
哪个函数可用于查找运行 Oracle 数据库的操作系统的当前日期和时间?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: coding
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c40 | 官方: 否 | 付费: 否
答案:
The SYSDATE() function can be used to find the current date and time of the operating system on which the Oracle database is running. The example given below shows how to do the same:-
SYSDATE() 函数可用于查找运行 Oracle 数据库的操作系统的当前日期和时间。下面给出的示例展示了如何做到这一点:-
SELECT TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS') "Current Date:" FROM DUAL;
SELECT TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS') "Current Date:" FROM DUAL;
477. Explain actual parameters with an example.
举例说明实际参数。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c43 | 官方: 否 | 付费: 否
答案:
Actual parameters are defined as the variables or expressions referenced in the parameter list of a subprogram. An example of a procedure call that lists two actual parameters named empNumber and amount is as follows:-
实际参数被定义为在子程序的参数列表中引用的变量或表达式。一个过程调用的示例列出了两个名为 empNumber 和 amount 的实际参数,如下所示:-
updateSalary(empNumber,amount);
updateSalary(empNumber,amount);
478. Explain formal parameters with an example.
举例说明形式参数。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c46 | 官方: 否 | 付费: 否
答案:
Formal parameters can be defined as variables declared in a subprogram specification and referenced in the subprogram body. An example of a procedure that declares two formal parameters named empID and amount: is as follows:-
形式参数可以定义为在子程序规范中声明并在子程序体中引用的变量。一个声明了两个名为 empID 和 amount 的形式参数的过程示例如下:-
PROCEDURE updateSalary(empID INTEGER, amount REAL) IS currentSalary REAL;
PROCEDURE updateSalary(empID INTEGER, amount REAL) IS currentSalary REAL;
Successful Tech Career for FREE!
免费开启成功的科技职业生涯!
Successful Tech Career!
成功的技术职业生涯!
Interview Process
面试流程
CTC & Designation
CTC与职位级别
Projects on the Job
工作项目
Referral System
推荐系统
Try It Out
试试看
2 Lakh+ Roadmaps Created
已生成20万+职业规划
479. Write a query to find the average salary of employees from the Emp Oracle Table.
编写一个查询,从Emp Oracle表中找出员工的平均工资。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c49 | 官方: 否 | 付费: 否
答案:
A query to find the average salary of employees from the Emp Oracle Table is given below:-
下面给出了一个从Emp Oracle表中找出员工平均工资的查询:-
SELECT AVG(SALARY) FROM EMP GROUP BY SALARY;
SELECT AVG(SALARY) FROM EMP GROUP BY SALARY;
480. Write a query to list the duplicate values in an Oracle table.
编写一个查询,列出Oracle表中的重复值。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c4c | 官方: 否 | 付费: 否
答案:
Written below is a query to list the duplicate values in an Oracle table:-
下面写的是一个列出Oracle表中重复值的查询:-
SELECT NAME, COUNT (NAME) FROM EMPLOYEE GROUP BY NAME HAVING COUNT (NAME) > 1;
SELECT NAME, COUNT (NAME) FROM EMPLOYEE GROUP BY NAME HAVING COUNT (NAME) > 1;
481. State the usage of the GRANT option in the IMP command.
说明IMP命令中GRANT选项的用途。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c4f | 官方: 否 | 付费: 否
答案:
The GRANT option in the IMP command can be used to import object grants.
IMP命令中的GRANT选项可用于导入对象授权。
482. Illustrate the use of the TRANSLATE function with an example.
用一个示例说明 TRANSLATE 函数的用法。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: coding
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c52 | 官方: 否 | 付费: 否
答案:
The TRANSLATE function of Oracle is used for replacing a sequence of characters in a string with some other set of characters. The TRANSLATE function replaces a single character at a time. Let us take a look at an example of translating the string "ROLL41" to "RAMM42" with the help of the TRANSLATE function.
Oracle 的 TRANSLATE 函数用于将字符串中的一系列字符替换为另一组字符。TRANSLATE 函数每次替换一个字符。让我们看一个借助 TRANSLATE 函数将字符串 "ROLL41" 转换为 "RAMM42" 的示例。
TRANSLATE("ROLL41", "OL1", "AM2");
TRANSLATE("ROLL41", "OL1", "AM2");
483. Illustrate the use of the REPLACE function with an example.
用一个示例说明 REPLACE 函数的用法。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: coding
- 分类: general
- 公司: Oracle
- id: 69b37c0958d557c902bb6c56 | 官方: 否 | 付费: 否
答案:
The REPLACE function of Oracle is used for replacing a sequence of characters in a string with some other set of characters. Let us take a look at an example to translate the string "R12S121" to "R34S341" with the help of the REPLACE function.
Oracle 的 REPLACE 函数用于将字符串中的一系列字符替换为另一组字符。让我们看一个借助 REPLACE 函数将字符串 "R12S121" 转换为 "R34S341" 的示例。
REPLACE("R12S121", "12", "34");
REPLACE("R12S121", "12", "34");
Note that every occurrence of the substring "12" is replaced by the substring "34".
注意,子字符串 "12" 的每一次出现都会被替换为子字符串 "34"。
Recommended Resources
推荐资源
- SQL Interview Questions
- DBMS Interview Questions
484. What do you understand about the memory layers that are in the Oracle shared pool?
你对 Oracle 共享池中的内存层了解多少?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c5a | 官方: 否 | 付费: 否
答案:
There are two memory layers in the Oracle shared pool:- - Library Cache - The information about the SQL statements that were parsed, data about cursors, and any plan data that might be present is present in the Library Cache.
Oracle 共享池中有两个内存层:- - 库缓存 - 已解析的 SQL 语句信息、游标数据以及可能存在的任何计划数据都存在于库缓存中。
- Data Dictionary Cache - The Data Dictionary Cache layer contains information about the accounts of the users, their privileges, and information about segments.
485. List the various components of the physical database structure of an Oracle database.
列出 Oracle 数据库物理数据库结构的各个组件。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c5d | 官方: 否 | 付费: 否
答案:
The different components of the physical database structure of an Oracle database are listed below:- - Greater than equal to two redo log files.
Oracle 数据库物理数据库结构的各个组件如下所示:- - 大于等于两个重做日志文件。
- Greater than equal to one data file.
- Greater than equal to one control file.
486. The Oracle database has been developed using which language?
Oracle 数据库是使用哪种语言开发的?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c61 | 官方: 否 | 付费: 否
答案:
The C language was used to develop the Oracle database.
Oracle 数据库是使用 C 语言开发的。
487. What is the logical storage structure of Oracle? List the main components of the logical database structure in the Oracle database.
Oracle 的逻辑存储结构是什么?列出 Oracle 数据库中逻辑数据库结构的主要组件。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c67 | 官方: 否 | 付费: 否
答案:
The Oracle Database allocates logical space for all data in the database in addition to the physical files. The logical units of database space allocation are data blocks, extents, segments, and tablespaces. At a physical level, the data is stored in data files on a disk. The data in the data files are stored in operating system blocks.
除了物理文件之外,Oracle 数据库还为数据库中的所有数据分配逻辑空间。数据库空间分配的逻辑单元是数据块、区、段和表空间。在物理层面上,数据存储在磁盘上的数据文件中。数据文件中的数据存储在操作系统块中。
There are two main components in the logical database structure of the Oracle database:-
Oracle 数据库的逻辑数据库结构中有两个主要组件:-
Tablespaces: The basic storage allocation in an Oracle database is a tablespace. Each tablespace is composed of one or more physical (operating system) files. The SYSTEM tablespace is used to create each and every database. Other tablespaces are created by the Database Administrator. 2. Database's schema objects: A schema in Oracle is similar to an account or a username. Each object in the database is owned by a schema. Every Oracle database is created with two initial schemas: SYS, which is used to store the data dictionary, and SYSTEM, which often stores some data dictionary extensions as well as critical tables for other tools. Other schemas are created by the DBA. Each schema can be granted quotas in any tablespace.
- 表空间:Oracle 数据库中的基本存储分配是表空间。每个表空间由一个或多个物理(操作系统)文件组成。SYSTEM 表空间用于创建每一个数据库。其他表空间由数据库管理员创建。 2. 数据库的模式对象:Oracle 中的模式类似于账户或用户名。数据库中的每个对象都归某个模式所有。每个 Oracle 数据库在创建时都会有两个初始模式:SYS,用于存储数据字典;以及 SYSTEM,通常存储一些数据字典扩展以及其他工具所需的关键表。其他模式由 DBA 创建。每个模式都可以在任何表空间中被授予配额。
488. Define a tablespace in context with the Oracle database.
结合 Oracle 数据库的上下文定义表空间。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c6a | 官方: 否 | 付费: 否
答案:
The Logical Storage Unit of an Oracle database is called a tablespace. It is nothing but a set of related logical structures. Tablespace groups relate the logical structures of the database together. Logically, the data is stored in the tablespaces in Oracle and physically, the data is stored in the datafiles associated with the respective tablespaces.
Oracle 数据库的逻辑存储单元称为表空间。它不过是一组相关的逻辑结构。表空间组将数据库的逻辑结构关联在一起。在逻辑上,数据在 Oracle 中存储在表空间中;在物理上,数据存储在与其各自表空间关联的数据文件中。
489. List the default tablespaces of Oracle.
列出 Oracle 的默认表空间。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c6d | 官方: 否 | 付费: 否
答案:
The default tablespaces of Oracle are as follows:-
Oracle 的默认表空间如下:-
The SYSTEM and SYSAUX tablespaces - These store system-generated objects such as data dictionary tables in them. One should not store any object in these tablespaces. 2. The USERS tablespace - It is used for ad-hoc users. 3. The UNDOTBS1 tablespace - Is used for holding the undo data. 4. The TEMP tablespace - It is the temporary tablespace that is used for storing intermediate results of sorting, hashing, and large object processing operations.
- SYSTEM 和 SYSAUX 表空间 - 这些表空间存储系统生成的对象,例如其中的数据字典表。不应在这些表空间中存储任何对象。 2. USERS 表空间 - 它用于临时用户。 3. UNDOTBS1 表空间 - 用于保存撤销数据。 4. TEMP 表空间 - 它是临时表空间,用于存储排序、哈希和大对象处理操作的中间结果。
490. What is the fundamental difference between an online and an offline tablespace?
在线表空间和离线表空间之间的根本区别是什么?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c70 | 官方: 否 | 付费: 否
答案:
If a tablespace is offline, we cannot access data stored in it. In contrast to that, if a tablespace is online, the data of the tablespace is available for reading as well as writing.
如果表空间处于离线状态,我们就无法访问存储在其中数据。与此相反,如果表空间处于在线状态,那么该表空间的数据可供读取和写入。
491. Define a SYSTEM tablespace. When it is created?
定义 SYSTEM 表空间。它何时被创建?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c73 | 官方: 否 | 付费: 否
答案:
When any database is created in the Oracle database system, a SYSTEM tablespace is automatically generated. The Data dictionary tables for the entire database are present in The SYSTEM tablespace. It is important that the SYSTEM tablespace remains online always as it contains the data dictionary that must be available to Oracle.
在 Oracle 数据库系统中创建任何数据库时,都会自动生成一个 SYSTEM 表空间。整个数据库的数据字典表都存在于 SYSTEM 表空间中。SYSTEM 表空间始终保持在线非常重要,因为它包含 Oracle 必须可用的数据字典。
492. Define an Oracle table.
定义 Oracle 表。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c76 | 官方: 否 | 付费: 否
答案:
An Oracle table is a basic unit of data storage in an Oracle database. Every accessible information of any user is present in rows and columns of an Oracle table.
Oracle 表是 Oracle 数据库中数据存储的基本单元。任何用户可访问的每条信息都存在于 Oracle 表的行和列中。
493. Define a snapshot in the context of an Oracle database.
结合 Oracle 数据库的上下文定义快照。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c79 | 官方: 否 | 付费: 否
答案:
Oracle uses snapshots, which are also known as materialized views, in order to replicate data to the non-master sites in a replicated environment. Snapshots are also used to cache the "expensive" queries in a data warehouse environment. So in short, a snapshot is nothing but a copy of the target master table from a single point in time.
Oracle 使用快照(也称为物化视图)将数据复制到复制环境中的非主站点。快照也用于在数据仓库环境中缓存“昂贵”的查询。简而言之,快照不过是从单个时间点对目标主表的副本。
494. What do you understand by the RAW datatype?
你对 RAW 数据类型了解多少?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c7c | 官方: 否 | 付费: 否
答案:
The RAW datatype is used to store values in binary data format in an Oracle Database. The maximum size for a RAW datatype in a table is 32767 bytes.
RAW 数据类型用于在 Oracle 数据库中以二进制数据格式存储值。表中 RAW 数据类型的最大大小为 32767 字节。
495. What do you understand by a savepoint in the Oracle database?
你对 Oracle 数据库中的保存点有何理解?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c7f | 官方: 否 | 付费: 否
答案:
Savepoints can be used to break a transaction into smaller parts. It also allows the rolling back of a transaction. At any given time, at most five save points are allowed. Savepoints save our data, and therefore, whenever we encounter an error, we can roll back to the point where we had saved our SAVEPOINT.
保存点可用于将事务分解为更小的部分。它还允许回滚事务。在任何给定时间,最多允许五个保存点。保存点保存我们的数据,因此,每当我们遇到错误时,我们都可以回滚到我们保存 SAVEPOINT 的位置。
496. Describe the various Oracle database objects in brief.
简要描述各种 Oracle 数据库对象。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c82 | 官方: 否 | 付费: 否
答案:
The description of various Oracle database objects is as follows:- - Tables: Tables are a set of elements organized in a vertical and horizontal fashion.
各种 Oracle 数据库对象的描述如下:- - 表:表是以垂直和水平方式组织的一组元素。
- Tablespaces: Tablespaces are the logical storage unit in Oracle.
- Views: A view can be defined as a virtual table that has been derived from one or multiple tables.
- Indexes: Indexes are a performance-tuning method to process the records.
- Synonyms: Synonyms are names for tables.
497. State the usage of the ANALYZE command in Oracle.
说明 Oracle 中 ANALYZE 命令的用法。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c85 | 官方: 否 | 付费: 否
答案:
The ANALYZE command in Oracle can be used to perform a number of functions on indexes, tables, or clusters. Some of the use cases of the ANALYZE command in Oracle are as follows:- - The ANALYZE command can be used to find out migrated and chained rows of the table or cluster. Also, it can be used to validate the structure of the object.
Oracle 中的 ANALYZE 命令可用于对索引、表或簇执行多种功能。Oracle 中 ANALYZE 命令的一些用例如下:- - ANALYZE 命令可用于找出表或簇中迁移和链接的行。此外,它还可用于验证对象的结构。
- It helps in collecting the statistics about objects which the optimizer is using. After that, they are stored in the data dictionary.
- It helps in deleting statistics used by objects from the data dictionary.
498. Define hash clusters in Oracle.
定义 Oracle 中的哈希簇。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c88 | 官方: 否 | 付费: 否
答案:
A hash cluster provides an alternative to a non-clustered table with an index or an index cluster. Using indexed tables or index clusters, the Oracle Database is able to locate the rows in a table using key values that the database stores in a separate index.
哈希簇为带索引的非簇表或索引簇提供了一种替代方案。使用索引表或索引簇,Oracle 数据库能够使用数据库存储在单独索引中的键值来定位表中的行。
499. State the most common types of modules in Oracle forms.
说明 Oracle 表单中最常见的模块类型。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c8b | 官方: 否 | 付费: 否
答案:
The most common types of modules in Oracle forms are as follows:- - Form module.
Oracle 表单中最常见的模块类型如下:- - 表单模块。
- Menu module.
- Pl/SQL Library module.
- Object Library module.
500. Define a synonym in the Oracle database and state its types.
定义 Oracle 数据库中的同义词并说明其类型。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c8e | 官方: 否 | 付费: 否
答案:
Synonyms are defined as aliases for tables, views, sequences or program units. There are two types of synonyms in the Oracle database:- - Private Synonyms: These synonyms are only accessible to the owner.
同义词被定义为表、视图、序列或程序单元的别名。Oracle 数据库中有两种类型的同义词:- - 私有同义词:这些同义词仅所有者可访问。
- Public Synonyms: These synonyms are accessible to any database user.
501. Which data type in the Oracle database has a varying length binary string?
Oracle 数据库中哪种数据类型具有可变长度的二进制字符串?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c91 | 官方: 否 | 付费: 否
答案:
The BLOB data type in the Oracle database has a varying length binary string. It is used to store two gigabytes of memory and for it, the length needs to be specified in bytes. An example to illustrate the usage of the BLOB data type is given below:-
Oracle 数据库中的 BLOB 数据类型具有可变长度的二进制字符串。它用于存储两千兆字节的内存,并且需要以字节为单位指定长度。下面给出了一个说明 BLOB 数据类型用法的示例:-
Creating a table:-
创建表:-
create table photos(name varchar(32) not null primary key, picture blob(10M));
create table photos(name varchar(32) not null primary key, picture blob(10M));
Querying for all logotype pictures:-
查询所有标志图片:-
select name,length(picture) from photos where name like '%logo%';
select name,length(picture) from photos where name like '%logo%';
502. Describe Logical backup in Oracle.
描述 Oracle 中的逻辑备份。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c94 | 官方: 否 | 付费: 否
答案:
The Logical backup mechanism is for reading a set of database records and writing them into a file. We can use an Export utility to take the backup while an Import utility can be used to recover from the backup.
逻辑备份机制用于读取一组数据库记录并将其写入文件。我们可以使用导出实用程序进行备份,而导入实用程序可用于从备份中恢复。
503. What do you understand by recursive hints in Oracle.
你对 Oracle 中的递归提示了解多少?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c97 | 官方: 否 | 付费: 否
答案:
We can define a recursive hint as to the number of times a dictionary table is continuously called by various processes. Recursive hints occur because of the small size of the data dictionary cache.
我们可以将递归提示定义为字典表被各种进程连续调用的次数。递归提示的产生是由于数据字典缓存的大小较小。
504. State the limitations of the CHECK constraint.
陈述 CHECK 约束的局限性。
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6c9a | 官方: 否 | 付费: 否
答案:
The biggest limitation of the CHECK constraint is as follows:- The condition needs to be a boolean expression that is being evaluated using the values in the row being inserted or updated. It can also not contain any subqueries whatsoever.
CHECK 约束的最大局限性如下:- 条件必须是一个布尔表达式,使用正在插入或更新的行中的值进行评估。它也不能包含任何子查询。
Oracle Interview Preparation
505. How many rounds are conducted in an Oracle interview for a Software Engineer?
Oracle 软件工程师面试要进行几轮?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6ccb | 官方: 否 | 付费: 否
答案:
There are around 3-4 Interview Rounds: Online Coding Round(One Round), Technical Round (2 Rounds), and HR Round.
大约有 3-4 轮面试:在线编码轮(一轮)、技术轮(2 轮)和 HR 轮。
506. Why do you want to join Oracle?
你为什么想加入 Oracle?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6cce | 官方: 否 | 付费: 否
答案:
There are a lot of high-quality products which Oracle employees work on every day and the amount of opportunity that Oracle presents its employees is humongous. Also, the work culture is really good over there and the compensation offered to Oracle employees is on the higher end of the standards of the Information Technology or Software Industry.
Oracle 员工每天处理大量高质量产品,Oracle 为其员工提供的机会是巨大的。此外,那里的工作文化非常好,Oracle 员工获得的薪酬处于信息技术或软件行业标准的高端。
507. Are Oracle interviews hard?
Oracle 面试难吗?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6cd1 | 官方: 否 | 付费: 否
答案:
The toughness of an interview depends upon the amount of hard work you have put in to prepare for them. Usually, the questions asked in a standard Oracle interview are of Easy to Medium Level but it varies from person to person. Since the number of interview rounds range anywhere from four to seven, it can be intimidating at times for a candidate. But if you are in, it is going to be worth the effort.
面试的难度取决于你为准备面试所付出的努力。通常,标准 Oracle 面试中提出的问题属于简单到中等水平,但因人而异。由于面试轮数从四到七轮不等,有时对候选人来说可能令人生畏。但如果你被录取了,这些努力都是值得的。
508. What are some of the questions which one should ask the interviewer at Oracle?
在 Oracle 面试时应该问面试官哪些问题?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6cd6 | 官方: 否 | 付费: 否
答案:
It is always nice to ask questions about the company’s culture and what is the current technology using which the company makes its products. Asking about the future innovations at Oracle also might be a good idea as it might make the interviewer believe that you are looking forward to joining Oracle for a long time. You can also ask about the interviewer’s personal experience at Oracle and what skills you must develop before you join the job.
询问公司文化以及公司目前使用哪些技术来制造产品总是好的。询问 Oracle 未来的创新也可能是个好主意,因为这可能会让面试官相信你希望长期加入 Oracle。你还可以询问面试官在 Oracle 的个人经历,以及你在入职前必须培养哪些技能。
509. What are some of the famous products of Oracle?
Oracle 有哪些著名产品?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6cdb | 官方: 否 | 付费: 否
答案:
Some of the famous products of Oracle are as follows:-
Oracle 的一些著名产品如下:
Oracle Database 2. Oracle E-Business Suite 3. PeopleSoft Enterprise 4. Siebel 5. Oracle JDeveloper, a freeware IDE
- Oracle Database 2. Oracle E-Business Suite 3. PeopleSoft Enterprise 4. Siebel 5. Oracle JDeveloper,一个免费软件 IDE
510. What are the skills required for an Oracle developer?
Oracle 开发者需要哪些技能?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6cde | 官方: 否 | 付费: 否
答案:
As mentioned previously in this article, having a good knowledge of Java will definitely prove to be helpful to an Oracle developer. Also, having a thorough knowledge of SQL databases, cloud technologies and various models of software engineering, for instance, Agile Method, Waterfall Method, etc. might prove to be useful.
如本文前面所述,具备良好的 Java 知识肯定会对 Oracle 开发者有所帮助。此外,全面了解 SQL 数据库、云技术和各种软件工程模型,例如 Agile Method、Waterfall Method 等,也可能会有用。
511. How do I get hired in Oracle?
我如何被 Oracle 录用?
- 知识点: 数据库 (标签: interviewbit, oracle, company-specific)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: general
- 公司: Oracle
- id: 69b37c0a58d557c902bb6ce1 | 官方: 否 | 付费: 否
答案:
As is the case with any other software company, Oracle also looks forward to hiring people with extremely good problem-solving skills. Someone who is well-versed in Data Structures and Algorithms and can apply them in real-world problems will definitely have a good chance of getting hired at Oracle. Also, having a few good projects, preferably using Java and its frameworks like Spring, etc. also might increase the chance of one getting hired at Oracle.
与其他任何软件公司一样,Oracle 也期待招聘具有极强问题解决能力的人。精通数据结构与算法,并能将其应用于现实世界问题的人,肯定有很好的机会被 Oracle 录用。此外,拥有一些优秀的项目,最好使用 Java 及其框架如 Spring 等,也可能增加被 Oracle 录用的机会。
Coding Problems
0/3
Easy Problems
简单问题
Arrays
数组
Puzzles
谜题
Tree Data Structure
树数据结构
Set Matrix Zeros
矩阵置零
Easy
简单
48.4 Mins
48.4 分钟
Solve
解答
Make a Statement
发表声明
Easy
简单
4.35 Mins
4.35 分钟
Solve
解答
Diameter of Binary Tree
二叉树的直径
Easy
简单
18.25 Mins
18.25 分钟
Solve
解答
0/1
Intermediate Problems
中级问题
Tree Data Structure
树数据结构
Max Depth of Binary Tree
二叉树的最大深度
Medium
中等
6.57 Mins
6.57 分钟
Solve
解答
512. What is the use of SYS.ALL_DEPENDENCIES?
SYS.ALL_DEPENDENCIES的用途是什么?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb754a | 官方: 否 | 付费: 否
答案:
- SYS.ALL_DEPENDENCIES is used for describing all the dependencies between procedures, packages, triggers, functions that are accessible to the current user. It returns the columns like name, dependency_type, type, referenced_owner etc.
513. What are the virtual tables available during the execution of the database trigger?
在数据库触发器执行期间可用的虚拟表有哪些?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb754d | 官方: 否 | 付费: 否
答案:
- The THEN and NOW tables are the virtual tables that are available during the database trigger execution. The table columns are referred to as THEN.column and NOW.column respectively.
- Only the NOW.column is available for insert-related triggers.
- Only the THEN.column values are available for the DELETE-related triggers.
- Both the virtual table columns are available for UPDATE triggers.
514. Differentiate between the cursors declared in procedures and the cursors declared in the package specifications.
区分在过程声明的游标和在包规范中声明的游标。
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7550 | 官方: 否 | 付费: 否
答案:
- The cursors that are declared in the procedures will have the local scope and hence they cannot be used by other procedures.
- The cursors that are declared in package specifications are treated with global scope and hence they can be used and accessed by other procedures.
515. What is the difference between ROLLBACK and ROLLBACK TO statements in PL/SQL?
在PL/SQL中,ROLLBACK和ROLLBACK TO语句有什么区别?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7553 | 官方: 否 | 付费: 否
答案:
- ROLLBACK command is used for rolling back all the changes from the beginning of the transaction.
- ROLLBACK TO command is used for undoing the transaction only till a SAVEPOINT. The transactions cannot be rolled back before the SAVEPOINT and hence the transaction remains active even before the command is specified.
516. What are the various functions available for manipulating the character data?
有哪些用于操作字符数据的函数?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: coding
- 分类: fullstack
- id: 69b37c1a58d557c902bb7556 | 官方: 否 | 付费: 否
答案:
- The functions that are used for manipulating the character data are called String Functions.
LEFT: This function returns the specified number of characters from the left part of a string.
LEFT:此函数返回字符串左侧指定数量的字符。
Syntax: LEFT(string_value, numberOfCharacters).
语法:LEFT(string_value, numberOfCharacters)。
For example, LEFT(‘InterviewBit’, 9) will return ‘Interview’.
例如,LEFT(‘InterviewBit’, 9) 将返回 ‘Interview’。
RIGHT: This function returns the defined number of characters from the right part of a string. Syntax: RIGHT(string_value, numberOfCharacters) For example, RIGHT(‘InterviewBit’,3) would return ‘Bit’.
RIGHT:此函数返回字符串右侧指定数量的字符。语法:RIGHT(string_value, numberOfCharacters) 例如,RIGHT(‘InterviewBit’,3) 将返回 ‘Bit’。
SUBSTRING: This function would select the data from a specified start position through the number of characters defined from any part of the string. Syntax: SUBSTRING(string_value, start_position, numberOfCharacters) For example, SUBSTRING(‘InterviewBit’,2,4) would return ‘terv’.
SUBSTRING:此函数将从字符串中任意部分指定的起始位置开始,选取指定字符数的数据。语法:SUBSTRING(string_value, start_position, numberOfCharacters) 例如,SUBSTRING(‘InterviewBit’,2,4) 将返回‘terv’。
LTRIM: This function would trim all the white spaces on the left part of the string. Syntax: LTRIM(string_value) For example, LTRIM(’ InterviewBit’) will return ‘InterviewBit’.
LTRIM:此函数将去除字符串左侧的所有空白字符。语法:LTRIM(string_value) 例如,LTRIM(’ InterviewBit’) 将返回‘InterviewBit’。
RTRIM: This function would trim all the white spaces on the right part of the string. Syntax: RTRIM(string_value) For example, RTRIM('InterviewBit ') will return ‘InterviewBit’.
RTRIM:此函数将去除字符串右侧的所有空白字符。语法:RTRIM(string_value) 例如,RTRIM('InterviewBit ') 将返回‘InterviewBit’。
UPPER: This function is used for converting all the characters to the upper case in a string. Syntax: UPPER(string_variable) For example, UPPER(‘interviewBit’) would return ‘INTERVIEWBIT’.
UPPER:此函数用于将字符串中的所有字符转换为大写。语法:UPPER(string_variable) 例如,UPPER(‘interviewBit’) 将返回‘INTERVIEWBIT’。
LOWER: This function is used for converting all the characters of a string to lowercase. Syntax: LOWER(string_variable) For example, LOWER(‘INterviewBit’) would return ‘interviewbit’.
LOWER:此函数用于将字符串中的所有字符转换为小写。语法:LOWER(string_variable) 例如,LOWER(‘INterviewBit’) 将返回‘interviewbit’。
517. What is the importance of %TYPE and %ROWTYPE data types in PL/SQL?
在PL/SQL中,%TYPE和%ROWTYPE数据类型的重要性是什么?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7559 | 官方: 否 | 付费: 否
答案:
- %TYPE: This declaration is used for the purpose of anchoring by providing the data type of any variable, column, or constant. It is useful during the declaration of a variable that has the same data type as that of its table column.Consider the example of declaring a variable named ib_employeeid which has the data type and its size same as that of the column employeeid in table ib_employee. The syntax would be : ib_employeeid ib_employee.employeeid%TYPE;
- %ROWTYPE: This is used for declaring a variable that has the same data type and size as that of a row in the table. The row of a table is called a record and its fields would have the same data types and names as the columns defined in the table.For example: In order to declare a record named ib_emprecord for storing an entire row in a table called ib_employee, the syntax is:ib_emprecord ib_employee%ROWTYPE;
518. Differentiate between SQL and PL/SQL.
区分SQL和PL/SQL。
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb755c | 官方: 否 | 付费: 否
答案:
| SQL | PL/SQL |
|---|---|
| SQL is a natural language meant for the interactive processing of data in the database. SQL是一种用于数据库中数据交互式处理的自然语言。 | PL/SQL is a procedural extension of SQL. PL/SQL是SQL的过程化扩展。 |
| Decision-making and looping are not allowed in SQL. SQL中不允许决策和循环。 | PL/SQL supports all features of procedural language such as conditional and looping statements. PL/SQL支持过程语言的所有特性,如条件和循环语句。 |
| All SQL statements are executed at a time by the database server which is why it becomes a time-consuming process. 所有SQL语句由数据库服务器一次执行,因此这是一个耗时的过程。 | PL/SQL statements are executed one block at a time thereby reducing the network traffic. PL/SQL语句逐块执行,从而减少网络流量。 |
| There is no error handling mechanism in SQL. SQL中没有错误处理机制。 | This supports an error handling mechanism. 这支持错误处理机制。 |
519. Differentiate between implicit cursor and explicit cursor.
区分隐式游标和显式游标。
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb755f | 官方: 否 | 付费: 否
答案:
| Implicit Cursor 隐式游标 | Explicit Cursor 显式游标 |
|---|---|
| An implicit cursor is used when a query returns a single row value. 当查询返回单行值时,使用隐式游标。 | When a subquery returns more than one row, an explicit cursor is used. These rows are called Active Set. 当子查询返回多行时,使用显式游标。这些行称为活动集。 |
| This is used for all DML operations like DECLARE, OPEN, FETCH, CLOSE. 这用于所有DML操作,如DECLARE、OPEN、FETCH、CLOSE。 | This is used to process Multirow SELECT Statements. 这用于处理多行SELECT语句。 |
| NO_DATA_FOUND Exception is handled here. 这里处理NO_DATA_FOUND异常。 | NO_DATA_FOUND cannot be handled here. 这里无法处理NO_DATA_FOUND。 |
520. Why is SYSDATE and USER keywords used?
为什么要使用SYSDATE和USER关键字?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c1a58d557c902bb7562 | 官方: 否 | 付费: 否
答案:
SYSDATE:
This keyword returns the current time and date on the local database server.此关键字返回本地数据库服务器上的当前时间和日期。
The syntax is SYSDATE.
语法是SYSDATE。
In order to extract part of the date, we use the TO_CHAR function on SYSDATE and specify the format we need.
为了提取日期的一部分,我们在SYSDATE上使用TO_CHAR函数,并指定所需格式。
Usage:
用法:
SELECT SYSDATE FROM dual;
SELECT SYSDATE FROM dual;
SELECT id, TO_CHAR(SYSDATE, 'yyyy/mm/dd') from InterviewBitEmployeeTable where customer_id - USER:
从InterviewBitEmployeeTable表中选择id,将系统日期格式化为'yyyy/mm/dd',其中customer_id等于当前用户:
This keyword returns the user id of the current session.
该关键字返回当前会话的用户ID。
Usage:SELECT USER FROM dual;
用法:从dual中选择USER;
521. Can you explain the PL/SQL execution architecture?
你能解释一下PL/SQL的执行架构吗?
- 知识点: 数据库 (主题: pl-sql, oracle, database;标签: interviewbit, pl-sql, topic-specific, oracle, database)
- 类型: technical | 难度: medium | 子类型: system-design
- 分类: fullstack
- id: 69b37c1a58d557c902bb7565 | 官方: 否 | 付费: 否
答案:
The PL/SQL engine does the process of compilation and execution of the PL/SQL blocks and programs and can only work if it is installed on an Oracle server or any application tool that supports Oracle such as Oracle Forms. - PL/SQL is one of the parts of Oracle RDBMS, and it is important to know that most of the Oracle applications are developed using the client-server architecture. The Oracle database forms the server-side and requests to the database form a part of the client-side.
PL/SQL引擎负责PL/SQL块和程序的编译与执行过程,且仅当安装在Oracle服务器或支持Oracle的应用程序工具(如Oracle Forms)上时才能运行。- PL/SQL是Oracle RDBMS的组成部分之一,重要的是要知道大多数Oracle应用程序都是基于客户端-服务器架构开发的。Oracle数据库构成服务器端,对数据库的请求构成客户端的一部分。
- So based on the above fact and the fact that PL/SQL is not a standalone programming language, we must realize that the PL/SQL engine can reside in either the client environment or the server environment. This makes it easy to move PL/SQL modules and sub-programs between server-side and client-side applications.
- Based on the architecture shown below, we can understand that PL/SQL engine plays an important role in the process and execute the PL/SQL statements and whenever it encounters the SQL statements, they are sent to the SQL Statement Processor.
- Case 1: PL/SQL engine is on the server: In this case, the whole PL/SQL block gets passed to the PL/SQL engine present on the Oracle server which is then processed and the response is sent.
Case 2: PL/SQL engine is on the client: Here the engine lies within the Oracle Developer tools and the processing of the PL/SQL statements is done on the client-side.
In case, there are any SQL statements in the PL/SQL block, then they are sent to the Oracle server for SQL processing. When there are no SQL statements, then the whole block processing occurs at the client-side.如果PL/SQL块中有任何SQL语句,则它们会发送到Oracle服务器进行SQL处理。当没有SQL语句时,整个块的处理在客户端进行。
522. What is the difference between a primary key and a unique key?
主键和唯一键有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bb1 | 官方: 否 | 付费: 否
答案:
A Primary Key uniquely identifies each record in a table and cannot be NULL, whereas a Unique Key ensures uniqueness but allows one NULL value.
主键唯一标识表中的每条记录且不能为NULL,而唯一键确保唯一性但允许一个NULL值。
| Feature 特性 | Primary Key 主键 | Unique Key 唯一键 |
|---|---|---|
| Uniqueness 唯一性 | Must be unique 必须唯一 | Must be unique 必须唯一 |
| NULL Values NULL值 | Not allowed 不允许 | One NULL allowed 允许一个NULL |
| Number per Table 每表数量 | Only one 仅一个 | Multiple allowed 允许多个 |
| Purpose 用途 | Record identification 记录标识 | Data uniqueness 数据唯一性 |
| Index Created 创建索引 | Automatically 自动 | Automatically 自动 |
523. What is the difference Between WHERE Clause and the HAVING Clause
WHERE子句和HAVING子句之间有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bb6 | 官方: 否 | 付费: 否
答案:
The WHERE clause filters rows before grouping, while HAVING filters grouped data after aggregation.
WHERE子句在分组前过滤行,而HAVING在聚合后过滤分组数据。
| Aspect | WHERE Clause | HAVING Clause |
|---|---|---|
| Purpose | Filters rows before grouping | Filters groups after grouping |
| Used With | SELECT, UPDATE, DELETE | Only with SELECT (usually with GROUP BY) |
| Works On | Individual rows | Aggregate/grouped data |
| Aggregate Functions | Cannot be used with aggregate functions | Can be used with aggregate functions |
| Execution Order | Evaluated before GROUP BY | Evaluated after GROUP BY |
| Example | WHERE salary > 50000 | HAVING COUNT(*) > 3 |
524. What are DDL, DML, DCL, TCL, and DQL in SQL?
SQL中的DDL、DML、DCL、TCL和DQL分别是什么?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bb9 | 官方: 否 | 付费: 否
答案:
- DDL: Data Definition Language is used to create, modify, and drop the schema of database objects. CREATE, ALTER TABLE, DROP, TRUNCATE, and ADD COLUMN are DDL commands.
- DML: Data Manipulation Language allows for changing or manipulating the existing data of the tables. UPDATE, DELETE, and INSERT are DML commands.
- DCL: Data Control Language allows the administrator of the database to manage the rights and permissions of the users in the database. GRANT and REVOKE are DCL commands.
- TCL: Transaction Control Language is used to maintain the SQL operations within the database. It also allows the changes to be saved, which are made by the DML commands. COMMIT, SET TRANSACTION, ROLLBACK, and SAVEPOINT are examples of TCL commands.
- DQL: Data Query Language is used to retrieve data from databases using the SELECT statement.
Table of Contents:
目录:
- SQL Difference-Based Interview Questions
- SQL Basics & Core Concepts Interview Questions
- SQL Joins & Table Relationships Interview Questions
- SQL Query-Based & Scenario-Driven Interview Questions
- Advanced SQL & Database Architecture Interview Questions
525. What is the difference between the Drop vs Delete commands?
Drop和Delete命令有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bbc | 官方: 否 | 付费: 否
答案:
DELETE removes rows from a table, while DROP removes the entire table structure permanently.
DELETE从表中删除行,而DROP永久删除整个表结构。
| Feature
特性 | DELETE | DROP |
| Removes Data 删除数据 | Yes 是 | Yes 是 |
| Removes Structure 删除结构 | No 否 | Yes 是 |
| WHERE Clause WHERE子句 | Supported 支持 | Not supported 不支持 |
| Rollback Possible 可回滚 | Yes (with transaction) 是(带事务) | No 否 |
| Use Case 使用场景 | Delete specific records 删除特定记录 | Remove the table completely 完全移除表 |
526. What is the difference between BETWEEN and IN Operators
BETWEEN 和 IN 运算符有什么区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bbf | 官方: 否 | 付费: 否
答案:
BETWEEN selects values within a range, while IN matches values from a specified list.
BETWEEN 选择某个范围内的值,而 IN 匹配指定列表中的值。
| Feature
特性 | BETWEEN | IN |
| Type 类型 | Range-based 基于范围 | List-based 基于列表 |
| Inclusive 包含边界 | Yes 是 | N/A 不适用 |
| Readability 可读性 | Best for ranges 最适合范围 | Best for multiple values 最适合多个值 |
| Performance 性能 | Efficient for ranges 对范围高效 | Efficient for lists 对列表高效 |
| Example 示例 | Salary BETWEEN 10k AND 50k 薪资 BETWEEN 10k AND 50k | ID IN (1,2,3) |
527. What is the difference between SQL and NoSQL Databases
SQL 和 NoSQL 数据库有什么区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bc6 | 官方: 否 | 付费: 否
答案:
SQL databases are relational, table-based, and schema-driven, while NoSQL databases are non-relational, schema-flexible, and designed for high scalability.
SQL 数据库是关系型、基于表且由模式驱动的,而 NoSQL 数据库是非关系型、模式灵活且为高可扩展性设计的。
| Feature
特性 | SQL Databases
SQL 数据库 | NoSQL Databases
NoSQL 数据库 |
| Data Structure 数据结构 | Tables (rows & columns) 表(行和列) | Documents, Key-Value, Graph 文档、键值、图 |
| Schema 模式 | Fixed schema 固定模式 | Dynamic schema 动态模式 |
| Scalability 可扩展性 | Vertical 垂直 | Horizontal 水平 |
| ACID Compliance ACID 合规性 | Fully supported 完全支持 | Limited / Eventual 有限/最终一致 |
| Use Case 使用场景 | Complex queries 复杂查询 | Big data, real-time apps 大数据、实时应用 |
528. What is the difference between SQL and **PL/SQL
SQL 和 PL/SQL 有什么区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bc9 | 官方: 否 | 付费: 否
答案:
SQL is used to query and manage data, whereas PL/SQL adds procedural capabilities like loops, conditions, and exception handling.
SQL 用于查询和管理数据,而 PL/SQL 添加了过程化能力,如循环、条件和异常处理。
| Feature
特性 | SQL | PL/SQL |
| Type 类型 | Query language 查询语言 | Procedural extension 过程化扩展 |
| Control Structures 控制结构 | Not supported 不支持 | Supported 支持 |
| Execution 执行方式 | One statement at a time 一次一条语句 | Block execution 块执行 |
| Error Handling 错误处理 | Limited 有限 | Advanced 高级 |
| Usage 用途 | Data manipulation 数据操作 | Business logic 业务逻辑 |
529. What is the difference between On-Premise SQL and **Cloud SQL
本地 SQL 和 云 SQL 有什么区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bcc | 官方: 否 | 付费: 否
答案:
On-premise SQL runs on local infrastructure, while Cloud SQL is managed, scalable, and hosted on cloud platforms.
本地 SQL 在本地基础设施上运行,而云 SQL 是托管、可扩展且部署在云平台上的。
| Feature
特性 | On-Premise SQL
本地 SQL | Cloud SQL
云 SQL |
| Infrastructure 基础设施 | Local servers 本地服务器 | Cloud-hosted 云托管 |
| Scalability 可扩展性 | Limited 有限 | High 高 |
| Maintenance 维护 | Manual 手动 | Managed 托管 |
| Cost Model 成本模式 | High upfront 前期成本高 | Pay-as-you-go 按需付费 |
| Availability 可用性 | Local access 本地访问 | Global access 全局访问 |
530. What is the difference between INNER JOIN and **SELF JOIN
INNER JOIN 和 SELF JOIN 有什么区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bcf | 官方: 否 | 付费: 否
答案:
INNER JOIN combines rows from two tables based on a condition, while SELF JOIN joins a table with itself.
INNER JOIN 基于条件合并两个表中的行,而 SELF JOIN 将表与自身进行连接。
| Feature
特性 | INNER JOIN | SELF JOIN |
| Tables Used 使用的表 | Two different tables 两个不同的表 | Same table 同一个表 |
| Purpose 目的 | Match related records 匹配相关记录 | Hierarchical data 层次结构数据 |
| Syntax 语法 | Simple 简单 | Uses aliases 使用别名 |
| Common Use 常见用途 | Relational data 关系数据 | Employee–manager relation 员工-经理关系 |
| Complexity 复杂度 | Low 低 | Moderate 中等 |
531. What is the difference between LEFT JOIN and **RIGHT JOIN
LEFT JOIN 和 RIGHT JOIN 有什么区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bd2 | 官方: 否 | 付费: 否
答案:
A LEFT JOIN returns all records from the left table and matching records from the right, whereas a RIGHT JOIN returns all records from the right table and matching records from the left.
LEFT JOIN(左连接)返回左表中的所有记录以及右表中匹配的记录,而RIGHT JOIN(右连接)返回右表中的所有记录以及左表中匹配的记录。
| Feature 特性 | LEFT JOIN | RIGHT JOIN |
|---|---|---|
| Base Table 基表 | Left table 左表 | Right table 右表 |
| Non-matching Rows 不匹配的行 | From the left table 来自左表 | From the right table 来自右表 |
| NULL Values NULL值 | Right side 在右侧 | Left side 在左侧 |
| Usage 使用频率 | More commonly used 更常用 | Less commonly used 较少用 |
| Logic 逻辑 | A ← B | A → B |
532. What is the difference between a FULL JOIN and a **CARTESIAN JOIN
FULL JOIN(全连接)和CARTESIAN JOIN(笛卡尔连接)之间有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bd5 | 官方: 否 | 付费: 否
答案:
A FULL JOIN returns all matching and non-matching rows from both tables, while a CARTESIAN JOIN returns every possible row combination.
FULL JOIN(全连接)返回两个表中的所有匹配和不匹配的行,而CARTESIAN JOIN(笛卡尔连接)返回所有可能的行组合。
| Feature 特性 | FULL JOIN | CARTESIAN JOIN |
|---|---|---|
| Matching Condition 匹配条件 | Required 必需 | Not required 不需要 |
| Output Size 输出大小 | Controlled 可控 | Very large 非常大 |
| NULL Handling NULL处理 | For non-matches 用于不匹配项 | No NULL logic 无NULL逻辑 |
| Performance 性能 | Moderate 中等 | Very slow 非常慢 |
| Use Case 使用场景 | Complete comparison 完整比较 | Rare / testing only 罕见/仅测试使用 |
533. What is the difference between JOINs and the UNION Clause
JOIN(连接)和UNION(并集)子句之间有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bd8 | 官方: 否 | 付费: 否
答案:
JOINs combine columns from multiple tables, while UNION combines rows from multiple SELECT queries.
JOIN(连接)组合多个表中的列,而UNION(并集)组合多个SELECT查询中的行。
| Feature
特性 | JOIN | UNION |
| Combines 组合对象 | Columns 列 | Rows 行 |
| Tables Required 所需表 | Related tables 相关表 | Same column structure 相同列结构 |
| Duplicate Handling 重复处理 | Allowed 允许 | Removed (UNION) 移除(UNION) |
| WHERE Condition WHERE条件 | Used across tables 跨表使用 | Used per query 每个查询分别使用 |
| Use Case 使用场景 | Relational data 关系数据 | Merging results 合并结果 |
534. What is the difference between NULL, 0, and **Empty String (“”)?
NULL、0和空字符串("")之间有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bdf | 官方: 否 | 付费: 否
答案:
NULL means no value, 0 is a numeric value, and an empty string represents a value with no characters.
NULL表示没有值,0是一个数字值,而空字符串表示一个没有字符的值。
| Feature
特性 | NULL | 0 | Empty String (“”)
空字符串("") |
| Meaning 含义 | No value 没有值 | Numeric value 数字值 | Blank text 空白文本 |
| Data Type 数据类型 | Any 任意 | Numeric 数字 | String 字符串 |
| Comparison 比较 | Needs IS NULL 需要使用IS NULL | Normal comparison 正常比较 | Normal comparison 正常比较 |
| Storage 存储 | No memory 不占用内存 | Stored 存储 | Stored 存储 |
| Common Mistake 常见错误 | Treated as zero 被视为零 | Confused with NULL 与NULL混淆 | Confused with NULL 与NULL混淆 |
535. Difference between CHAR, VARCHAR, and VARCHAR2
CHAR、VARCHAR和VARCHAR2之间的区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7be2 | 官方: 否 | 付费: 否
答案:
CHAR is a fixed-length datatype, VARCHAR is a variable-length datatype, and VARCHAR2 is an Oracle-specific datatype recommended for safe and efficient string storage.
CHAR是固定长度的数据类型,VARCHAR是可变长度的数据类型,而VARCHAR2是Oracle特有的数据类型,推荐用于安全高效的字符串存储。
| Feature 特性 | CHAR | VARCHAR | VARCHAR2 |
|---|---|---|---|
| Length Type 长度类型 | Fixed 固定 | Variable 可变 | Variable 可变 |
| Storage 存储 | Wastes unused space 浪费未使用的空间 | Efficient 高效 | More efficient 更高效 |
| Trailing Spaces 尾随空格 | Padded automatically 自动填充 | Not padded 不填充 | Not padded 不填充 |
| Database Support 数据库支持 | All databases 所有数据库 | Most databases 大多数数据库 | Oracle only 仅Oracle |
| Recommended Usage 推荐使用 | Rare 很少 | Conditional 有条件 | Yes (Oracle) 是(Oracle) |
536. Difference between Clustered and Non-Clustered Indexes
聚集索引和非聚集索引之间的区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7be6 | 官方: 否 | 付费: 否
答案:
A clustered index defines the physical order of data in a table, while a non-clustered index maintains a separate structure with pointers to data rows.
聚集索引定义了表中数据的物理顺序,而非聚集索引维护一个带有指向数据行指针的单独结构。
| Feature 特性 | Clustered Index 聚集索引 | Non-Clustered Index 非聚集索引 |
|---|---|---|
| Data Storage 数据存储 | Physically sorted 物理排序 | Logical structure 逻辑结构 |
| Indexes per Table 每表索引数 | Only one 仅一个 | Multiple allowed 允许多个 |
| Search Speed 搜索速度 | Faster 更快 | Slightly slower 稍慢 |
| Extra Storage 额外存储 | No 否 | Yes 是 |
| Common Use 常见用途 | Primary key 主键 | Frequently queried columns 频繁查询的列 |
537. Difference between OLTP and OLAP
OLTP 和 OLAP 之间的区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7be9 | 官方: 否 | 付费: 否
答案:
OLTP systems handle real-time transactional operations, whereas OLAP systems are designed for complex analytical queries and reporting.
OLTP 系统处理实时事务操作,而 OLAP 系统专为复杂分析查询和报告而设计。
| Feature 特性 | OLTP | OLAP |
|---|---|---|
| Primary Purpose 主要目的 | Transaction processing 事务处理 | Data analysis 数据分析 |
| Operations 操作 | INSERT, UPDATE, DELETE INSERT、UPDATE、DELETE | Complex SELECT queries 复杂 SELECT 查询 |
| Data Volume 数据量 | Small per transaction 每笔事务较小 | Very large 非常大 |
| Response Time 响应时间 | Very fast 非常快 | Moderate 适中 |
| Examples 示例 | Banking systems, e-commerce 银行系统、电子商务 | Reporting, business intelligence 报告、商业智能 |
538. Difference between RDBMS and DBMS
RDBMS 和 DBMS 之间的区别
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5b58d557c902bc7bec | 官方: 否 | 付费: 否
答案:
A DBMS stores and manages data, while an RDBMS organizes data into relational tables with keys, constraints, and relationships.
DBMS 存储和管理数据,而 RDBMS 将数据组织成具有键、约束和关系的关系型表。
| Feature 特性 | DBMS | RDBMS |
|---|---|---|
| Data Storage 数据存储 | Files 文件 | Tables 表 |
| Relationships 关系 | Not supported 不支持 | Supported 支持 |
| Normalization 规范化 | Not available 不可用 | Available 可用 |
| Multi-User Support 多用户支持 | Limited 有限 | Advanced 高级 |
| Examples 示例 | File-based systems 基于文件的系统 | MySQL, PostgreSQL, Oracle MySQL、PostgreSQL、Oracle |
539. What is SQL JOIN?
什么是 SQL JOIN?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c59 | 官方: 否 | 付费: 否
答案:
The SQL JOIN component joins rows from one or more tables in a relational database. Create sets that can be stored in tabular form or used routinely. JOIN is to combine columns from one table or multiple tables using the same value.
SQL JOIN 组件用于连接关系数据库中一个或多个表中的行。创建可以以表格形式存储或常规使用的数据集。JOIN 是使用相同值组合一个或多个表中的列。
540. What are the different types of JOINs in SQL?
SQL 中有哪些不同类型的 JOIN?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c5c | 官方: 否 | 付费: 否
答案:
There are six different types of JOINs in SQL, which are: - INNER JOIN: An INNER JOIN is used to return records of the same value in two tables.
SQL 中有六种不同类型的 JOIN,分别是:- INNER JOIN:INNER JOIN 用于返回两个表中具有相同值的记录。
- LEFT JOIN: LEFT JOIN is used to join all the rows in the left table with matching rows in the right table.
- RIGHT JOIN: RIGHT JOIN is used to join all the rows in the right table with the corresponding rows in the left table.
- FULL JOIN: A FULL JOIN is used to return all records from two tables, if there are matching records in each table.
- SELF JOIN: A SELF JOIN is a join used to join a table to itself. SELF JOINS treats one table as two tables.
- CARTESIAN JOIN: A CARTESIAN Integral is used to multiply the number of rows in the first table by the number of rows in the second table. It is also called a CROSS JOIN.
541. Is a SELF JOIN an INNER JOIN or an OUTER JOIN?
SELF JOIN 是 INNER JOIN 还是 OUTER JOIN?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c5f | 官方: 否 | 付费: 否
答案:
The SELF JOIN can be an INNER JOIN, OUTER JOIN, or a CROSS JOIN. SELF JOIN is used to link tables automatically based on columns that contain duplicate data in multiple rows.
SELF JOIN 可以是 INNER JOIN、OUTER JOIN 或 CROSS JOIN。SELF JOIN 用于基于多行中包含重复数据的列自动关联表。
542. What is NATURAL JOIN?
什么是 NATURAL JOIN?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c62 | 官方: 否 | 付费: 否
答案:
A NATURAL JOIN in SQL is a kind of join that automatically combines two tables only by the common columns that have the same name and compatible data types. Unlike INNER JOIN or EQUI JOIN, a NATURAL JOIN doesn’t require an explicit join condition using the ON clause.
SQL 中的 NATURAL JOIN 是一种自动仅通过具有相同名称和兼容数据类型的公共列来组合两个表的连接类型。与 INNER JOIN 或 EQUI JOIN 不同,NATURAL JOIN 不需要使用 ON 子句显式指定连接条件。
It implicitly matches columns with identical names in both tables and returns rows where the values in those columns are equal.
它隐式匹配两个表中名称相同的列,并返回这些列中值相等的行。
543. What is an EQUI JOIN?
什么是等值连接?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c65 | 官方: 否 | 付费: 否
答案:
An EQUI JOIN is a type of join operation in a database that combines rows from two or more tables based on a matching condition using the equality operator (=). It is used to retrieve data where values in specified columns are equal.
等值连接是数据库中的一种连接操作,它基于使用等号(=)的匹配条件来合并两个或多个表中的行。它用于检索指定列中值相等的相关数据。
Here is an example of the syntax for an EQUI JOIN:
以下是等值连接语法的一个示例:
SELECT column_name(s) FROM table1 JOIN table2
SELECT column_name(s) FROM table1 JOIN table2
-- Matches rows
-- 匹配行
where values in the specified columns are equal ON
使用 ON 指定列中的值相等
table1.column_name = table2.column_name. copy
table1.column_name = table2.column_name. copy
544. Can you join a table to itself in SQL?
在SQL中,可以将表与自身连接吗?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c68 | 官方: 否 | 付费: 否
答案:
Yes, in SQL, it is possible to join a table to itself, which is known as a self-join. By using table aliases, you can treat the same table as two separate entities and perform a join operation on them based on specified conditions. Self-joins are used when you need to retrieve information by comparing rows within the same table.
是的,在SQL中,可以将表与自身连接,这被称为自连接。通过使用表别名,您可以将同一表视为两个独立的实体,并根据指定条件对它们执行连接操作。当您需要通过比较同一表中的行来检索信息时,会使用自连接。
545. What is a HASH JOIN?
什么是哈希连接?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c6b | 官方: 否 | 付费: 否
答案:
A HASH JOIN requires two inputs, an INNER table and an OUTER table. HASH JOINS involve using a HASH table to identify matching rows between two tables. HASH JOINS are an option when other joins are not recommended. When joining large data sets that are unsorted or non-indexed, HASH JOINS are better.
哈希连接需要两个输入,一个内部表和一个外部表。哈希连接涉及使用哈希表来识别两个表之间的匹配行。当其他连接方式不推荐时,哈希连接是一种选择。当连接未排序或未索引的大型数据集时,哈希连接更好。
546. What is MERGE JOIN?
什么是合并连接?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c6e | 官方: 否 | 付费: 否
答案:
MERGE JOIN is one of the most important join types in SQL Server. In MERGE JOIN, your query plan is effective, and you don’t need to make many changes to improve query performance because the MERGE JOIN operator uses ordered data entry, it can use two large data sets.
合并连接是SQL Server中最重要的连接类型之一。在合并连接中,您的查询计划是高效的,您不需要做太多更改来改善查询性能,因为合并连接运算符使用有序数据输入,它可以处理两个大型数据集。
547. Can you explain NESTED JOIN in SQL?
您能解释SQL中的嵌套连接吗?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c71 | 官方: 否 | 付费: 否
答案:
In SQL, a Nested Join (also referred to as a Nested Loop Join) is the basic method that most relational databases employ for connecting two tables. It is the default approach that database engines frequently use for joining small or medium datasets.
在SQL中,嵌套连接(也称为嵌套循环连接)是大多数关系数据库用于连接两个表的基本方法。它是数据库引擎在连接小型或中型数据集时经常使用的默认方法。
In a Nested Join, one table is treated as the outer table, and for each row in this outer table, the system searches for matching rows in the inner table. This process repeats until all matching combinations are found.
在嵌套连接中,一个表被视为外部表,对于这个外部表中的每一行,系统都会在内部表中搜索匹配的行。这个过程会重复,直到找到所有匹配组合。
548. How do you map a Many-to-Many relationship?
如何映射多对多关系?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c76 | 官方: 否 | 付费: 否
答案:
A Many-to-Many relationship is mapped using a Junction Table (also called a Bridge Table) that stores the relationships between two tables.
多对多关系通过一个连接表(也称为桥接表)来映射,该表存储两个表之间的关系。
In a many-to-many relationship, multiple records in one table can be related to multiple records in another table. Since relational databases do not support many-to-many relationships directly, a junction table is used to resolve this. - The junction table contains foreign keys from both related tables
在多对多关系中,一个表中的多条记录可以与另一个表中的多条记录相关。由于关系型数据库不直接支持多对多关系,因此使用连接表来解决这一问题。- 连接表包含来自两个相关表的外键
- Each foreign key references the primary key of a parent table
- The combination of foreign keys usually forms a composite primary key
- Ensures data integrity and avoids redundancy
549. What is a Cross-Join (Cartesian Product)?
什么是交叉连接(笛卡尔积)?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c79 | 官方: 否 | 付费: 否
答案:
A Cross Join produces a Cartesian Product by combining every row from one table with every row from another table.
交叉连接通过将一个表中的每一行与另一个表中的每一行组合来生成笛卡尔积。
If the first table has N rows and the second table has M rows, the result of a cross join will contain N × M rows. - No join condition is required
如果第一个表有N行,第二个表有M行,则交叉连接的结果将包含N × M行。- 不需要连接条件
- Produces all possible row combinations
- Can generate very large result sets
- Mostly used for testing or generating combinations
550. Explain Common Table Expressions in SQL.
解释SQL中的公用表表达式。
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c80 | 官方: 否 | 付费: 否
答案:
In general, a Common Table Expressions (CTEs) is a temporary, named result set that can be used to refer to an UPDATE, INSERT, SELECT, or DELETE statement. A CTE can be specified by adding WITH before an UPDATE, INSERT, DELETE, SELECT, or MERGE statement. Multiple CTEs can be used in the WITH clause by separating them with commas.
一般来说,公用表表达式(CTEs)是一个临时的、命名的结果集,可用于引用UPDATE、INSERT、SELECT或DELETE语句。可以通过在UPDATE、INSERT、DELETE、SELECT或MERGE语句前添加WITH来指定CTE。在WITH子句中,多个CTE可以用逗号分隔。
551. What is a recursive CTE?
什么是递归CTE?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c83 | 官方: 否 | 付费: 否
答案:
A recursive CTE (Common Table Expression) is a SQL construct that enables a query to refer to itself in order to carry out iterative tasks. Generally, it is used to handle hierarchical or tree-like data, such as employee-management hierarchies or category-subcategory structure
递归CTE(公用表表达式)是一种SQL构造,它使查询能够引用自身以执行迭代任务。通常,它用于处理层次结构或树状数据,如员工管理层级或类别-子类别结构。
Example syntax:
示例语法:
WITH RECURSIVE employee_hierarchy AS (
WITH RECURSIVE employee_hierarchy AS (
SELECT id, name, manager_id FROM employees
SELECT id, name, manager_id FROM employees
WHERE manager_id IS NULL UNION ALL
WHERE manager_id IS NULL UNION ALL
SELECT e.id, e.name, e.manager_id FROM employees e
SELECT e.id, e.name, e.manager_id FROM employees e
INNER JOIN employee_hierarchy eh ON e.manager_id = eh.id )
INNER JOIN employee_hierarchy eh ON e.manager_id = eh.id )
SELECT * FROM employee_hierarchy; copy
SELECT * FROM employee_hierarchy; copy
Understand how hierarchical recursive queries work in MySQL through this blog.
通过这篇博客了解MySQL中分层递归查询的工作原理。
552. How will you structure data to perform a JOIN Operation in a one-to-many relationship situation?
在一对多关系情况下,你将如何组织数据来执行JOIN操作?
- 知识点: 数据库 (主题: sql, database;标签: intellipaat, sql, topic-specific, sql, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5c58d557c902bc7c86 | 官方: 否 | 付费: 否
答案:
To create a one-to-many relationship, you need to add the primary key from one side to many sides as a column. To create a many-to-many relationship, you need a middle table that contains the primary keys from the many-to-many tables.
要创建一对多关系,你需要将一侧的主键作为列添加到多侧。要创建多对多关系,你需要一个中间表,其中包含多对多表的主键。
553. What is a Cross-Join?
什么是交叉连接(Cross-Join)?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d7a | 官方: 否 | 付费: 否
答案:
Cross join can be defined as a cartesian product of the two tables included in the join. The table after join contains the same number of rows as in the cross-product of the number of rows in the two tables. If a WHERE clause is used in cross join then the query will work like an INNER JOIN.
交叉连接可以定义为两表连接时的笛卡尔积。连接后的表包含的行数与两表行数的交叉乘积相同。如果在交叉连接中使用了WHERE子句,那么查询将类似于内连接(INNER JOIN)的工作方式。
SELECT stu.name, sub.subject
SELECT stu.name, sub.subject
FROM students AS stu
FROM students AS stu
CROSS JOIN subjects AS sub;
CROSS JOIN subjects AS sub;
Write a SQL statement to CROSS JOIN 'table_1' with 'table_2' and fetch 'col_1' from table_1 & 'col_2' from table_2 respectively. Do not use alias.
编写一条SQL语句,对'table_1'和'table_2'执行CROSS JOIN,分别从table_1中获取'col_1',从table_2中获取'col_2'。不要使用别名。
Check
检查
Write a SQL statement to perform SELF JOIN for 'Table_X' with alias 'Table_1' and 'Table_2', on columns 'Col_1' and 'Col_2' respectively.
编写一条SQL语句,对'Table_X'执行SELF JOIN,使用别名'Table_1'和'Table_2',分别基于列'Col_1'和'Col_2'。
Check
检查
554. List the different types of relationships in SQL.
列出SQL中不同类型的关系。
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d7d | 官方: 否 | 付费: 否
答案:
- One-to-One - This can be defined as the relationship between two tables where each record in one table is associated with the maximum of one record in the other table.
- One-to-Many & Many-to-One - This is the most commonly used relationship where a record in a table is associated with multiple records in the other table.
- Many-to-Many - This is used in cases when multiple instances on both sides are needed for defining a relationship.
- Self-Referencing Relationships - This is used when a table needs to define a relationship with itself.
555. What are Entities and Relationships?
什么是实体和关系?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d80 | 官方: 否 | 付费: 否
答案:
Entity : An entity can be a real-world object, either tangible or intangible, that can be easily identifiable. For example, in a college database, students, professors, workers, departments, and projects can be referred to as entities. Each entity has some associated properties that provide it an identity.
实体:实体可以是现实世界中的对象,无论是有形的还是无形的,且易于识别。例如,在学院数据库中,学生、教授、工作人员、部门和项目都可以称为实体。每个实体都具有一些关联属性,为其提供身份标识。
Relationships : Relations or links between entities that have something to do with each other. For example - The employee's table in a company's database can be associated with the salary table in the same database.
关系:实体之间彼此相关的关联或链接。例如,公司数据库中的员工表可以与同一数据库中的薪资表关联。
556. What is Cursor? How to use a Cursor?
什么是游标?如何使用游标?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d83 | 官方: 否 | 付费: 否
答案:
A database cursor is a control structure that allows for the traversal of records in a database. Cursors, in addition, facilitates processing after traversal, such as retrieval, addition, and deletion of database records. They can be viewed as a pointer to one row in a set of rows.
数据库游标是一种控制结构,允许遍历数据库中的记录。此外,游标还便于遍历后的处理,例如检索、添加和删除数据库记录。它们可以被视为指向一组行中某一行的指针。
Working with SQL Cursor:
使用 SQL 游标:
DECLARE a cursor after any variable declaration. The cursor declaration must always be associated with a SELECT Statement. 2. Open cursor to initialize the result set. The OPEN statement must be called before fetching rows from the result set. 3. FETCH statement to retrieve and move to the next row in the result set. 4. Call the CLOSE statement to deactivate the cursor. 5. Finally use the DEALLOCATE statement to delete the cursor definition and release the associated resources.
- 在任何变量声明之后声明一个游标。游标声明必须始终与 SELECT 语句关联。 2. 打开游标以初始化结果集。在从结果集中获取行之前,必须调用 OPEN 语句。 3. 使用 FETCH 语句检索并移动到结果集中的下一行。 4. 调用 CLOSE 语句以停用游标。 5. 最后使用 DEALLOCATE 语句删除游标定义并释放相关资源。
DECLARE @name VARCHAR(50) / Declare All Required Variables /
DECLARE @name VARCHAR(50) / 声明所有所需变量 /
DECLARE db_cursor CURSOR FOR / Declare Cursor Name/
DECLARE db_cursor CURSOR FOR / 声明游标名称 /
SELECT name
SELECT name
FROM myDB.students
FROM myDB.students
WHERE parent_name IN ('Sara', 'Ansh')
WHERE parent_name IN ('Sara', 'Ansh')
OPEN db_cursor / Open cursor and Fetch data into @name /
OPEN db_cursor / 打开游标并将数据提取到 @name /
FETCH next
FETCH next
FROM db_cursor
FROM db_cursor
INTO @name
INTO @name
CLOSE db_cursor / Close the cursor and deallocate the resources /
CLOSE db_cursor / 关闭游标并释放资源 /
DEALLOCATE db_cursor
DEALLOCATE db_cursor
557. What are UNION, MINUS and INTERSECT commands?
UNION、MINUS 和 INTERSECT 命令是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d86 | 官方: 否 | 付费: 否
答案:
The UNION operator combines and returns the result-set retrieved by two or more SELECT statements. The MINUS operator in SQL is used to remove duplicates from the result-set obtained by the second SELECT query from the result-set obtained by the first SELECT query and then return the filtered results from the first. The INTERSECT clause in SQL combines the result-set fetched by the two SELECT statements where records from one match the other and then returns this intersection of result-sets.
UNION 运算符合并并返回由两个或多个 SELECT 语句检索到的结果集。SQL 中的 MINUS 运算符用于从第一个 SELECT 查询获得的结果集中移除第二个 SELECT 查询获得的结果集中的重复项,然后返回第一个查询的过滤结果。SQL 中的 INTERSECT 子句合并两个 SELECT 语句检索到的结果集,其中一个的记录与另一个匹配,然后返回这些结果集的交集。
Certain conditions need to be met before executing either of the above statements in SQL - - Each SELECT statement within the clause must have the same number of columns
在 SQL 中执行上述任一语句前,需要满足某些条件——子句中的每个 SELECT 语句必须具有相同数量的列
- The columns must also have similar data types
The columns in each SELECT statement should necessarily have the same order
SELECT name FROM Students / Fetch the union of queries /SELECT name FROM Students / 获取查询的并集 /
UNION
UNION
SELECT name FROM Contacts;
SELECT name FROM Contacts;
SELECT name FROM Students / Fetch the union of queries with duplicates/
SELECT name FROM Students / 获取带重复项的查询并集 /
UNION ALL
UNION ALL
SELECT name FROM Contacts;
SELECT name FROM Contacts;
SELECT name FROM Students / Fetch names from students /
SELECT name FROM Students / 从学生中获取姓名 /
MINUS / that aren't present in contacts /
MINUS / 那些不在联系人中出现的 /
SELECT name FROM Contacts;
SELECT name FROM Contacts;
SELECT name FROM Students / Fetch names from students /
SELECT name FROM Students / 从学生中获取姓名 /
INTERSECT / that are present in contacts as well /
INTERSECT / 那些也出现在联系人中的 /
SELECT name FROM Contacts;
SELECT name FROM Contacts;
Write a SQL query to fetch "names" that are present in either table "accounts" or in table "registry".
编写一个 SQL 查询来获取“姓名”,这些姓名出现在表“accounts”或表“registry”中。
Check
检查
Write a SQL query to fetch "names" that are present in "accounts" but not in table "registry".
编写一个 SQL 查询来获取“姓名”,这些姓名出现在“accounts”中但不在表“registry”中。
Check
检查
Write a SQL query to fetch "names" from table "contacts" that are neither present in "accounts.name" nor in "registry.name".
编写一个SQL查询,从“contacts”表中获取既不在“accounts.name”中也不在“registry.name”中的“names”。
Check
检查
558. What are some common clauses used with SELECT query in SQL?
SQL中与SELECT查询一起使用的常见子句有哪些?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d89 | 官方: 否 | 付费: 否
答案:
Some common SQL clauses used in conjuction with a SELECT query are as follows: - WHERE clause in SQL is used to filter records that are necessary, based on specific conditions.
SQL中与SELECT查询一起使用的一些常见子句如下:- SQL中的WHERE子句用于根据特定条件过滤必要的记录。
ORDER BY clause in SQL is used to sort the records based on some field(s) in ascending (ASC) or descending order (DESC).
SELECT *SELECT *
FROM myDB.students
FROM myDB.students
WHERE graduation_year = 2019
WHERE graduation_year = 2019
ORDER BY studentID DESC; - GROUP BY clause in SQL is used to group records with identical data and can be used in conjunction with some aggregation functions to produce summarized results from the database.
ORDER BY studentID DESC; - SQL中的GROUP BY子句用于分组具有相同数据的记录,可以与一些聚合函数结合使用,从数据库生成汇总结果。HAVING clause in SQL is used to filter records in combination with the GROUP BY clause. It is different from WHERE, since the WHERE clause cannot filter aggregated records.
SELECT COUNT(studentId), countrySELECT COUNT(studentId), country
FROM myDB.students
FROM myDB.students
WHERE country != "INDIA"
WHERE country != "INDIA"
GROUP BY country
GROUP BY country
HAVING COUNT(studentID) > 5;
HAVING COUNT(studentID) > 5;
559. What is the SELECT statement?
什么是SELECT语句?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d8c | 官方: 否 | 付费: 否
答案:
SELECT operator in SQL is used to select data from a database. The data returned is stored in a result table, called the result-set.
SQL中的SELECT运算符用于从数据库中选择数据。返回的数据存储在结果表中,称为结果集。
SELECT * FROM myDB.students;
SELECT * FROM myDB.students;
560. What is a Subquery? What are its types?
什么是子查询?它有哪些类型?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d8f | 官方: 否 | 付费: 否
答案:
A subquery is a query within another query, also known as a nested query or inner query . It is used to restrict or enhance the data to be queried by the main query, thus restricting or enhancing the output of the main query respectively. For example, here we fetch the contact information for students who have enrolled for the maths subject:
子查询是另一个查询内部的查询,也称为嵌套查询或内查询。它用于限制或增强主查询要查询的数据,从而分别限制或增强主查询的输出。例如,这里我们获取已报名数学科目的学生的联系信息:
SELECT name, email, mob, address
SELECT name, email, mob, address
FROM myDb.contacts
FROM myDb.contacts
WHERE roll_no IN (
WHERE roll_no IN (
SELECT roll_no
SELECT roll_no
FROM myDb.students
FROM myDb.students
WHERE subject = 'Maths');
WHERE subject = 'Maths');
There are two types of subquery - Correlated and Non-Correlated . - A correlated subquery cannot be considered as an independent query, but it can refer to the column in a table listed in the FROM of the main query.
子查询有两种类型——相关子查询和非相关子查询。相关子查询不能被视为独立查询,但它可以引用主查询的FROM列表中表内的列。
A non-correlated subquery can be considered as an independent query and the output of the subquery is substituted in the main query.
Write a SQL query to update the field "status" in table "applications" from 0 to 1.编写一个SQL查询,将表“applications”中的字段“status”从0更新为1。
Check
检查
Write a SQL query to select the field "app_id" in table "applications" where "app_id" less than 1000.
编写一个SQL查询,选择表“applications”中字段“app_id”小于1000的记录。
Check
检查
Write a SQL query to fetch the field "app_name" from "apps" where "apps.id" is equal to the above collection of "app_id".
编写一个SQL查询,从“apps”中获取字段“app_name”,其中“apps.id”等于上述“app_id”的集合。
Check
检查
561. What is a Query?
什么是查询?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d92 | 官方: 否 | 付费: 否
答案:
A query is a request for data or information from a database table or combination of tables. A database query can be either a select query or an action query.
查询是从数据库表或表组合中请求数据或信息的操作。数据库查询可以是选择查询或操作查询。
SELECT fname, lname / select query /
SELECT fname, lname / 选择查询 /
FROM myDb.students
FROM myDb.students
WHERE student_id = 1;
WHERE student_id = 1;
UPDATE myDB.students / action query /
UPDATE myDB.students / 操作查询 /
SET fname = 'Captain', lname = 'America'
SET fname = 'Captain', lname = 'America'
WHERE student_id = 1;
WHERE student_id = 1;
562. What is Data Integrity?
什么是数据完整性?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d95 | 官方: 否 | 付费: 否
答案:
Data Integrity is the assurance of accuracy and consistency of data over its entire life-cycle and is a critical aspect of the design, implementation, and usage of any system which stores, processes, or retrieves data. It also defines integrity constraints to enforce business rules on the data when it is entered into an application or a database.
数据完整性是在整个生命周期中确保数据准确性和一致性的保证,是任何存储、处理或检索数据的系统的设计、实现和使用中的关键方面。它还定义了完整性约束,以在数据进入应用程序或数据库时强制执行业务规则。
563. What is the difference between Clustered and Non-clustered index?
聚集索引和非聚集索引有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d98 | 官方: 否 | 付费: 否
答案:
As explained above, the differences can be broken down into three small factors - - Clustered index modifies the way records are stored in a database based on the indexed column. A non-clustered index creates a separate entity within the table which references the original table.
如上所述,差异可以分解为三个小因素——聚集索引基于索引列修改记录在数据库中的存储方式。非聚集索引在表中创建一个引用原始表的独立实体。
- Clustered index is used for easy and speedy retrieval of data from the database, whereas, fetching records from the non-clustered index is relatively slower.
- In SQL, a table can have a single clustered index whereas it can have multiple non-clustered indexes.
564. What is an Index? Explain its different types.
什么是索引?解释其不同类型。
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7d9b | 官方: 否 | 付费: 否
答案:
A database index is a data structure that provides a quick lookup of data in a column or columns of a table. It enhances the speed of operations accessing data from a database table at the cost of additional writes and memory to maintain the index data structure.
数据库索引是一种数据结构,提供对表中一列或多列数据的快速查找。它提高了从数据库表访问数据的操作速度,代价是需要额外的写入和内存来维护索引数据结构。
CREATE INDEX index_name / Create Index /
CREATE INDEX index_name / 创建索引 /
ON table_name (column_1, column_2);
ON table_name (column_1, column_2);
DROP INDEX index_name; / Drop Index /
DROP INDEX index_name; / 删除索引 /
There are different types of indexes that can be created for different purposes: - Unique and Non-Unique Index:
根据不同的目的,可以创建不同类型的索引:- 唯一索引和非唯一索引:
Unique indexes are indexes that help maintain data integrity by ensuring that no two rows of data in a table have identical key values. Once a unique index has been defined for a table, uniqueness is enforced whenever keys are added or changed within the index.
唯一索引是帮助维护数据完整性的索引,通过确保表中没有任何两行数据具有相同的键值来实现。一旦为表定义了唯一索引,当在索引中添加或更改键时,就会强制实施唯一性。
CREATE UNIQUE INDEX myIndex
CREATE UNIQUE INDEX myIndex
ON students (enroll_no);
ON students (enroll_no);
Non-unique indexes, on the other hand, are not used to enforce constraints on the tables with which they are associated. Instead, non-unique indexes are used solely to improve query performance by maintaining a sorted order of data values that are used frequently. - Clustered and Non-Clustered Index:
另一方面,非唯一索引不用于对与之关联的表实施约束。相反,非唯一索引仅通过维护经常使用的数据值的排序顺序来提高查询性能。- 聚簇索引和非聚簇索引:
Clustered indexes are indexes whose order of the rows in the database corresponds to the order of the rows in the index. This is why only one clustered index can exist in a given table, whereas, multiple non-clustered indexes can exist in the table.
聚簇索引是指数据库中行的顺序与索引中行的顺序相对应的索引。这就是为什么给定表中只能存在一个聚簇索引,而表中可以存在多个非聚簇索引的原因。
The only difference between clustered and non-clustered indexes is that the database manager attempts to keep the data in the database in the same order as the corresponding keys appear in the clustered index.
聚簇索引和非聚簇索引之间的唯一区别在于,数据库管理器尝试使数据库中的数据顺序与聚簇索引中相应键出现的顺序保持一致。
Clustering indexes can improve the performance of most query operations because they provide a linear-access path to data stored in the database.
聚簇索引可以提高大多数查询操作的性能,因为它们为存储在数据库中的数据提供了线性访问路径。
Write a SQL statement to create a UNIQUE INDEX "my_index" on "my_table" for fields "column_1" & "column_2".
编写一个 SQL 语句,在 "my_table" 上为字段 "column_1" 和 "column_2" 创建一个名为 "my_index" 的唯一索引。
Check
检查
565. What is a Self-Join?
什么是自连接?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5d58d557c902bc7da2 | 官方: 否 | 付费: 否
答案:
A self JOIN is a case of regular join where a table is joined to itself based on some relation between its own column(s). Self-join uses the INNER JOIN or LEFT JOIN clause and a table alias is used to assign different names to the table within the query.
自连接是常规连接的一种情况,其中表根据其自身列之间的某种关系与自身连接。自连接使用 INNER JOIN 或 LEFT JOIN 子句,并使用表别名在查询中为表分配不同的名称。
SELECT A.emp_id AS "Emp_ID",A.emp_name AS "Employee",
SELECT A.emp_id AS "Emp_ID",A.emp_name AS "Employee",
B.emp_id AS "Sup_ID",B.emp_name AS "Supervisor"
B.emp_id AS "Sup_ID",B.emp_name AS "Supervisor"
FROM employee A, employee B
FROM employee A, employee B
WHERE A.emp_sup = B.emp_id;
WHERE A.emp_sup = B.emp_id;
566. What is a Join? List its different types.
什么是连接?列出其不同类型。
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7da5 | 官方: 否 | 付费: 否
答案:
The SQL Join clause is used to combine records (rows) from two or more tables in a SQL database based on a related column between the two.
SQL 连接子句用于基于两个表之间的相关列,合并 SQL 数据库中两个或更多表中的记录(行)。
There are four different types of JOINs in SQL: - (INNER) JOIN: Retrieves records that have matching values in both tables involved in the join. This is the widely used join for queries.
SQL 中有四种不同类型的连接:- (INNER) 连接:检索连接中两个表中都具有匹配值的记录。这是查询中广泛使用的连接。
SELECT *
SELECT *
FROM Table_A
FROM Table_A
JOIN Table_B;
JOIN Table_B;
SELECT *
SELECT *
FROM Table_A
FROM Table_A
INNER JOIN Table_B; - LEFT (OUTER) JOIN: Retrieves all the records/rows from the left and the matched records/rows from the right table.
INNER JOIN Table_B; - LEFT (OUTER) 连接:检索左表中的所有记录/行以及右表中的匹配记录/行。
SELECT *
SELECT *
FROM Table_A A
FROM Table_A A
LEFT JOIN Table_B B
LEFT JOIN Table_B B
ON A.col = B.col; - RIGHT (OUTER) JOIN: Retrieves all the records/rows from the right and the matched records/rows from the left table.
ON A.col = B.col; - RIGHT (OUTER) 连接:检索右表中的所有记录/行以及左表中的匹配记录/行。
SELECT *
SELECT *
FROM Table_A A
FROM Table_A A
RIGHT JOIN Table_B B
RIGHT JOIN Table_B B
ON A.col = B.col; - FULL (OUTER) JOIN: Retrieves all the records where there is a match in either the left or right table.
ON A.col = B.col; - FULL (OUTER) JOIN:检索左表或右表中所有匹配的记录。
SELECT *
SELECT *
FROM Table_A A
FROM Table_A A
FULL JOIN Table_B B
FULL JOIN Table_B B
ON A.col = B.col;
ON A.col = B.col;
567. What are Constraints in SQL?
SQL 中的约束是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7db6 | 官方: 否 | 付费: 否
答案:
Constraints are used to specify the rules concerning data in the table. It can be applied for single or multiple fields in an SQL table during the creation of the table or after creating using the ALTER TABLE command. The constraints are: - NOT NULL - Restricts NULL value from being inserted into a column.
约束用于指定有关表中数据的规则。它可以在创建表时或使用 ALTER TABLE 命令创建后应用于 SQL 表中的单个或多个字段。约束包括:- NOT NULL - 限制 NULL 值被插入到列中。
- CHECK - Verifies that all values in a field satisfy a condition.
- DEFAULT - Automatically assigns a default value if no value has been specified for the field.
- UNIQUE - Ensures unique values to be inserted into the field.
- INDEX - Indexes a field providing faster retrieval of records.
- PRIMARY KEY - Uniquely identifies each record in a table.
- FOREIGN KEY - Ensures referential integrity for a record in another table.
568. What are Tables and Fields?
什么是表和字段?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7db9 | 官方: 否 | 付费: 否
答案:
A table is an organized collection of data stored in the form of rows and columns. Columns can be categorized as vertical and rows as horizontal. The columns in a table are called fields while the rows can be referred to as records.
表是以行和列形式存储的有组织的数据集合。列可以归类为垂直方向,行则为水平方向。表中的列被称为字段,而行可称为记录。
569. What is the difference between SQL and MySQL?
SQL 和 MySQL 有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7dbc | 官方: 否 | 付费: 否
答案:
SQL is a standard language for retrieving and manipulating structured databases. On the contrary, MySQL is a relational database management system, like SQL Server, Oracle or IBM DB2, that is used to manage SQL databases.
SQL 是检索和操作结构化数据库的标准语言。相反,MySQL 是一个关系数据库管理系统,如 SQL Server、Oracle 或 IBM DB2,用于管理 SQL 数据库。
570. What is RDBMS? How is it different from DBMS?
什么是 RDBMS?它与 DBMS 有何不同?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7dc3 | 官方: 否 | 付费: 否
答案:
RDBMS stands for Relational Database Management System. The key difference here , compared to DBMS, is that RDBMS stores data in the form of a collection of tables, and relations can be defined between the common fields of these tables. Most modern database management systems like MySQL, Microsoft SQL Server, Oracle, IBM DB2, and Amazon Redshift are based on RDBMS.
RDBMS 代表关系数据库管理系统。与 DBMS 相比,关键区别在于 RDBMS 以表集合的形式存储数据,并且可以在这些表的公共字段之间定义关系。大多数现代数据库管理系统,如 MySQL、Microsoft SQL Server、Oracle、IBM DB2 和 Amazon Redshift,都基于 RDBMS。
571. What is DBMS?
什么是DBMS?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7dc9 | 官方: 否 | 付费: 否
答案:
DBMS stands for Database Management System. DBMS is a system software responsible for the creation, retrieval, updation, and management of the database. It ensures that our data is consistent, organized, and is easily accessible by serving as an interface between the database and its end-users or application software.
DBMS 代表数据库管理系统。DBMS 是负责数据库创建、检索、更新和管理的系统软件。它通过作为数据库与其最终用户或应用软件之间的接口,确保我们的数据一致、有序且易于访问。
572. What is Collation? What are the different types of Collation Sensitivity?
什么是排序规则?排序规则敏感性有哪些不同类型?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7dcc | 官方: 否 | 付费: 否
答案:
Collation refers to a set of rules that determine how data is sorted and compared. Rules defining the correct character sequence are used to sort the character data. It incorporates options for specifying case sensitivity, accent marks, kana character types, and character width. Below are the different types of collation sensitivity: - Case sensitivity: A and a are treated differently.
排序规则是指决定数据如何排序和比较的一组规则。定义正确字符序列的规则用于对字符数据进行排序。它包括指定大小写敏感性、重音符号、假名字符类型和字符宽度的选项。以下是不同类型的排序规则敏感性:- 大小写敏感性:A和a被视为不同。
- Accent sensitivity: a and á are treated differently.
- Kana sensitivity: Japanese kana characters Hiragana and Katakana are treated differently.
- Width sensitivity: Same character represented in single-byte (half-width) and double-byte (full-width) are treated differently.
573. What is Pattern Matching in SQL?
什么是SQL中的模式匹配?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7dcf | 官方: 否 | 付费: 否
答案:
SQL pattern matching provides for pattern search in data if you have no clue as to what that word should be. This kind of SQL query uses wildcards to match a string pattern, rather than writing the exact word. The LIKE operator is used in conjunction with SQL Wildcards to fetch the required information. - Using the % wildcard to perform a simple search
SQL模式匹配允许在您对所需单词一无所知的情况下对数据进行模式搜索。这种SQL查询使用通配符来匹配字符串模式,而不是写出确切的单词。LIKE运算符与SQL通配符结合使用以获取所需信息。- 使用%通配符进行简单搜索
The % wildcard matches zero or more characters of any type and can be used to define wildcards both before and after the pattern. Search a student in your database with first name beginning with the letter K:
%通配符匹配任意类型的零个或多个字符,可用于在模式前后定义通配符。在您的数据库中搜索名字以字母K开头的学生:
SELECT *
SELECT *
FROM students
FROM students
WHERE first_name LIKE 'K%'
WHERE first_name LIKE 'K%'
- Omitting the patterns using the NOT keyword
Use the NOT keyword to select records that don't match the pattern. This query returns all students whose first name does not begin with K.
使用NOT关键字选择不匹配模式的记录。此查询返回所有名字不以K开头的学生。
SELECT *
SELECT *
FROM students
FROM students
WHERE first_name NOT LIKE 'K%'
WHERE first_name NOT LIKE 'K%'
- Matching a pattern anywhere using the % wildcard twice
Search for a student in the database where he/she has a K in his/her first name.
在数据库中搜索名字中包含字母K的学生。
SELECT *
SELECT *
FROM students
FROM students
WHERE first_name LIKE '%Q%'
WHERE first_name LIKE '%Q%'
- Using the _ wildcard to match pattern at a specific position
The _ wildcard matches exactly one character of any type. It can be used in conjunction with % wildcard. This query fetches all students with letter K at the third position in their first name.
_通配符精确匹配任意类型的一个字符。它可以与%通配符结合使用。此查询获取所有名字中第三个位置为字母K的学生。
SELECT *
SELECT *
FROM students
FROM students
WHERE first_name LIKE '__K%'
WHERE first_name LIKE '__K%'
- Matching patterns for a specific length
The _ wildcard plays an important role as a limitation when it matches exactly one character. It limits the length and position of the matched results. For example -
_ 通配符在匹配恰好一个字符时起到重要的限制作用。它限制了匹配结果的长度和位置。例如 -
SELECT / Matches first names with three or more letters */
SELECT / 匹配具有三个或更多字母的名字 */
FROM students
FROM students
WHERE first_name LIKE '___%'
WHERE first_name LIKE '___%'
SELECT / Matches first names with exactly four characters */
SELECT / 匹配恰好具有四个字符的名字 */
FROM students
FROM students
WHERE first_name LIKE '____'
WHERE first_name LIKE '____'
574. How to create empty tables with the same structure as another table?
如何创建与另一个表结构相同的空表?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7dd2 | 官方: 否 | 付费: 否
答案:
Creating empty tables with the same structure can be done smartly by fetching the records of one table into a new table using the INTO operator while fixing a WHERE clause to be false for all records. Hence, SQL prepares the new table with a duplicate structure to accept the fetched records but since no records get fetched due to the WHERE clause in action, nothing is inserted into the new table.
通过使用 INTO 操作符将一个表的记录提取到新表中,同时将 WHERE 子句设置为对所有记录都为假,可以巧妙地创建具有相同结构的空表。因此,SQL 会准备一个具有重复结构的新表来接受提取的记录,但由于 WHERE 子句生效导致没有记录被提取,因此新表中不会插入任何内容。
SELECT * INTO Students_copy
SELECT * INTO Students_copy
FROM Students WHERE 1 = 2;
FROM Students WHERE 1 = 2;
575. What is a Recursive Stored Procedure?
什么是递归存储过程?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7dd5 | 官方: 否 | 付费: 否
答案:
A stored procedure that calls itself until a boundary condition is reached, is called a recursive stored procedure. This recursive function helps the programmers to deploy the same set of code several times as and when required. Some SQL programming languages limit the recursion depth to prevent an infinite loop of procedure calls from causing a stack overflow, which slows down the system and may lead to system crashes.
一个存储过程调用自身直到达到边界条件,被称为递归存储过程。这种递归函数帮助程序员在需要时多次部署同一套代码。一些 SQL 编程语言限制递归深度,以防止无限循环的过程调用导致栈溢出,这会拖慢系统速度并可能导致系统崩溃。
DELIMITER $ /* Set a new delimiter => $ */
DELIMITER $ /* 设置新的定界符 => $ */
CREATE PROCEDURE calctotal( / Create the procedure /
CREATE PROCEDURE calctotal( / 创建存储过程 /
IN number INT, / Set Input and Ouput variables /
IN number INT, / 设置输入和输出变量 /
OUT total INT
OUT total INT
) BEGIN
) BEGIN
DECLARE score INT DEFAULT NULL; / Set the default value => "score" /
DECLARE score INT DEFAULT NULL; / 设置默认值 => "score" /
SELECT awards FROM achievements / Update "score" via SELECT query /
SELECT awards FROM achievements / 通过 SELECT 查询更新 "score" /
WHERE id = number INTO score;
WHERE id = number INTO score;
IF score IS NULL THEN SET total = 0; / Termination condition /
IF score IS NULL THEN SET total = 0; / 终止条件 /
ELSE
ELSE
CALL calctotal(number+1); / Recursive call /
CALL calctotal(number+1); / 递归调用 /
SET total = total + score; / Action after recursion /
SET total = total + score; / 递归后的操作 /
END IF;
结束如果;
END $ / End of procedure /
END $ / 存储过程结束 /
DELIMITER ; / Reset the delimiter /
DELIMITER ; / 重置定界符 /
576. What is Database?
什么是数据库?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7ddc | 官方: 否 | 付费: 否
答案:
A database is an organized collection of data, stored and retrieved digitally from a remote or local computer system. Databases can be vast and complex, and such databases are developed using fixed design and modeling approaches.
数据库是一种有组织的数据集合,通过远程或本地计算机系统以数字方式进行存储和检索。数据库可能庞大而复杂,此类数据库是使用固定的设计和建模方法开发的。
577. What is User-defined function? What are its various types?
什么是用户自定义函数?它有哪几种类型?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: coding
- 分类: fullstack
- id: 69b37c5e58d557c902bc7de7 | 官方: 否 | 付费: 否
答案:
The user-defined functions in SQL are like functions in any other programming language that accept parameters, perform complex calculations, and return a value. They are written to use the logic repetitively whenever required. There are two types of SQL user-defined functions: - Scalar Function: As explained earlier, user-defined scalar functions return a single scalar value.
SQL 中的用户自定义函数类似于任何其他编程语言中的函数,它们接受参数、执行复杂计算并返回一个值。编写这些函数是为了在需要时重复使用逻辑。SQL 用户自定义函数有两种类型:- 标量函数:如前所述,用户自定义标量函数返回单个标量值。
Table-Valued Functions: User-defined table-valued functions return a table as output.
Inline: returns a table data type based on a single SELECT statement.内联函数:基于单个 SELECT 语句返回表数据类型。
Multi-statement: returns a tabular result-set but, unlike inline, multiple SELECT statements can be used inside the function body.
多语句函数:返回表格形式的结果集,但与内联函数不同,函数体内可以使用多个 SELECT 语句。
578. What are Aggregate and Scalar functions?
什么是聚合函数和标量函数?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: coding
- 分类: fullstack
- id: 69b37c5e58d557c902bc7dea | 官方: 否 | 付费: 否
答案:
An aggregate function performs operations on a collection of values to return a single scalar value. Aggregate functions are often used with the GROUP BY and HAVING clauses of the SELECT statement. Following are the widely used SQL aggregate functions: - AVG() - Calculates the mean of a collection of values.
聚合函数对一组值执行操作以返回单个标量值。聚合函数通常与 SELECT 语句的 GROUP BY 和 HAVING 子句一起使用。以下是广泛使用的 SQL 聚合函数:- AVG() - 计算一组值的平均值。
- COUNT() - Counts the total number of records in a specific table or view.
- MIN() - Calculates the minimum of a collection of values.
- MAX() - Calculates the maximum of a collection of values.
- SUM() - Calculates the sum of a collection of values.
- FIRST() - Fetches the first element in a collection of values.
LAST() - Fetches the last element in a collection of values.
Note: All aggregate functions described above ignore NULL values except for the COUNT function.注意:上述所有聚合函数都忽略 NULL 值,但 COUNT 函数除外。
A scalar function returns a single value based on the input value. Following are the widely used SQL scalar functions: - LEN() - Calculates the total length of the given field (column).
标量函数根据输入值返回单个值。以下是广泛使用的 SQL 标量函数:- LEN() - 计算给定字段(列)的总长度。
- UCASE() - Converts a collection of string values to uppercase characters.
- LCASE() - Converts a collection of string values to lowercase characters.
- MID() - Extracts substrings from a collection of string values in a table.
- CONCAT() - Concatenates two or more strings.
- RAND() - Generates a random collection of numbers of a given length.
- ROUND() - Calculates the round-off integer value for a numeric field (or decimal point values).
- NOW() - Returns the current date & time.
- FORMAT() - Sets the format to display a collection of values.
579. What is the difference between DELETE and TRUNCATE statements?
DELETE 和 TRUNCATE 语句有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7ded | 官方: 否 | 付费: 否
答案:
The TRUNCATE command is used to delete all the rows from the table and free the space containing the table. The DELETE command deletes only the rows from the table based on the condition given in the where clause or deletes all the rows from the table if no condition is specified. But it does not free the space containing the table.
TRUNCATE 命令用于删除表中的所有行并释放包含该表的空间。DELETE 命令根据 where 子句中给定的条件仅删除表中的行,或者如果未指定条件则删除表中的所有行。但它不会释放包含该表的空间。
580. What is the difference between DROP and TRUNCATE statements?
DROP 和 TRUNCATE 语句有什么区别?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7df0 | 官方: 否 | 付费: 否
答案:
If a table is dropped, all things associated with the tables are dropped as well. This includes - the relationships defined on the table with other tables, the integrity checks and constraints, access privileges and other grants that the table has. To create and use the table again in its original form, all these relations, checks, constraints, privileges and relationships need to be redefined. However, if a table is truncated, none of the above problems exist and the table retains its original structure.
如果删除了一个表,与该表关联的所有内容也会被删除。这包括:表与其他表上定义的关系、完整性检查和约束、访问权限以及该表拥有的其他授权。要以原始形式重新创建和使用该表,需要重新定义所有这些关系、检查、约束、权限和关联。但是,如果表被 TRUNCATE,则上述问题都不存在,表保留其原始结构。
581. What are the TRUNCATE, DELETE and DROP statements?
什么是 TRUNCATE、DELETE 和 DROP 语句?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7df3 | 官方: 否 | 付费: 否
答案:
DELETE statement is used to delete rows from a table.
DELETE 语句用于从表中删除行。
DELETE FROM Candidates
DELETE FROM Candidates
WHERE CandidateId > 1000;
WHERE CandidateId > 1000;
TRUNCATE command is used to delete all the rows from the table and free the space containing the table.
TRUNCATE 命令用于删除表中的所有行,并释放包含该表的空间。
TRUNCATE TABLE Candidates;
TRUNCATE TABLE Candidates;
DROP command is used to remove an object from the database. If you drop a table, all the rows in the table are deleted and the table structure is removed from the database.
DROP 命令用于从数据库中移除一个对象。如果您删除一个表,表中所有行都会被删除,并且表结构也会从数据库中移除。
DROP TABLE Candidates;
DROP TABLE Candidates;
Write a SQL statement to wipe a table 'Temporary' from memory.
编写一条 SQL 语句,从内存中清除表 'Temporary'。
Check
检查
Write a SQL query to remove first 1000 records from table 'Temporary' based on 'id'.
编写一条 SQL 查询,根据 'id' 从表 'Temporary' 中删除前 1000 条记录。
Check
检查
Write a SQL statement to delete the table 'Temporary' while keeping its relations intact.
编写一条 SQL 语句,删除表 'Temporary' 但保持其关系不变。
Check
检查
582. What are the various forms of Normalization?
什么是规范化的各种形式?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7df6 | 官方: 否 | 付费: 否
答案:
Normal Forms are used to eliminate or reduce redundancy in database tables. The different forms are as follows: - First Normal Form:A relation is in first normal form if every attribute in that relation is a single-valued attribute. If a relation contains a composite or multi-valued attribute, it violates the first normal form. Let's consider the following students table. Each student in the table, has a name, his/her address, and the books they issued from the public library -
范式用于消除或减少数据库表中的冗余。不同的形式如下:- 第一范式:如果关系中的每个属性都是单值属性,则关系处于第一范式。如果关系包含复合属性或多值属性,则违反第一范式。让我们考虑以下学生表。表中的每个学生都有名字、地址以及从公共图书馆借阅的书籍 -
Students Table
学生表
| Student 学生 | Address 地址 | Books Issued 借阅书籍 | Salutation 称呼 |
|---|---|---|---|
| Sara 萨拉 | Amanora Park Town 94 阿莫诺拉公园镇 94 | Until the Day I Die (Emily Carpenter), Inception (Christopher Nolan) 直到我死的那一天(艾米丽·卡彭特),盗梦空间(克里斯托弗·诺兰) | Ms. 女士 |
| Ansh 安什 | 62nd Sector A-10 62区 A-10 | The Alchemist (Paulo Coelho), Inferno (Dan Brown) 牧羊少年奇幻之旅(保罗·柯艾略),地狱(丹·布朗) | Mr. 先生 |
| Sara 萨拉 | 24th Street Park Avenue 24街公园大道 | Beautiful Bad (Annie Ward), Woman 99 (Greer Macallister) 美丽的坏女人(安妮·沃德),女人 99(格里尔·麦卡利斯特) | Mrs. 夫人 |
| Ansh 安什 | Windsor Street 777 温莎街 777 | Dracula (Bram Stoker) 德古拉(布拉姆·斯托克) | Mr. 先生 |
As we can observe, the Books Issued field has more than one value per record, and to convert it into 1NF, this has to be resolved into separate individual records for each book issued. Check the following table in 1NF form -
我们可以观察到,借阅书籍字段每个记录有多个值,要转换为第一范式,这必须分解为每本借阅书籍的独立记录。请查看以下第一范式形式的表 -
Students Table (1st Normal Form)
学生表(第一范式)
| Student 学生 | Address 地址 | Books Issued 借阅图书 | Salutation 称呼 |
|---|---|---|---|
| Sara | Amanora Park Town 94 | Until the Day I Die (Emily Carpenter) | Ms. 女士 |
| Sara | Amanora Park Town 94 | Inception (Christopher Nolan) | Ms. 女士 |
| Ansh | 62nd Sector A-10 | The Alchemist (Paulo Coelho) | Mr. 先生 |
| Ansh | 62nd Sector A-10 | Inferno (Dan Brown) | Mr. 先生 |
| Sara | 24th Street Park Avenue | Beautiful Bad (Annie Ward) | Mrs. 夫人 |
| Sara | 24th Street Park Avenue | Woman 99 (Greer Macallister) | Mrs. 夫人 |
| Ansh | Windsor Street 777 | Dracula (Bram Stoker) | Mr. 先生 |
| - Second Normal Form: - 第二范式: |
A relation is in second normal form if it satisfies the conditions for the first normal form and does not contain any partial dependency. A relation in 2NF has no partial dependency , i.e., it has no non-prime attribute that depends on any proper subset of any candidate key of the table. Often, specifying a single column Primary Key is the solution to the problem. Examples -
如果一个关系满足第一范式的条件且不包含任何部分依赖,则称其处于第二范式。处于2NF的关系没有部分依赖,即它没有任何非主属性依赖于该表任何候选键的任一真子集。通常,指定单一列作为主键即可解决此问题。示例 -
Example 1 - Consider the above example. As we can observe, the Students Table in the 1NF form has a candidate key in the form of [Student, Address] that can uniquely identify all records in the table. The field Books Issued (non-prime attribute) depends partially on the Student field. Hence, the table is not in 2NF. To convert it into the 2nd Normal Form, we will partition the tables into two while specifying a new Primary Key attribute to identify the individual records in the Students table. The Foreign Key constraint will be set on the other table to ensure referential integrity.
示例1 - 考虑上述示例。如我们所见,1NF形式的学生表有一个候选键 [学生, 地址],可以唯一标识表中的所有记录。字段“借阅图书”(非主属性)部分依赖于“学生”字段。因此,该表不处于2NF。要将其转换为第二范式,我们将把表分成两个,同时指定一个新的主键属性来标识学生表中的单个记录。外键约束将设置在另一个表上以确保引用完整性。
Students Table (2nd Normal Form)
学生表(第二范式)
| Student_ID 学生_ID | Student 学生 | Address 地址 | Salutation 称呼 |
|---|---|---|---|
| 1 | Sara | Amanora Park Town 94 | Ms. 女士 |
| 2 | Ansh | 62nd Sector A-10 | Mr. 先生 |
| 3 | Sara | 24th Street Park Avenue | Mrs. 夫人 |
| 4 | Ansh | Windsor Street 777 | Mr. 先生 |
Books Table (2nd Normal Form)
图书表(第二范式)
| Student_ID 学生_ID | Book Issued 借阅图书 |
|---|---|
| 1 | Until the Day I Die (Emily Carpenter) |
| 1 | Inception (Christopher Nolan) |
| 2 | The Alchemist (Paulo Coelho) |
| 2 | Inferno (Dan Brown) |
| 3 | Beautiful Bad (Annie Ward) |
| 3 | Woman 99 (Greer Macallister) |
| 4 | Dracula (Bram Stoker) |
Example 2 - Consider the following dependencies in relation to R(W,X,Y,Z)
示例2 - 考虑关系R(W,X,Y,Z)中的以下依赖
WX -> Y [W and X together determine Y]
WX -> Y [W和X共同确定Y]
XY -> Z [X and Y together determine Z]
XY -> Z [X和Y共同确定Z]
Here, WX is the only candidate key and there is no partial dependency, i.e., any proper subset of WX doesn’t determine any non-prime attribute in the relation. - Third Normal Form
这里,WX是唯一的候选键,且没有部分依赖,即WX的任何真子集都不能确定关系中的任何非主属性。 - 第三范式
A relation is said to be in the third normal form, if it satisfies the conditions for the second normal form and there is no transitive dependency between the non-prime attributes, i.e., all non-prime attributes are determined only by the candidate keys of the relation and not by any other non-prime attribute.
如果一个关系满足第二范式的条件,并且非主属性之间不存在传递依赖,即所有非主属性仅由关系的候选键确定,而非由任何其他非主属性确定,则称该关系处于第三范式。
Example 1 - Consider the Students Table in the above example. As we can observe, the Students Table in the 2NF form has a single candidate key Student_ID (primary key) that can uniquely identify all records in the table. The field Salutation (non-prime attribute), however, depends on the Student Field rather than the candidate key. Hence, the table is not in 3NF. To convert it into the 3rd Normal Form, we will once again partition the tables into two while specifying a new Foreign Key constraint to identify the salutations for individual records in the Students table. The Primary Key constraint for the same will be set on the Salutations table to identify each record uniquely.
示例1 - 考虑上述示例中的学生表。如我们所见,2NF形式的学生表有一个单一候选键 学生_ID(主键),可以唯一标识表中的所有记录。然而,字段“称呼”(非主属性)依赖于“学生”字段而非候选键。因此,该表不处于3NF。要将其转换为第三范式,我们将再次把表分成两个,同时指定一个新的外键约束来标识学生表中单个记录的称呼。主键约束将设置在“称呼表”上,以唯一标识每条记录。
Students Table (3rd Normal Form)
学生表(第三范式)
| Student_ID 学生_ID | Student 学生 | Address 地址 | Salutation_ID 称呼_ID |
|---|---|---|---|
| 1 | Sara | Amanora Park Town 94 | 1 |
| 2 | Ansh | 62nd Sector A-10 | 2 |
| 3 | Sara | 24th Street Park Avenue | 3 |
| 4 | Ansh | Windsor Street 777 | 1 |
Books Table (3rd Normal Form)
图书表(第三范式)
| Student_ID 学生_ID | Book Issued 借阅图书 |
|---|---|
| 1 | Until the Day I Die (Emily Carpenter) |
| 1 | Inception (Christopher Nolan) |
| 2 | The Alchemist (Paulo Coelho) |
| 2 | Inferno (Dan Brown) |
| 3 | Beautiful Bad (Annie Ward) |
| 3 | Woman 99 (Greer Macallister) |
| 4 | Dracula (Bram Stoker) |
Salutations Table (3rd Normal Form)
称谓表(第三范式)
| Salutation_ID 称谓ID | Salutation 称谓 |
|---|---|
| 1 | Ms. 女士 |
| 2 | Mr. 先生 |
| 3 | Mrs. 夫人 |
Example 2 - Consider the following dependencies in relation to R(P,Q,R,S,T)
示例2 - 考虑关系R(P,Q,R,S,T)中的以下依赖
P -> QR [P together determine C]
P -> QR [P共同决定C]
RS -> T [B and C together determine D]
RS -> T [B和C共同决定D]
Q -> S
Q -> S
T -> P
T -> P
For the above relation to exist in 3NF, all possible candidate keys in the above relation should be {P, RS, QR, T}. - Boyce-Codd Normal Form
为了使上述关系存在于3NF中,上述关系中所有可能的候选键应为{P, RS, QR, T}。 - 巴克斯-科德范式
A relation is in Boyce-Codd Normal Form if satisfies the conditions for third normal form and for every functional dependency, Left-Hand-Side is super key. In other words, a relation in BCNF has non-trivial functional dependencies in form X –> Y, such that X is always a super key. For example - In the above example, Student_ID serves as the sole unique identifier for the Students Table and Salutation_ID for the Salutations Table, thus these tables exist in BCNF. The same cannot be said for the Books Table and there can be several books with common Book Names and the same Student_ID.
如果一个关系满足第三范式的条件,并且对于每个函数依赖,左侧是超键,则该关系处于巴克斯-科德范式。换句话说,处于BCNF的关系具有形式为X –> Y的非平凡函数依赖,其中X始终是超键。例如 - 在上述示例中,Student_ID作为学生表的唯一唯一标识符,Salutation_ID作为称谓表的唯一标识符,因此这些表处于BCNF。但图书表则不然,可能存在多本具有相同书名和相同学生ID的图书。
583. What is a View?
什么是视图?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e08 | 官方: 否 | 付费: 否
答案:
A view in SQL is a virtual table based on the result-set of an SQL statement. A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
SQL中的视图是基于SQL语句结果集的虚拟表。视图包含行和列,就像真实的表一样。视图中的字段是数据库中一个或多个真实表中的字段。
584. What is the main disadvantage of deleting data from an existing table using the DROP TABLE command?
使用DROP TABLE命令从现有表中删除数据的主要缺点是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e0b | 官方: 否 | 付费: 否
答案:
DROP TABLE command deletes complete data from the table along with removing the complete table structure too. In case our requirement entails just remove the data, then we would need to recreate the table to store data in it. In such cases, it is advised to use the TRUNCATE command.
DROP TABLE命令会删除表中的所有数据以及整个表结构。如果我们的需求仅涉及删除数据,那么我们需要重新创建表来存储数据。在这种情况下,建议使用TRUNCATE命令。
585. Differentiate between commit and checkpoint.
区分提交和检查点。
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e0e | 官方: 否 | 付费: 否
答案:
The commit action ensures that the data consistency of the transaction is maintained and it ends the current transaction in the section. Commit adds a new record in the log that describes the COMMIT to the memory. Whereas, a checkpoint is used for writing all changes that were committed to disk up to SCN which would be kept in datafile headers and control files.
提交操作确保事务的数据一致性得以维持,并在该部分结束当前事务。提交会在日志中添加一条新记录,向内存描述COMMIT操作。而检查点用于将所有已提交的更改写入磁盘,直到SCN,该SCN会保存在数据文件头和控制文件中。
Conclusion:
结论:
SQL is a language for the database. It has a vast scope and robust capability of creating and manipulating a variety of database objects using commands like CREATE, ALTER, DROP, etc, and also in loading the database objects using commands like INSERT. It also provides options for Data Manipulation using commands like DELETE, TRUNCATE and also does effective retrieval of data using cursor commands like FETCH, SELECT, etc. There are many such commands which provide a large amount of control to the programmer to interact with the database in an efficient way without wasting many resources. The popularity of SQL has grown so much that almost every programmer relies on this to implement their application's storage functionalities thereby making it an exciting language to learn. Learning this provides the developer a benefit of understanding the data structures used for storing the organization's data and giving an additional level of control and in-depth understanding of the application.
SQL是用于数据库的语言。它具有广泛的范围和强大的能力,可使用CREATE、ALTER、DROP等命令创建和操作各种数据库对象,也可使用INSERT等命令加载数据库对象。它还提供使用DELETE、TRUNCATE等命令进行数据操作选项,并通过FETCH、SELECT等游标命令高效检索数据。还有许多此类命令,为程序员提供了大量控制权,使其能够高效地与数据库交互,而不会浪费太多资源。SQL的流行度已增长到几乎每个程序员都依赖它来实现应用程序的存储功能,从而使其成为一门令人兴奋的学习语言。学习SQL能让开发者理解用于存储组织数据的结构,并提供额外层面的控制和对应用程序的深入理解。
PostgreSQL being an open-source database system having extremely robust and sophisticated ACID, Indexing, and Transaction supports has found widespread popularity among the developer community.
PostgreSQL作为开源数据库系统,具有极其强大和复杂的ACID、索引和事务支持,在开发者社区中广受欢迎。
References and Resources: - PostgreSQL Download
参考资料和资源:- PostgreSQL下载
- PostgreSQL Tutorial
- SQL Guide
- SQL Server Interview Questions
- SQL Query Interview Questions and Answers
- SQL Interview Questions for Data Science
- MySQL Interview Questions
- DBMS Interview Questions
- PL SQL Interview Questions
- MongoDB Interview Questions
- Database Testing Interview Questions
- SQL Vs MySQL
- PostgreSQL vs MySQL
- Difference Between SQL and PLSQL
- Difference between RDBMS and DBMS
- SQL Vs NoSQL
- SQL IDE
- SQL Projects
- MySQL Commands
- SQL Books
- OLTP vs OLAP
586. What are parallel queries in PostgreSQL?
PostgreSQL中的并行查询是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e11 | 官方: 否 | 付费: 否
答案:
Parallel Queries support is a feature provided in PostgreSQL for devising query plans capable of exploiting multiple CPU processors to execute the queries faster.
并行查询支持是PostgreSQL中提供的一项功能,用于设计能够利用多个CPU处理器更快执行查询的查询计划。
587. Does PostgreSQL support full text search?
PostgreSQL是否支持全文搜索?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e14 | 官方: 否 | 付费: 否
答案:
Full-Text Search is the method of searching single or collection of documents stored on a computer in a full-text based database. This is mostly supported in advanced database systems like SOLR or ElasticSearch. However, the feature is present but is pretty basic in PostgreSQL.
全文搜索是在基于全文的数据库中搜索存储在计算机上的单个或一组文档的方法。这主要在SOLR或ElasticSearch等高级数据库系统中得到支持。然而,该功能在PostgreSQL中存在,但相当基础。
588. How will you take backup of the database in PostgreSQL?
如何在PostgreSQL中备份数据库?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e17 | 官方: 否 | 付费: 否
答案:
We can achieve this by using the pg_dump tool for dumping all object contents in the database into a single file. The steps are as follows:
我们可以通过使用pg_dump工具来实现,将数据库中的所有对象内容转储到单个文件中。步骤如下:
Step 1 : Navigate to the bin folder of the PostgreSQL installation path.
步骤1:导航到PostgreSQL安装路径的bin文件夹。
C:\>cd C:\Program Files\PostgreSQL\10.0\bin
C:\>cd C:\Program Files\PostgreSQL\10.0\bin
Step 2: Execute pg_dump program to take the dump of data to a .tar folder as shown below:
步骤2:执行pg_dump程序,将数据转储到.tar文件夹中,如下所示:
pg_dump -U postgres -W -F t sample_data > C:\Users\admin\pgbackup\sample_data.tar
pg_dump -U postgres -W -F t sample_data > C:\Users\admin\pgbackup\sample_data.tar
The database dump will be stored in the sample_data.tar file on the location specified.
数据库转储将存储到指定位置的sample_data.tar文件中。
589. How do you perform case-insensitive searches using regular expressions in PostgreSQL?
如何在PostgreSQL中使用正则表达式进行不区分大小写的搜索?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e1a | 官方: 否 | 付费: 否
答案:
To perform case insensitive matches using a regular expression, we can use POSIX (~*) expression from pattern matching operators. For example:
要使用正则表达式执行不区分大小写的匹配,我们可以使用模式匹配运算符中的 POSIX(~*)表达式。例如:
'interviewbit' ~ '.INTervIewBit.*'
'interviewbit' ~ '.INTervIewBit.*'
590. What can you tell about WAL (Write Ahead Logging)?
关于 WAL(预写日志)你能告诉我们什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e1d | 官方: 否 | 付费: 否
答案:
Write Ahead Logging is a feature that increases the database reliability by logging changes before any changes are done to the database. This ensures that we have enough information when a database crash occurs by helping to pinpoint to what point the work has been complete and gives a starting point from the point where it was discontinued.
预写日志是一种通过在对数据库进行任何更改之前记录更改来增加数据库可靠性的功能。这确保了当数据库崩溃发生时,我们有足够的信息,通过帮助精确定位工作已完成到哪一点,并从中断点提供起始点。
For more information, you can refer here .
有关更多信息,你可以参考这里。
591. How do you check the rows affected as part of previous transactions?
如何检查作为先前事务一部分而影响的行数?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e20 | 官方: 否 | 付费: 否
答案:
SQL standards state that the following three phenomena should be prevented whilst concurrent transactions. SQL standards define 4 levels of transaction isolations to deal with these phenomena. - Dirty reads: If a transaction reads data that is written due to concurrent uncommitted transaction, these reads are called dirty reads.
SQL 标准规定,在并发事务期间应防止以下三种现象。SQL 标准定义了 4 级事务隔离级别来处理这些现象。- 脏读:如果事务读取了因并发未提交事务而写入的数据,这些读取称为脏读。
- Phantom reads: This occurs when two same queries when executed separately return different rows. For example, if transaction A retrieves some set of rows matching search criteria. Assume another transaction B retrieves new rows in addition to the rows obtained earlier for the same search criteria. The results are different.
Non-repeatable reads: This occurs when a transaction tries to read the same row multiple times and gets different values each time due to concurrency. This happens when another transaction updates that data and our current transaction fetches that updated data, resulting in different values.
To tackle these, there are 4 standard isolation levels defined by SQL standards. They are as follows: - Read Uncommitted – The lowest level of the isolations. Here, the transactions are not isolated and can read data that are not committed by other transactions resulting in dirty reads.为了解决这些问题,SQL 标准定义了 4 种标准隔离级别。它们如下:- 读未提交 – 隔离级别中最低的级别。在这里,事务未被隔离,可以读取其他事务未提交的数据,导致脏读。
- Read Committed – This level ensures that the data read is committed at any instant of read time. Hence, dirty reads are avoided here. This level makes use of read/write lock on the current rows which prevents read/write/update/delete of that row when the current transaction is being operated on.
- Repeatable Read – The most restrictive level of isolation. This holds read and write locks for all rows it operates on. Due to this, non-repeatable reads are avoided as other transactions cannot read, write, update or delete the rows.
Serializable – The highest of all isolation levels. This guarantees that the execution is serializable where execution of any concurrent operations are guaranteed to be appeared as executing serially.
The following table clearly explains which type of unwanted reads the levels avoid:下表清楚说明了各个级别避免了哪种不需要的读取:
| Isolation levels 隔离级别 | Dirty Reads 脏读 | Phantom Reads 幻读 | Non-repeatable reads 不可重复读 |
|---|---|---|---|
| Read Uncommitted 读未提交 | Might occur 可能发生 | Might occur 可能发生 | Might occur 可能发生 |
| Read Committed 读已提交 | Won’t occur 不会发生 | Might occur 可能发生 | Might occur 可能发生 |
| Repeatable Read 可重复读 | Won’t occur 不会发生 | Might occur 可能发生 | Won’t occur 不会发生 |
| Serializable 可串行化 | Won’t occur 不会发生 | Won’t occur 不会发生 | Won’t occur 不会发生 |
592. What do you understand by command enable-debug?
你对命令 enable-debug 有什么理解?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e23 | 官方: 否 | 付费: 否
答案:
The command enable-debug is used for enabling the compilation of all libraries and applications. When this is enabled, the system processes get hindered and generally also increases the size of the binary file. Hence, it is not recommended to switch this on in the production environment. This is most commonly used by developers to debug the bugs in their scripts and help them spot the issues. For more information regarding how to debug, you can refer here .
命令 enable-debug 用于启用所有库和应用程序的编译。当此选项启用时,系统进程会受到阻碍,并且通常还会增加二进制文件的大小。因此,不建议在生产环境中开启此选项。这最常用于开发人员调试脚本中的错误并帮助他们发现问题。有关如何调试的更多信息,你可以参考这里。
593. What do you understand by multi-version concurrency control?
你对多版本并发控制有什么理解?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e26 | 官方: 否 | 付费: 否
答案:
MVCC or Multi-version concurrency control is used for avoiding unnecessary database locks when 2 or more requests tries to access or modify the data at the same time. This ensures that the time lag for a user to log in to the database is avoided. The transactions are recorded when anyone tries to access the content.
MVCC 或称为多版本并发控制,用于避免当两个或多个请求同时尝试访问或修改数据时不必要的数据库锁。这确保了用户登录数据库的时间延迟得以避免。当有人尝试访问内容时,事务会被记录。
For more information regarding this, you can refer here .
有关此问题的更多信息,你可以参考这里。
594. Can you explain the architecture of PostgreSQL?
你能解释 PostgreSQL 的架构吗?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: system-design
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e29 | 官方: 否 | 付费: 否
答案:
- The architecture of PostgreSQL follows the client-server model.
- The server side comprises of background process manager, query processer, utilities and shared memory space which work together to build PostgreSQL’s instance that has access to the data. The client application does the task of connecting to this instance and requests data processing to the services. The client can either be GUI (Graphical User Interface) or a web application. The most commonly used client for PostgreSQL is pgAdmin.
595. What are ACID properties? Is PostgreSQL compliant with ACID?
什么是 ACID 属性?PostgreSQL 是否符合 ACID 标准?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e2c | 官方: 否 | 付费: 否
答案:
ACID stands for Atomicity, Consistency, Isolation, Durability. They are database transaction properties which are used for guaranteeing data validity in case of errors and failures. - Atomicity: This property ensures that the transaction is completed in all-or-nothing way.
ACID 代表原子性、一致性、隔离性、持久性。它们是数据库事务属性,用于在出现错误和故障时保证数据的有效性。- 原子性:此属性确保事务以全有或全无的方式完成。
- Consistency: This ensures that updates made to the database is valid and follows rules and restrictions.
- Isolation: This property ensures integrity of transaction that are visible to all other transactions.
Durability: This property ensures that the committed transactions are stored permanently in the database.
PostgreSQL is compliant with ACID properties.PostgreSQL 符合 ACID 属性标准。
596. How can you delete a database in PostgreSQL?
如何在 PostgreSQL 中删除数据库?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e2f | 官方: 否 | 付费: 否
答案:
This can be done by using the DROP DATABASE command as shown in the syntax below:
可以通过使用 DROP DATABASE 命令来完成,如下面语法所示:
DROP DATABASE database_name;
DROP DATABASE database_name;
If the database has been deleted successfully, then the following message would be shown:
如果数据库已成功删除,则会显示以下消息:
DROP DATABASE
DROP DATABASE
597. How can you get a list of all databases in PostgreSQL?
如何获取 PostgreSQL 中所有数据库的列表?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e33 | 官方: 否 | 付费: 否
答案:
This can be done by using the command \l -> backslash followed by the lower-case letter L.
可以通过使用命令 \l -> 反斜杠后跟小写字母 L 来完成。
598. What are string constants in PostgreSQL?
什么是 PostgreSQL 中的字符串常量?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e37 | 官方: 否 | 付费: 否
答案:
They are character sequences bound within single quotes. These are using during data insertion or updation to characters in the database. There are special string constants that are quoted in dollars. Syntax: $tag$$tag$ The tag in the constant is optional and when we are not specifying the tag, the constant is called a double-dollar string literal.
它们是括在单引号内的字符序列。在向数据库中的字符进行数据插入或更新时使用这些常量。还有以美元符号引用的特殊字符串常量。语法:$tag$$tag$ 常量中的标签是可选的,当我们不指定标签时,该常量被称为双美元字符串字面量。
599. Define sequence.
定义序列。
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e3a | 官方: 否 | 付费: 否
答案:
A sequence is a schema-bound, user-defined object which aids to generate a sequence of integers. This is most commonly used to generate values to identity columns in a table. We can create a sequence by using the CREATE SEQUENCE statement as shown below:
序列是一种绑定到模式、用户定义的对象,有助于生成整数序列。这最常用于生成表中标识列的值。我们可以使用 CREATE SEQUENCE 语句创建序列,如下所示:
CREATE SEQUENCE serial_num START 100;
CREATE SEQUENCE serial_num START 100;
To get the next number 101 from the sequence, we use the nextval() method as shown below:
要从序列中获取下一个数字 101,我们使用 nextval() 方法,如下所示:
SELECT nextval('serial_num');
SELECT nextval('serial_num');
We can also use this sequence while inserting new records using the INSERT command:
我们也可以在使用 INSERT 命令插入新记录时使用这个序列:
INSERT INTO ib_table_name VALUES (nextval('serial_num'), 'interviewbit');
INSERT INTO ib_table_name VALUES (nextval('serial_num'), 'interviewbit');
600. What is the capacity of a table in PostgreSQL?
PostgreSQL 中表的容量是多少?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e3d | 官方: 否 | 付费: 否
答案:
The maximum size of PostgreSQL is 32TB.
PostgreSQL 的最大大小为 32TB。
601. What is the importance of the TRUNCATE statement?
TRUNCATE 语句的重要性是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e40 | 官方: 否 | 付费: 否
答案:
TRUNCATE TABLE name_of_table statement removes the data efficiently and quickly from the table. The truncate statement can also be used to reset values of the identity columns along with data cleanup as shown below:
TRUNCATE TABLE name_of_table 语句可以高效且快速地移除表中的数据。TRUNCATE 语句也可以用于重置标识列的值,同时进行数据清理,如下所示:
TRUNCATE TABLE name_of_table
TRUNCATE TABLE name_of_table
RESTART IDENTITY;
RESTART IDENTITY;
We can also use the statement for removing data from multiple tables all at once by mentioning the table names separated by comma as shown below:
我们也可以使用该语句同时从多个表中移除数据,只需将表名用逗号分隔列出,如下所示:
TRUNCATE TABLE
TRUNCATE TABLE
table_1,
table_1,
table_2,
table_2,
table_3;
table_3;
602. Define tokens in PostgreSQL?
在 PostgreSQL 中定义令牌?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e4a | 官方: 否 | 付费: 否
答案:
A token in PostgreSQL is either a keyword, identifier, literal, constant, quotes identifier, or any symbol that has a distinctive personality. They may or may not be separated using a space, newline or a tab. If the tokens are keywords, they are usually commands with useful meanings. Tokens are known as building blocks of any PostgreSQL code.
PostgreSQL 中的令牌可以是关键字、标识符、字面量、常量、带引号的标识符,或任何具有独特性质的符号。它们可能用空格、换行或制表符分隔,也可能不用。如果令牌是关键字,它们通常是具有有用含义的命令。令牌被称为任何 PostgreSQL 代码的构建块。
603. What are partitioned tables called in PostgreSQL?
PostgreSQL 中的分区表称为什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e4d | 官方: 否 | 付费: 否
答案:
Partitioned tables are logical structures that are used for dividing large tables into smaller structures that are called partitions. This approach is used for effectively increasing the query performance while dealing with large database tables. To create a partition, a key called partition key which is usually a table column or an expression, and a partitioning method needs to be defined. There are three types of inbuilt partitioning methods provided by Postgres: - Range Partitioning: This method is done by partitioning based on a range of values. This method is most commonly used upon date fields to get monthly, weekly or yearly data. In the case of corner cases like value belonging to the end of the range, for example: if the range of partition 1 is 10-20 and the range of partition 2 is 20-30, and the given value is 10, then 10 belongs to the second partition and not the first.
分区表是用于将大型表划分为称为分区的较小结构的逻辑结构。这种方法在处理大型数据库表时用于有效提高查询性能。要创建分区,需要定义一个称为分区键的键(通常是表列或表达式)以及一种分区方法。Postgres 提供了三种内置分区方法:- 范围分区:此方法通过基于值范围进行分区来实现。此方法最常用于日期字段,以获取每月、每周或每年的数据。对于像值属于范围末尾这样的边界情况,例如:如果分区1的范围是10-20,分区2的范围是20-30,给定值为10,则10属于第二个分区而不是第一个分区。
- List Partitioning: This method is used to partition based on a list of known values. Most commonly used when we have a key with a categorical value. For example, getting sales data based on regions divided as countries, cities, or states.
Hash Partitioning: This method utilizes a hash function upon the partition key. This is done when there are no specific requirements for data division and is used to access data individually. For example, you want to access data based on a specific product, then using hash partition would result in the dataset that we require.
The type of partition key and the type of method used for partitioning determines how positive the performance and the level of manageability of the partitioned table are.分区键的类型和用于分区的分区方法类型决定了分区表在性能和可管理性水平上的积极程度。
604. How can we start, restart and stop the PostgreSQL server?
我们如何启动、重启和停止 PostgreSQL 服务器?
- 知识点: 数据库 / 行为与软技能 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: behavioral | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e50 | 官方: 否 | 付费: 否
答案:
- To start the PostgreSQL server, we run:
service postgresql start
service postgresql start
- Once the server is successfully started, we get the below message:
Starting PostgreSQL: ok
正在启动 PostgreSQL:正常
- To restart the PostgreSQL server, we run:
service postgresql restart
service postgresql restart
Once the server is successfully restarted, we get the message:
服务器成功重启后,我们收到消息:
Restarting PostgreSQL: server stopped
正在重启 PostgreSQL:服务器已停止
ok
正常
- To stop the server, we run the command:
service postgresql stop
service postgresql stop
Once stopped successfully, we get the message:
成功停止后,我们收到消息:
Stopping PostgreSQL: server stopped
正在停止 PostgreSQL:服务器已停止
ok
正常
605. What is the command used for creating a database in PostgreSQL?
在 PostgreSQL 中用于创建数据库的命令是什么?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e53 | 官方: 否 | 付费: 否
答案:
The first step of using PostgreSQL is to create a database. This is done by using the createdb command as shown below: createdb db_name After running the above command, if the database creation was successful, then the below message is shown:
使用 PostgreSQL 的第一步是创建数据库。这是通过使用 createdb 命令完成的,如下所示:createdb db_name 运行上述命令后,如果数据库创建成功,则显示以下消息:
CREATE DATABASE
CREATE DATABASE
606. How will you change the datatype of a column?
如何更改列的数据类型?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e56 | 官方: 否 | 付费: 否
答案:
This can be done by using the ALTER TABLE statement as shown below:
这可以通过使用如下所示的 ALTER TABLE 语句来完成:
Syntax:
语法:
ALTER TABLE tname
修改表名
ALTER COLUMN col_name [SET DATA] TYPE new_data_type;
修改列名 [设置数据类型] 为新数据类型;
607. How do you define Indexes in PostgreSQL?
如何在 PostgreSQL 中定义索引?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e59 | 官方: 否 | 付费: 否
答案:
Indexes are the inbuilt functions in PostgreSQL which are used by the queries to perform search more efficiently on a table in the database. Consider that you have a table with thousands of records and you have the below query that only a few records can satisfy the condition, then it will take a lot of time to search and return those rows that abide by this condition as the engine has to perform the search operation on every single to check this condition. This is undoubtedly inefficient for a system dealing with huge data. Now if this system had an index on the column where we are applying search, it can use an efficient method for identifying matching rows by walking through only a few levels. This is called indexing.
索引是 PostgreSQL 中的内置功能,查询使用它来更高效地在数据库中的表上执行搜索。假设你有一个包含数千条记录的表,并且你有一个只有少数记录能满足条件的查询,那么要搜索并返回符合该条件的行将花费大量时间,因为引擎必须对每一行执行搜索操作来检查该条件。对于处理大量数据的系统来说,这无疑是低效的。现在,如果该系统在应用搜索的列上有索引,它就可以通过仅遍历几个层级来使用高效方法识别匹配的行。这称为索引。
Select * from some_table where table_col=120
从某个表中选择 *,其中表列 = 120
608. What is PostgreSQL?
什么是 PostgreSQL?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5e58d557c902bc7e5c | 官方: 否 | 付费: 否
答案:
PostgreSQL was first called Postgres and was developed by a team led by Computer Science Professor Michael Stonebraker in 1986. It was developed to help developers build enterprise-level applications by upholding data integrity by making systems fault-tolerant. PostgreSQL is therefore an enterprise-level, flexible, robust, open-source, and object-relational DBMS that supports flexible workloads along with handling concurrent users. It has been consistently supported by the global developer community. Due to its fault-tolerant nature, PostgreSQL has gained widespread popularity among developers.
PostgreSQL 最初被称为 Postgres,由计算机科学教授 Michael Stonebraker 领导的团队于 1986 年开发。它的开发目的是通过使系统具备容错性来维护数据完整性,帮助开发者构建企业级应用程序。因此,PostgreSQL 是一个企业级、灵活、健壮、开源且面向对象的 DBMS,它支持灵活的工作负载并处理并发用户。它一直受到全球开发者社区的支持。由于其容错特性,PostgreSQL 在开发者中广受欢迎。
609. How do you find orphan rows (orders without users)?
如何查找孤立行(没有用户的订单)?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ea0 | 官方: 否 | 付费: 否
答案:
Orphan rows occur when records in one table reference entries that do not exist in another table. A common example is orders that do not have a matching user record. Identifying such rows is important for data quality checks and referential integrity validation.
孤行发生在一个表中的记录引用了另一个表中不存在的条目时。一个常见的例子是没有匹配用户记录的订单。识别此类行对于数据质量检查和参照完整性验证非常重要。
The standard way to find orphan rows is to use an anti-join, which returns rows from one table that have no matching rows in another table.
查找孤行的标准方法是使用反连接,它返回一个表中在另一个表中没有匹配行的行。
Example: Finding orders that do not have a corresponding user.
示例:查找没有对应用户的订单。
SELECT o.order_id, o.user_id
选择 o.order_id, o.user_id
FROM orders o
FROM orders o
LEFT JOIN users u
LEFT JOIN users u
ON o.user_id = u.user_id
ON o.user_id = u.user_id
WHERE u.user_id IS NULL;
WHERE u.user_id IS NULL;
In this query: - A left join keeps all orders
在这个查询中:- 左连接保留了所有订单
- Rows where no matching user exists result in NULL values on the user side
Filtering on u.user_id IS NULL identifies orphan orders
An alternative approach is to use NOT EXISTS , which is often preferred for clarity and NULL safety:另一种方法是使用 NOT EXISTS,这通常更受青睐,因为它更清晰且能避免 NULL 问题:
SELECT o.order_id, o.user_id
选择 o.order_id, o.user_id
FROM orders o
FROM orders o
WHERE NOT EXISTS (
WHERE NOT EXISTS (
SELECT 1
SELECT 1
FROM users u
FROM users u
WHERE u.user_id = o.user_id
WHERE u.user_id = o.user_id
);
Both methods correctly identify orphan rows. Anti-joins like these are commonly used in data audits, cleanup tasks, and pipeline validations to ensure data consistency.
两种方法都能正确识别孤立行。此类反连接常用于数据审计、清理任务和管道验证,以确保数据一致性。
610. 9. How do you compute LTV and bucket users?
- 如何计算 LTV 并将用户分桶?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ea3 | 官方: 否 | 付费: 否
答案:
Lifetime Value (LTV) represents the total revenue generated by a user over their entire lifetime. To compute LTV, all purchases made by a user are summed up. Once LTV is calculated, users can be grouped into buckets (for example, high, medium, low value) to support segmentation and analysis.
生命周期价值(LTV)表示用户在其整个生命周期内产生的总收入。要计算 LTV,需将用户的所有购买金额相加。一旦计算出 LTV,就可以将用户分组到不同桶中(例如,高、中、低价值),以支持细分和分析。
A common way to bucket users is by using the NTILE window function, which divides users into equal-sized groups based on their LTV.
一种常见的用户分桶方法是使用 NTILE 窗口函数,它根据用户的 LTV 将用户划分为大小相等的组。
Example: Computing user LTV and dividing users into 4 value buckets.
示例:计算用户 LTV 并将用户划分到 4 个价值桶中。
WITH user_ltv AS (
WITH user_ltv AS (
SELECT
选择
user_id,
user_id,
SUM(amount) AS ltv
SUM(amount) AS ltv
FROM orders
FROM orders
GROUP BY user_id
GROUP BY user_id
)
SELECT
选择
user_id,
user_id,
ltv,
ltv,
NTILE(4) OVER (ORDER BY ltv DESC) AS ltv_bucket
NTILE(4) OVER (ORDER BY ltv DESC) AS ltv_bucket
FROM user_ltv;
FROM user_ltv;
In this query: - LTV is calculated as the total spend per user
在此查询中:- LTV 按每个用户的总消费额计算
- Users are ordered by LTV in descending order
NTILE(4) splits users into four equal buckets
These buckets can be interpreted as high-value, mid-value, and low-value user segments. This method is widely used in customer analytics, marketing targeting, and revenue analysis.这些分桶可被解读为高价值、中价值和低价值用户群体。此方法广泛应用于客户分析、营销定向和收入分析中。
611. How do you find churned customers (no purchase in the last 60 days)?
你如何找出流失客户(最近 60 天内没有购买记录)?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ea6 | 官方: 否 | 付费: 否
答案:
Churned customers are typically defined as users who were active in the past but have not made a purchase within a recent time window, such as the last 60 days. The key is to identify each customer’s most recent purchase date and compare it with the current date.
流失客户通常被定义为过去活跃但在最近一段时间窗口(如最近 60 天)内没有进行购买的用户。关键在于识别每位客户的最近购买日期,并将其与当前日期进行比较。
This is usually done by aggregating purchase data per customer and filtering based on the maximum purchase date.
这通常通过按客户汇总购买数据,并根据最大购买日期进行筛选来实现。
Example: Finding customers who have not purchased in the last 60 days.
示例:找出最近 60 天内未购买过的客户。
SELECT
选择
customer_id
customer_id
FROM orders
FROM orders
GROUP BY customer_id
GROUP BY customer_id
HAVING MAX(order_date) In this query: - MAX(order_date) identifies the most recent purchase per customer
HAVING MAX(order_date) 在此查询中:- MAX(order_date) 识别每个客户最近的一次购买
Customers whose latest purchase is older than 60 days are marked as churned
If customers with no purchases at all also need to be included, a left join with the customer table can be used instead of grouping only on orders.如果还需要包含完全没有购买记录的客户,可以使用与客户表的左连接,而不是仅对订单进行分组。
This approach is simple, efficient, and commonly used in retention and churn analysis.
这种方法简单、高效,常用于留存和流失分析中。
612. How do you detect anomalies compared to a trailing 7-day average?
你如何检测与过去7天平均值的异常?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ea9 | 官方: 否 | 付费: 否
答案:
Anomaly detection using a trailing average involves comparing the current day’s metric against the average value from the previous 7 days. A data point is typically considered anomalous if it deviates significantly from this rolling baseline.
使用移动平均进行异常检测涉及将当前日期的指标与前7天的平均值进行比较。如果数据点显著偏离此滚动基线,通常被视为异常。
The usual approach is to calculate a 7-day rolling average using a window function and then compare the current value with that average. This helps smooth out short-term fluctuations and highlights unusual spikes or drops.
常见的方法是使用窗口函数计算7天滚动平均值,然后将当前值与该平均值进行比较。这有助于平滑短期波动并突出异常的峰值或下降。
Example: Detecting daily revenue anomalies using a trailing 7-day average.
示例:使用过去7天平均值检测每日收入异常。
SELECT
选择
order_date,
order_date,
daily_revenue,
daily_revenue,
AVG(daily_revenue) OVER (
AVG(daily_revenue) OVER (
ORDER BY order_date
ORDER BY order_date
ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING
ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING
) AS trailing_7_day_avg,
) AS trailing_7_day_avg,
CASE
CASE
WHEN daily_revenue >
当 daily_revenue >
AVG(daily_revenue) OVER (
AVG(daily_revenue) OVER (
ORDER BY order_date
ORDER BY order_date
ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING
ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING
) * 1.3
THEN 'anomaly'
THEN 'anomaly'
ELSE 'normal'
ELSE 'normal'
END AS status
END AS status
FROM daily_sales;
FROM daily_sales;
In this query: - The rolling average is calculated using the previous 7 days only
在此查询中:- 滚动平均值仅使用前7天计算
- The current day is excluded to avoid bias
A threshold (for example, 30% above average) is used to flag anomalies
Thresholds can be adjusted based on business needs. This method is widely used in monitoring systems to detect unusual behavior while accounting for natural variation in the data.阈值可根据业务需求调整。此方法广泛用于监控系统,以检测异常行为,同时考虑数据中的自然变化。
613. How do you find revenue excluding refunds or chargebacks?
如何计算排除退款或拒付后的收入?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7eac | 官方: 否 | 付费: 否
答案:
To calculate revenue excluding refunds or chargebacks, the idea is to compute net revenue by subtracting refunded or reversed amounts from the original sales. This ensures revenue reflects only the money actually retained by the business.
要计算排除退款或拒付后的收入,思路是通过从原始销售额中减去已退款或已冲销的金额来计算净收入。这确保收入仅反映企业实际留存的资金。
The most common approach is to separate sales and refund transactions, then aggregate them together using conditional logic. Each transaction type is handled differently while summing amounts.
最常见的方法是将销售和退款交易分开,然后使用条件逻辑将它们聚合在一起。每种交易类型在求和时被区别处理。
Example: Calculating net revenue from sales and refunds.
示例:从销售和退款中计算净收入。
SELECT
选择
SUM(
SUM(
CASE
CASE
WHEN transaction_type = 'sale' THEN amount
WHEN transaction_type = 'sale' THEN amount
WHEN transaction_type IN ('refund', 'chargeback') THEN -amount
WHEN transaction_type IN ('refund', 'chargeback') THEN -amount
ELSE 0
否则 0
END
END
) AS net_revenue
) AS net_revenue
FROM transactions;
FROM transactions;
In this query: - Sales increase revenue
在此查询中:- 销售增加收入
- Refunds and chargebacks reduce revenue
Net revenue is computed in a single aggregation
If refunds are stored in a separate table, a similar result can be achieved by aggregating sales and refunds separately and then subtracting refund totals.如果退款存储在单独的表中,可以通过分别汇总销售和退款,然后减去退款总额来获得类似结果。
This approach ensures that revenue reports remain accurate and are not inflated by transactions that were later reversed
这种方法确保收入报告保持准确,不会因后来被撤销的交易而虚高
614. How do you compute A/B test conversion uplift?
如何计算A/B测试转化率提升?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7eaf | 官方: 否 | 付费: 否
答案:
A/B test conversion uplift measures how much better one variant performs compared to another. The key is to separate users by their assigned variant and then calculate conversion rates independently for each group.
A/B测试转化率提升衡量一个变体相对于另一个变体表现好多少。关键在于根据用户被分配的变体来区分用户,然后独立计算每个组的转化率。
To compute uplift correctly, users must be counted only once, based on their original assignment, and conversions should be measured after the assignment event.
要正确计算提升,用户必须根据其原始分配仅计数一次,并且转化应在分配事件之后进行衡量。
Example: Calculating conversion rates for control and treatment groups.
示例:计算对照组和实验组的转化率。
WITH assignments AS (
WITH assignments AS (
SELECT
选择
user_id,
user_id,
variant
variant
FROM ab_assignments
从 ab_assignments
),
conversions AS (
转换 AS (
SELECT DISTINCT user_id
选择不同的用户ID
FROM events
FROM events
WHERE event_type = 'purchase'
其中事件类型 = '购买'
)
SELECT
选择
a.variant,
a.变体,
COUNT(DISTINCT a.user_id) AS users,
计算不同的a.用户ID AS 用户数,
COUNT(DISTINCT c.user_id) AS converted_users,
计算不同的c.用户ID AS 转化用户数,
COUNT(DISTINCT c.user_id) * 1.0 / COUNT(DISTINCT a.user_id) AS conversion_rate
计算不同的c.用户ID * 1.0 / 计算不同的a.用户ID AS 转化率
FROM assignments a
从分配 a
LEFT JOIN conversions c
左连接转换 c
ON a.user_id = c.user_id
在 a.用户ID = c.用户ID
GROUP BY a.variant;
分组依据 a.变体;
Once conversion rates are computed for each variant, uplift is calculated as the difference between the treatment and control conversion rates.
一旦计算出每个变体的转化率,提升量就通过处理组和对照组转化率之间的差异来计算。
This approach ensures that: - Users are grouped strictly by their assigned variant
这种方法确保了:- 用户严格按照分配到的变体进行分组
- Conversions are attributed correctly
Each user is counted only once
A/B test analysis often extends this by adding statistical significance checks, but the core SQL logic focuses on correct assignment and conversion counting.A/B测试分析通常通过添加统计显著性检验来扩展,但核心SQL逻辑专注于正确分配和转化计数。
615. How do you deduplicate rows and keep the latest record?
你如何对行去重并保留最新记录?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7eb2 | 官方: 否 | 付费: 否
答案:
Deduplication is commonly required when multiple records exist for the same entity, and only the most recent record should be retained. The standard approach is to rank records within each duplicate group using a timestamp and then filter out all but the latest one.
当同一实体存在多条记录且只需保留最新一条时,通常需要进行去重。标准做法是使用时间戳对每个重复组内的记录进行排序,然后过滤掉除最新记录外的所有记录。
This is typically done using the ROW_NUMBER window function, ordered by the timestamp in descending order. Rows with rank 1 represent the latest record per group.
这通常使用 ROW_NUMBER 窗口函数实现,按时间戳降序排序。排名为 1 的行代表每个组中的最新记录。
Example: Keeping the latest record per user based on updated_at .
示例:根据 updated_at 保留每位用户的最新记录。
SELECT *
SELECT *
FROM (
FROM (
SELECT
选择
user_id,
user_id,
email,
email,
updated_at,
updated_at,
ROW_NUMBER() OVER (
ROW_NUMBER() OVER (
PARTITION BY user_id
PARTITION BY user_id
ORDER BY updated_at DESC
ORDER BY updated_at DESC
) AS rn
) AS rn
FROM user_updates
FROM user_updates
) ranked
) ranked
WHERE rn = 1;
WHERE rn = 1;
In this query: - Records are grouped by user_id
在此查询中:- 记录按 user_id 分组
- The most recent record is ranked first using descending order
Filtering on rn = 1 removes older duplicates
This method is reliable, easy to read, and works well even when multiple updates exist for the same entity. It is preferred over DISTINCT when the definition of “latest” depends on time or versioning.此方法可靠、易于阅读,并且即使同一实体存在多个更新也能很好地工作。当“最新”的定义取决于时间或版本时,它优先于 DISTINCT。
616. How do you sessionize events using a 30-minute inactivity window?
如何使用30分钟非活动窗口将会话事件分段?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7eb5 | 官方: 否 | 付费: 否
答案:
Sessionization groups user events into sessions based on periods of activity separated by inactivity. A common rule is to start a new session if the time gap between two consecutive events exceeds 30 minutes.
会话分段根据由非活动期分隔的活动周期将用户事件分组为会话。常见规则是,如果两个连续事件之间的时间间隔超过30分钟,则开始一个新会话。
The typical approach uses the LAG window function to compare each event’s timestamp with the previous event for the same user. When the gap is greater than 30 minutes, a session break is identified. A cumulative sum is then used to assign session numbers.
典型方法使用 LAG 窗口函数将每个事件的时间戳与同一用户上一个事件进行比较。当间隔大于30分钟时,标识会话中断。然后使用累加和来分配会话编号。
Example: Creating sessions per user with a 30-minute inactivity threshold.
示例:为每个用户创建具有30分钟非活动阈值的会话。
WITH ordered_events AS (
WITH ordered_events AS (
SELECT
选择
user_id,
user_id,
event_time,
event_time,
LAG(event_time) OVER (
LAG(event_time) OVER (
PARTITION BY user_id
PARTITION BY user_id
ORDER BY event_time
排序 按 event_time
) AS prev_event_time
) AS prev_event_time
FROM events
FROM events
),
session_flags AS (
session_flags AS (
SELECT
选择
user_id,
user_id,
event_time,
event_time,
CASE
CASE
WHEN prev_event_time IS NULL
当 prev_event_time 为空
OR event_time - prev_event_time > INTERVAL '30 minutes'
或 event_time - prev_event_time > INTERVAL '30 minutes'
THEN 1
则 1
ELSE 0
否则 0
END AS is_new_session
结束 作为 is_new_session
FROM ordered_events
从 ordered_events 中
)
SELECT
选择
user_id,
user_id,
event_time,
event_time,
SUM(is_new_session) OVER (
求和(is_new_session) 按 (
PARTITION BY user_id
PARTITION BY user_id
ORDER BY event_time
排序 按 event_time
ROWS UNBOUNDED PRECEDING
行 无界 之前
) AS session_id
) 作为 session_id
FROM session_flags;
从 session_flags 中;
This logic works as follows:
该逻辑的工作原理如下:
- LAG gets the previous event time for each user
- A new session is flagged when inactivity exceeds 30 minutes
- A cumulative sum assigns a unique session ID per user
Sessionization like this is commonly used in analytics to compute session counts, session duration, and user engagement metrics.
这种会话化处理常用于分析中,用于计算会话数、会话时长和用户参与度指标。
617. How do you compute D1/D7 retention cohorts?
如何计算D1/D7留存队列?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7eb8 | 官方: 否 | 付费: 否
答案:
D1 and D7 retention measure how many users return to the product 1 day or 7 days after their first activity. The main idea behind cohort analysis is to group users based on their signup or first activity date and then check whether they are active again after a fixed number of days.
D1和D7留存衡量的是用户在首次活动后的1天或7天内再次返回产品的用户数量。队列分析的主要思想是根据用户注册或首次活动日期对其进行分组,然后检查他们在固定天数后是否再次活跃。
To compute retention, users are first assigned to a cohort based on the date they joined. Their subsequent activity is then joined back to this cohort to see if they were active on Day 1 or Day 7 relative to the cohort date.
要计算留存率,首先根据用户加入的日期将其分配到特定的队列中。然后将他们后续的活动与该队列关联,以检查他们在相对于队列日期的第1天或第7天是否活跃。
Example: Calculating D1 and D7 retention based on user activity.
示例:基于用户活动计算D1和D7留存。
WITH cohorts AS (
WITH cohorts AS (
SELECT
选择
user_id,
user_id,
DATE(MIN(event_time)) AS cohort_date
DATE(MIN(event_time)) AS cohort_date
FROM events
FROM events
GROUP BY user_id
GROUP BY user_id
),
activity AS (
activity AS (
SELECT
选择
user_id,
user_id,
DATE(event_time) AS activity_date
DATE(event_time) AS activity_date
FROM events
FROM events
)
SELECT
选择
c.cohort_date,
c.cohort_date,
COUNT(DISTINCT c.user_id) AS cohort_size,
COUNT(DISTINCT c.user_id) AS cohort_size,
COUNT(DISTINCT CASE
COUNT(DISTINCT CASE
WHEN a.activity_date = c.cohort_date + INTERVAL '1 day'
WHEN a.activity_date = c.cohort_date + INTERVAL '1 day'
THEN c.user_id
THEN c.user_id
END) AS d1_retained,
END) AS d1_retained,
COUNT(DISTINCT CASE
COUNT(DISTINCT CASE
WHEN a.activity_date = c.cohort_date + INTERVAL '7 day'
WHEN a.activity_date = c.cohort_date + INTERVAL '7 day'
THEN c.user_id
THEN c.user_id
END) AS d7_retained
END) AS d7_retained
FROM cohorts c
FROM cohorts c
LEFT JOIN activity a
LEFT JOIN activity a
ON c.user_id = a.user_id
ON c.user_id = a.user_id
GROUP BY c.cohort_date
GROUP BY c.cohort_date
ORDER BY c.cohort_date;
ORDER BY c.cohort_date;
This approach ensures that: - Users are grouped by their first activity date
此方法确保:- 用户根据其首次活动日期进行分组
- Retention is measured relative to the cohort date
Each user is counted only once per retention window
Retention rates are then calculated by dividing D1 or D7 retained users by the total cohort size.然后通过将D1或D7留存用户除以总队列规模来计算留存率。
618. How do you calculate funnel conversion (visit -> signup -> purchase)?
如何计算漏斗转化(访问 -> 注册 -> 购买)?
- 知识点: 数据库 (主题: sql, database;标签: interviewbit, sql, topic-specific, database)
- 类型: technical | 难度: medium | 子类型: concept
- 分类: fullstack
- id: 69b37c5f58d557c902bc7ebb | 官方: 否 | 付费: 否
答案:
Funnel conversion measures how many users move through a defined sequence of events, such as visit -> signup -> purchase. The key challenge is to ensure that each user is counted only once at each stage and that events occur in the correct order.
漏斗转化衡量有多少用户按定义的事件序列(如访问 -> 注册 -> 购买)流动。关键挑战是确保每个用户在每一步只被计数一次,并且事件按正确顺序发生。
A common approach is to track distinct users at every stage of the funnel and use timestamps to enforce the sequence. This prevents users who sign up before visiting, or purchase without signing up, from being counted incorrectly.
常见方法是在漏斗的每个阶段跟踪不同的用户,并使用时间戳来强制顺序。这可以防止在访问前注册或在未注册的情况下购买的用户被错误计数。
Typically, the funnel is calculated within a fixed time window to keep the analysis meaningful.
通常,漏斗在固定的时间窗口内计算,以保持分析有意义。
Example: Calculating how many users progress through each funnel stage.
示例:计算有多少用户通过每个漏斗阶段。
WITH funnel_events AS (
WITH funnel_events AS (
SELECT
选择
user_id,
user_id,
MIN(CASE WHEN event_type = 'visit' THEN event_time END) AS visit_time,
MIN(CASE WHEN event_type = 'visit' THEN event_time END) AS visit_time,
MIN(CASE WHEN event_type = 'signup' THEN event_time END) AS signup_time,
MIN(CASE WHEN event_type = 'signup' THEN event_time END) AS signup_time,
MIN(CASE WHEN event_type = 'purchase' THEN event_time END) AS purchase_time
MIN(CASE WHEN event_type = 'purchase' THEN event_time END) AS purchase_time
FROM events
FROM events
GROUP BY user_id
GROUP BY user_id
)
SELECT
选择
COUNT(DISTINCT user_id) AS visits,
COUNT(DISTINCT user_id) AS visits,
COUNT(DISTINCT CASE
COUNT(DISTINCT CASE
WHEN signup_time IS NOT NULL
WHEN signup_time IS NOT NULL
AND signup_time > visit_time
AND signup_time > visit_time
THEN user_id
则 user_id
END) AS signups,
结束) AS 注册数,
COUNT(DISTINCT CASE
COUNT(DISTINCT CASE
WHEN purchase_time IS NOT NULL
当 purchase_time 不为空
AND purchase_time > signup_time
且 purchase_time > signup_time
THEN user_id
则 user_id
END) AS purchases
结束) AS 购买数
FROM funnel_events;
来自 funnel_events;
This query ensures that: - Each user is counted once per stage
此查询确保:- 每个用户在每个阶段仅被计数一次
- Events follow the correct order
Only valid funnel progressions are included
Funnel conversion rates can then be calculated by dividing signups by visits, and purchases by signups.漏斗转化率可通过将注册数除以访问数,以及购买数除以注册数来计算。
Coding Problems
0/3
Easy Problems
简单问题
SQL Programming
SQL编程
Engineers Joined
加入的工程师
Easy
简单
25.27 Mins
25.27 分钟
Solve
解答
Student Query
学生查询
Easy
简单
8.17 Mins
8.17 分钟
Solve
解答
Country Filtration
国家筛选
Easy
简单
6.8 Mins
6.8分钟
Solve
解答
0/1
Intermediate Problems
中级问题
SQL Programming
SQL编程
Study Selection
研究选择
Medium
中等
9.33 Mins
9.33分钟
Solve
解答
0/2
Advanced Problems
进阶问题
SQL Programming
SQL编程
Job Offer
工作邀请
Hard
困难
24.52 Mins
24.52分钟
Solve
解答
Job Offers 2.0
工作邀请2.0
Hard
困难
26.15 Mins
26.15分钟
Solve
解答
619. 如果 root 密码丢失,如何修改 root 密码?
- 知识点: 数据库 / 安全 / 系统设计/架构 / UI/UX 设计 (主题: mysql, security, admin;标签: Root Password, skip-grants-table)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e866 | 官方: 是 | 付费: 否
答案:
答案在密码丢失的情况下,用户应使用 skip-grants-table 启动数据库,然后修改密码。之后,使用新密码以正常模式重新启动数据库。
620. 如何解决数据盘(Data Disk)满了的问题?
- 知识点: 数据库 / 操作系统与网络 / 系统设计/架构 / UI/UX 设计 (主题: mysql, linux, storage;标签: Disk Full, Soft Link, .frm, .idb)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e86a | 官方: 是 | 付费: 否
答案:
答案当数据盘满且过载时,解决方式是创建一个软链接(Soft Link),并将 .frm 与 .idb 文件移动到该链接位置。
621. 如何定义在 MySQL 中对网络层(Network Layers)的测试?
- 知识点: 数据库 / 测试 / 操作系统与网络 / 系统设计/架构 / UI/UX 设计 (主题: mysql, networking, testing;标签: Network Layers, Testing, Architecture)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 6965da3dfa809e6d3885e87b | 官方: 是 | 付费: 否
答案:
答案为此,需要回顾分层架构(Layered Architecture),并在待测试的应用背景下,确定硬件(Hardware)与软件配置(Software Configuration)依赖关系。
622. EJB包括(SessionBean,EntityBean)说出他们的生命周期,及如何管理事务的?
- 知识点: 数据库 / 编程语言基础 (主题: java, ejb, transaction;标签: EJB, SessionBean, EntityBean, JTA, JTS, XA, OTS)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 6965e772fa809e6d388763dd | 官方: 是 | 付费: 否
答案:
答案SessionBean:Stateless Session Bean 的生命周期是由容器(Container)决定的,当客户机发出请求要建立一个Bean的实例时,EJB容器不一定要创建一个新的Bean的实例供客户机调用,而是随便找一个现有的实例提供给客户机。当客户机第一次调用一个Stateful Session Bean 时,容器必须立即在服务器中创建一个新的Bean实例,并关联到客户机上,以后此客户机调用Stateful Session Bean 的方法时容器会把调用分派到与此客户机相关联的Bean实例。
EntityBean:Entity Beans能存活相对较长的时间,并且状态是持续的。只要数据库中的数据存在,Entity beans就一直存活。而不是按照应用程序或者服务进程来说的。即使EJB容器崩溃了,Entity beans也是存活的。Entity Beans生命周期能够被容器或者 Beans自己管理。
EJB通过以下技术管理实务:对象管理组织(OMG)的对象实务服务(OTS,Object Transaction Service),Sun Microsystems的Transaction Service(JTS,Java Transaction Service)、Java Transaction API(JTA,Java Transaction API),开发组(X/Open)的XA接口(XA Interface)。
623. 神经网络(Neural Network)中激活函数(Activation Function)的真正意义?一个激活函数需要具备有哪些必要的属性?还有哪些属性是好的属性但不必要的?
- 知识点: 数据库 / 数据工程与数据科学/AI (主题: deep-learning, activation-function, relu, sigmoid, tanh, batch-normalization, selu, prelu, leaky-relu, maxout, optimization, sgd;标签: Activation Function, Nonlinearity, Differentiability, Saturation, Identity Mapping)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 69688906bc0b9904d6b60ae0 | 官方: 是 | 付费: 否
答案:
答案(1)非线性(Nonlinearity):即导数不是常数。这个条件是多层神经网络的基础,保证多层网络不退化成单层线性网络。这也是激活函数的意义所在。
(2)几乎处处可微(almost everywhere differentiable):可微性(differentiability)保证了在优化中梯度(gradient)的可计算性。传统的激活函数(activation function)如sigmoid等满足处处可微(everywhere differentiable)。对于分段线性函数(piecewise linear function)比如ReLU(Rectified Linear Unit),只满足几乎处处可微(即仅在有限个点处不可微)。对于SGD算法(Stochastic Gradient Descent)来说,由于几乎不可能收敛到梯度接近零的位置,有限的不可微点对于优化结果不会有很大影响。
(3)计算简单:非线性函数(nonlinear function)有很多。极端的说,一个多层神经网络(multi-layer neural network)也可以作为一个非线性函数,类似于Network In Network中把它当做卷积操作(convolution operation)的做法。但激活函数在神经网络前向的计算次数与神经元的个数成正比,因此简单的非线性函数自然更适合用作激活函数。这也是ReLU之流比其它使用Exp(Exponential)等操作的激活函数更受欢迎的其中一个原因。
(4)非饱和性(non-saturation):饱和(saturation)指的是在某些区间梯度接近于零(即梯度消失(vanishing gradient)),使得参数无法继续更新的问题。最经典的例子是Sigmoid,它的导数在x为比较大的正值和比较小的负值时都会接近于0。更极端的例子是阶跃函数(step function),由于它在几乎所有位置的梯度都为0,因此处处饱和,无法作为激活函数。ReLU在x>0时导数恒为1,因此对于再大的正值也不会饱和。但同时对于x<0,其梯度恒为0,这时候它也会出现饱和的现象(在这种情况下通常称为dying ReLU)。Leaky ReLU和PReLU(Parametric ReLU)的提出正是为了解决这一问题。
(5)单调性(monotonicity):即导数符号不变。这个性质大部分激活函数都有,除了诸如sin、cos等。个人理解,单调性使得在激活函数处的梯度方向不会经常改变,从而让训练更容易收敛。
(6)输出范围有限:有限的输出范围使得网络对于一些比较大的输入也会比较稳定,这也是为什么早期的激活函数都以此类函数为主,如Sigmoid、TanHo(Hyperbolic Tangent)。但这导致了前面提到的梯度消失问题,而且强行让每一层的输出限制到固定范围会限制其表达能力。因此现在这类函数仅用于某些需要特定输出范围的场合,比如概率输出(此时loss函数中的log操作能够抵消其梯度消失的影响)、LSTM(Long Short-Term Memory)里的gate函数。
(7)接近恒等变换(identity transformation):即约等于x。这样的好处是使得输出的幅值不会随着深度的增加而发生显著的增加,从而使网络更为稳定,同时梯度也能够更容易地回传。这个与非线性是有点矛盾的,因此激活函数基本只是部分满足这个条件,比如TanHo只在原点附近有线性区(在原点为0且在原点的导数为1),而ReLU只在x>0时为线性。这个性质也让初始化参数范围的推导更为简单。额外提一句,这种恒等变换的性质也被其他一些网络结构设计所借鉴,比如CNN(Convolutional Neural Network)中的ResNet[6]和RNN(Recurrent Neural Network)中的LSTM。
(8)参数少:大部分激活函数都是没有参数的。像PReLU带单个参数会略微增加网络的大小。还有一个例外是Maxout,尽管本身没有参数,但在同样输出通道数下Maxout需要的输入通道数是其它函数的k倍,这意味着神经元数目也需要变为k倍;但如果不考虑维持输出通道数的情况下,该激活函数又能将参数个数减少为原来的1/k倍。
(9)归一化(normalization):这个是最近才出来的概念,对应的激活函数是SELU[8](Scaled Exponential Linear Unit),主要思想是使样本分布自动归一化到零均值、单位方差的分布,从而稳定训练。在这之前,这种归一化的思想也被用于网络结构的设计,比如Batch Normalization(批归一化)。
624. 为什么“实时排行榜”用纯关系型数据库(relational database)在大规模下会变慢?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: system-design, database, performance;标签: RDBMS, performance, leaderboard)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 696dd4bae6ae93548e947f63 | 官方: 是 | 付费: 否
答案:
答案核心原因是实时排名需要频繁排序/扫描:计算某个玩家排名往往要比较大量记录(甚至全表扫描(full table scan)/复杂嵌套查询(nested query)),数据量到千万级时延迟显著;为了加速会建索引(index),但索引会降低写入性能;同时分数持续变化导致缓存很难命中且容易过期。最终关系库更适合持久化与分析,而不适合作为高频实时排名的主存储。
625. 如果用 DynamoDB 设计排行榜,GSI(Global Secondary Index)应如何建模?scatter-gather 的代价是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: system-design, dynamodb, nosql;标签: DynamoDB, GSI, scatter-gather)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 696dd4bae6ae93548e947f6c | 官方: 是 | 付费: 否
答案:
答案可用 GSI:partition key 选 player-id(或按榜单/区域分片),sort key 选 score,实现按分数范围查询。若需要全局 Top N,可能要对多个分区分别查询(scatter)再在服务端合并(gather),这会增加读放大(read amplification)、网络开销与服务端计算复杂度;当流量高到单一索引无法承载时才考虑更复杂的分区策略,并配合 DynamoDB Streams 做变更捕获与异步处理。
626. 为什么用 Cassandra 构建分布式计数器(distributed counter)在实践中可能“理论很美、落地很难”?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: distributed-systems, cassandra, crdt;标签: distributed counter, counters, idempotency)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 696de6ae623565038f404ba6 | 官方: 是 | 付费: 否
答案:
答案Cassandra 具备去中心化(decentralized)、gossip 通信、consistent hashing(一致性哈希)自动分区、leaderless replication(无主复制)等特性,理论上非常适合高可用与跨机房写入;但计数器场景对幂等(idempotency)与高并发更新的正确性要求极高。Cassandra 的 counter column 存在多项工程限制:计数列通常需要独立表结构、带 counter 的表生命周期受限(很难删除/变更)、更关键的是更新不幂等,在网络抖动/重试时容易造成重复累加,从而让“准确计数”难以保障。再叠加 Cassandra 运维复杂度高,实践上更倾向选择 CRDT(Conflict-Free Replicated Data Type)计数器或其他更可控方案。
627. 为什么即使 Redis 很快,也不建议用原生 INCR 之类命令做跨机房准确计数?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: redis, distributed-systems, consistency;标签: INCR, active-active, idempotency)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 696de6ae623565038f404bed | 官方: 是 | 付费: 否
答案:
答案Redis 原生命令在单实例/单主节点上原子性很好,但跨机房复制(cross-datacenter replication)会遇到网络抖动、重试与不确定成功(客户端不知道上次 INCR 是否执行成功)。由于 INCR 更新天然不幂等,一次请求被重复执行就会导致计数偏大。为了在多活场景保持准确,需要更新操作具备去重与可合并的语义;原生计数器很难做到这一点,除非额外引入 Lua/Set 存 userId、记录操作 ID 来实现应用层幂等。
628. 为什么文中强调“不要用消息队列(Message Queue)/原生 Redis(Native Redis)/Cassandra counter(Cassandra 计数器)”做可扩展准确计数?核心原因是什么?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: distributed-systems, crdt, redis, messaging, cassandra;标签: idempotency, accuracy, design choice)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 696de6bb623565038f405908 | 官方: 是 | 付费: 否
答案:
答案三者的共同痛点是:在高可用分布式环境(Distributed Environment)里,计数更新很难做到端到端幂等(End-to-End Idempotency)与严格一次语义(Exactly-Once Semantics)。消息队列(Message Queue)难保证 exactly-once;Redis INCR(Redis 自增命令)遇到网络失败重试会重复执行;Cassandra counter(Cassandra 计数器)更新同样不幂等(Non-Idempotent)且工程限制多。对于“必须准确”的计数器(Counter),这会把故障重试转化为数据错误。相比之下,CRDT(无冲突复制数据类型,Conflict-Free Replicated Data Type)通过数学收敛与幂等合并(Idempotent Merge),把正确性下沉到数据类型/存储层,更适合多活准确计数。
629. 什么是反规范化(Denormalization)?什么时候应该使用?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 (主题: databases, performance;标签: denormalization, performance, tradeoffs)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 696f113f120fcc1591159296 | 官方: 是 | 付费: 否
答案:
答案反规范化(Denormalization)为读性能引入冗余,减少 JOIN(连接操作)。适合读多写少、聚合频繁或 OLAP(在线分析处理,Online Analytical Processing)场景;风险是更难保证一致性(Consistency)、更新逻辑复杂、数据膨胀。需要配合同步策略、校验与回填机制。
630. 你会如何设计一个车辆 listing 系统(Car Listing System)?请描述核心组件与技术选型理由。
- 知识点: 数据库 / 安全 / 系统设计/架构 / UI/UX 设计 (主题: system-design, search, database;标签: System Design, Elasticsearch, JWT)
- 类型: technical | 难度: hard | 子类型: system-design
- 分类: fullstack
- 公司: Carsales
- id: 697042c1120fcc1591302fc1 | 官方: 是 | 付费: 否
答案:
答案核心组件:1) 前端(浏览/筛选/发布);2) 后端 API(Listings(列表)、Users(用户)、Media(媒体));3) 数据库(PostgreSQL/MySQL 存交易型数据);4) 搜索(Elasticsearch/OpenSearch 支持多维过滤/排序);5) 鉴权(JWT(JSON Web Token)/OAuth(开放授权,Open Authorization));6) 媒体存储(对象存储(Object Storage)+ CDN(内容分发网络,Content Delivery Network));7) 异步处理(图片处理、审核、索引同步)用队列(Queue)。
关键点:写入走 DB(数据库),搜索走 ES(Elasticsearch);通过事件/Outbox(发件箱模式)保证索引最终一致;对热门查询做缓存(Cache);对滥用做风控与限流(Rate Limiting)。
AnswerCore components: frontend; backend APIs (Listings/Users/Media); relational DB for transactional data; Elasticsearch/OpenSearch for fast filtered search; auth via JWT/OAuth; object storage + CDN for images; async processing via queues.
答案:核心组件:前端;后端 API(列表/用户/媒体);用于事务数据的关系型数据库;用于快速过滤搜索的 Elasticsearch/OpenSearch;通过 JWT/OAuth 进行身份验证;用于图片的对象存储 + CDN;通过队列进行异步处理。
Design: writes to DB, reads/search via ES; event/outbox for eventual consistency; caching for hot queries; abuse prevention & rate limiting.
设计:写入数据库,通过 ES 进行读取/搜索;使用事件/发件箱模式实现最终一致性;对热点查询进行缓存;滥用防护与速率限制。
631. 数据库索引(Database Index)有哪些不同类型,何时使用它们?
- 知识点: 数据库 (主题: databases, indexing;标签: B-Tree, Hash Index, Bitmap Index, Full-text)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 6977301aa39c9c5c3a8c6280 | 官方: 是 | 付费: 否
答案:
答案常见索引类型:B-Tree(B树索引)(最通用,适合范围查询与排序)、Hash(哈希索引)(等值查询快但不适合范围)、Bitmap(位图索引)(低基数列与位运算过滤)、全文索引(Full-Text Index)(文本检索)、空间索引(Spatial Index)(地理/几何)。选用时看查询模式:范围/排序优先 B-Tree;严格等值且引擎支持可用 Hash;维度型低基数过滤可考虑 Bitmap;文本搜索用全文索引。同时注意复合索引顺序与覆盖索引(Covering Index)策略。
632. 如何优化数据库查询以提高性能?
- 知识点: 数据库 / 操作系统与网络 / 行为与软技能 (主题: databases, sql, performance;标签: Explain Plan, Index, Slow Query, Concurrency)
- 类型: behavioral | 难度: hard | 子类型:
- 分类: fullstack
- id: 69773021a39c9c5c3a8c6a22 | 官方: 是 | 付费: 否
答案:
答案我会先看执行计划(Execution Plan)定位瓶颈(全表扫、回表(Table Lookup)、排序、临时表、锁等待),再针对性优化:建立/调整索引(复合索引顺序、覆盖索引)、减少不必要列与 JOIN(连接)、改写子查询(Subquery)、避免函数包裹索引列、分页用合适策略(seek/游标),并配合缓存(Cache)、分区(Partitioning)与读写分离。高并发场景还要关注事务范围、隔离级别(Isolation Level)与慢查询治理。
633. 你如何处理数据库备份和灾难恢复(Disaster Recovery)?
- 知识点: 数据库 / 行为与软技能 (主题: databases, reliability, dr;标签: Backup, RPO, RTO, PITR, DR)
- 类型: behavioral | 难度: hard | 子类型:
- 分类: fullstack
- id: 69773029a39c9c5c3a8c7445 | 官方: 是 | 付费: 否
答案:
答案我会定义 RPO(恢复点目标,Recovery Point Objective)/RTO(恢复时间目标,Recovery Time Objective)目标后设计备份策略:全量+增量/差异备份,配合 binlog/WAL(预写日志,Write-Ahead Logging)做时间点恢复;备份要加密、跨区域存储并做权限隔离。关键是定期演练恢复(restore drill)验证可用性,监控备份链路与失败告警;在关键系统上还会做主从复制(Master-Slave Replication)、跨区容灾与故障切换流程,确保真正可恢复而不是“只有备份文件”。
634. 你如何处理高需求环境中的数据库可扩展性(Scalability)?
- 知识点: 数据库 / 系统设计/架构 / 行为与软技能 (主题: databases, scaling, architecture;标签: Sharding, Read Replica, Caching, Hotspot)
- 类型: behavioral | 难度: hard | 子类型:
- 分类: fullstack
- id: 6977302fa39c9c5c3a8c7bc3 | 官方: 是 | 付费: 否
答案:
答案我会先区分读扩展与写扩展:读多可用只读副本与缓存(Cache);写压力大可用分片(Sharding)(按用户/时间/范围)、分区表(Partitioned Table)、CQRS(命令查询职责分离,Command Query Responsibility Segregation)/异步化与队列削峰。还会优化热点(热点键拆分、限流)、选择合适索引与查询策略,并用连接池(Connection Pool)、批量写入降低开销。架构层面需要清晰的一致性与事务边界,避免分布式事务(Distributed Transaction)失控。
635. 什么是并发控制(Concurrency Control)?
- 知识点: 数据库 / 操作系统与网络 (主题: databases, transactions, concurrency;标签: Concurrency Control, Locks, MVCC, Isolation)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 6977336da39c9c5c3a8da706 | 官方: 是 | 付费: 否
答案:
答案并发控制是 DBMS(Database Management System)在多个事务(Transaction)同时执行时,协调它们对数据的读写,避免冲突并保证数据一致性与隔离性。常见问题包括读-写冲突与写-写冲突,可能引发脏读(Dirty Read)、不可重复读(Non-repeatable Read)、幻读(Phantom Read)等现象。常用机制有锁(共享锁/排他锁、两段锁 2PL(Two-Phase Locking))、MVCC(Multi-Version Concurrency Control)、多版本快照(Snapshot)与隔离级别控制;目标是在一致性与并发性能之间取得平衡。
636. 什么是不一致依赖(Inconsistent dependency)?
- 知识点: 数据库 (主题: databases, data-quality;标签: dependency, data-quality)
- 类型: technical | 难度: hard | 子类型:
- 分类: fullstack
- id: 697825c0a39c9c5c3ab58c74 | 官方: 是 | 付费: 否
答案:
答案(面试中更常见的说法是数据依赖不一致/依赖链断裂)不一致依赖指由于依赖路径缺失、关系定义不完整或数据约束被破坏,导致无法可靠地获取所需数据或产生矛盾结果。实践中可通过完善外键(Foreign Key)/约束、统一数据源、修复 ETL(Extract, Transform, Load)依赖、以及数据质量校验来降低此类问题。
637. Design a podcast search engine with transcript and metadata capabilities.
设计一个支持转录和元数据功能的播客搜索引擎。
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 / 行为与软技能 (主题: system-design, distributed-systems, databases;标签: Atlassian System Design)
- 类型: technical | 难度: hard | 子类型: system-design
- 分类: fullstack
- 公司: Atlassian
- id: 6979de50c8f1f94b6462c74c | 官方: 是 | 付费: 否
答案:
设计要点:搭建采集/入库流水线(音频+元数据)→ASR(Automatic Speech Recognition)生成转写→清洗规范化→把转写与元数据分别存储并写入搜索索引(如 ES(Elasticsearch)/OpenSearch)。提供全文检索+元数据过滤+排序(相关性/新鲜度),并补齐缓存(Cache)、分片(Sharding)、权限、监控与回溯重建机制。
638. How would you design a database for a ride-sharing app?
你会如何为拼车应用设计数据库?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 / 行为与软技能 (主题: system-design, distributed-systems, databases;标签: Atlassian System Design)
- 类型: technical | 难度: hard | 子类型: system-design
- 分类: fullstack
- 公司: Atlassian
- id: 6979de50c8f1f94b6462c74f | 官方: 是 | 付费: 否
答案:
区分业务库与分析库:OLTP(Online Transaction Processing)侧追求低延迟与高写入,事件尽量不可变,按地区/城市分区(可选 NoSQL(Not Only SQL)/分片)。分析侧用星型模型(Star Schema):事实表(订单/支付/行程)+维度表(用户/司机/地点/时间),并做区域化与冷热分层优化成本与查询性能。
639. Design a database schema for a blogging platform.
为博客平台设计数据库架构。
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 / 行为与软技能 (主题: system-design, distributed-systems, databases;标签: Atlassian System Design)
- 类型: technical | 难度: hard | 子类型: system-design
- 分类: fullstack
- 公司: Atlassian
- id: 6979de50c8f1f94b6462c752 | 官方: 是 | 付费: 否
答案:
基础表:users、posts、comments、tags、post_tags(多对多)以及 engagement/metrics。建立 PK(Primary Key)/FK(Foreign Key)关系与约束(如作者入职/注册时间应早于首篇文章时间),对常用查询字段建索引;必要时用枚举约束标签/状态值。
640. How would you build an ETL pipeline to get Stripe payment data into the database?
你会如何构建 ETL 管道,将 Stripe 支付数据导入数据库?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 / 行为与软技能 (主题: system-design, distributed-systems, databases;标签: Atlassian System Design)
- 类型: technical | 难度: hard | 子类型: system-design
- 分类: fullstack
- 公司: Atlassian
- id: 6979de50c8f1f94b6462c755 | 官方: 是 | 付费: 否
答案:
Extract:通过 Stripe API(Application Programming Interface)/Webhook 拉取并处理鉴权与限流;Transform:清洗、去重、标准化并映射到数仓(Data Warehouse)schema;Load:按批或流式写入。用 Airflow/Glue 编排,加入幂等、重试、断点续跑与监控告警。
641. How would you build a database for a consumer file storage company like Dropbox?
你会如何为像 Dropbox 这样的消费级文件存储公司构建数据库?
- 知识点: 数据库 / 系统设计/架构 / UI/UX 设计 / 行为与软技能 (主题: system-design, distributed-systems, databases;标签: Atlassian System Design)
- 类型: technical | 难度: hard | 子类型: system-design
- 分类: fullstack
- 公司: Atlassian
- id: 6979de50c8f1f94b6462c758 | 官方: 是 | 付费: 否
答案:
元数据用关系库(文件/目录/权限/版本/时间戳),文件内容放对象存储(如 S3(Simple Storage Service))。版本管理可采用不可变对象+版本号/内容哈希,维护变更历史与审计;同步侧用 change log/事件流支持增量同步,并设计冲突解决策略。
642. How do you represent comments in Oracle?
你如何在 Oracle 中表示评论?
- 知识点: 数据库 (主题: application-support;标签: interviewbit, application-support, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b3793d58d557c902b99349 | 官方: 否 | 付费: 否
答案:
In a SQL statement, a comment can be inserted between keywords, parameters, or punctuation marks. To add a comment to your SQL statement in Oracle/PLSQL, you have two options. - Single Line comment (--): In your SQL statement, you can begin the comment with two hyphens (--) at the end of the line and proceed with the comment text. Comment text cannot go beyond one line. The comment must be terminated with a line break.Syntax:
在SQL语句中,注释可以插入在关键字、参数或标点符号之间。要在Oracle/PLSQL中为你的SQL语句添加注释,你有两种选择。- 单行注释(--):在你的SQL语句中,你可以在行末用两个连字符(--)开始注释,并继续输入注释文本。注释文本不能超过一行。注释必须用换行符终止。语法:
-- CommentText - Multi-line comment (/ /): In your SQL statement, you can begin the comment with a slash and an asterisk (/) at the end of the line and proceed with the comment text. Comment text may span multiple lines, i.e., it can go beyond one line. The comment must be terminated with an asterisk and a slash (/). There is no need to separate the opening and closing characters with a space or a line break.Syntax:
-- 注释文本 - 多行注释(/ /):在你的SQL语句中,你可以在行末用斜杠和星号(/)开始注释,并继续输入注释文本。注释文本可以跨越多行,即它可以超过一行。注释必须用星号和斜杠(/)终止。无需用空格或换行符分隔开始和结束字符。语法:
/* Comment text
/* 注释文本
... */
643. What do you mean by SQL join statements?
SQL联接语句是什么意思?
- 知识点: 数据库 (主题: application-support;标签: interviewbit, application-support, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b3793d58d557c902b9934f | 官方: 否 | 付费: 否
答案:
In SQL, join statements combine data from multiple tables based on a common field between them. Any time there are two or more tables listed in a SQL statement, a SQL JOIN is performed. Among the different types of joins are: - INNER JOIN: It will return records that have the same value in both tables. In this case, it would return records where table1 and table2 intersect. Below is a visual representation of the same.
在SQL中,联接语句基于表之间的共同字段将多个表的数据组合在一起。只要SQL语句中列出两个或更多表,就会执行SQL JOIN。不同类型的联接包括:- INNER JOIN:它将返回两个表中具有相同值的记录。在这种情况下,它将返回table1和table2相交的记录。以下是其视觉表示。
- LEFT (Outer) JOIN: It will return all records from the left-hand table, along with matched records from the right-hand table. It would return all records from table1 (left-hand table) and only those records from table2 (right-hand table) that intersect with table1. Below is a visual representation of the same.
- RIGHT (Outer) JOIN: It will return all records from the right-hand table, along with matched records from the left-hand table. It would return all records from table2 (right-hand table) and only those records from table1 (left-hand table) that intersect with table2. Below is a visual representation of the same.
- FULL (Outer) JOIN: It will return all records from both left-hand and right-hand tables. It would return all rows from both the left-hand table (table1) and right-hand table (table2) with NULL values in place wherever the join condition is not satisfied. Below is a visual representation of the same.
644. In the CommServe database, how are keys stored?
在 CommServe 数据库中,密钥是如何存储的?
- 知识点: 数据库 (标签: interviewbit, commvault, company-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: general
- 公司: Commvault
- id: 69b37a4d58d557c902ba50f8 | 官方: 否 | 付费: 否
答案:
Data encryption keys are encrypted with the client's RSA public key and stored in the database. Depending on the settings, the client's RSA private key is encrypted with either a built-in passphrase or a passphrase provided by the user.
数据加密密钥使用客户端的 RSA 公钥加密后存储在数据库中。根据设置,客户端的 RSA 私钥使用内置口令或用户提供的口令加密。
645. What events are triggered during a Deduplication Database (DDB) backup process?
在重复数据删除数据库(DDB)备份过程中会触发哪些事件?
- 知识点: 数据库 (标签: interviewbit, commvault, company-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: general
- 公司: Commvault
- id: 69b37a4d58d557c902ba510b | 官方: 否 | 付费: 否
答案:
The following events occur when the DDB backup job starts: - For a few seconds, all communication with the active DDB is halted. To ensure that the DDB is in a dormant stage, the information in memory is committed to memory.
当DDB备份作业启动时,会发生以下事件: - 在几秒钟内,与活动DDB的所有通信都会暂停。为确保DDB处于休眠阶段,内存中的信息会被提交到内存中。
- The DDB process uses VSS (Windows) or LVM (Linux) snapshots to make a snapshot of the volume.
- The file systems Extended 3 File System (ext3) and VERITAS Volume Manager (VxVM) are also supported on the Linux platform.
- All communication with the DDB is resumed when the snapshot is created, and the DDB is automatically backed up from that snapshot.
- If a VSS (Windows) or LVM (Linux) snapshot fails, the DDB backup falls back on a live volume backup.
- The snapshot is erased after a successful DDB backup. The Job Controller displays the DDB Backup job in a running condition at this point.
- If the DDB MediaAgent restarts during a DDB backup job, the job is marked as Pending. The DDB backup job resumes from the beginning after the restart.
- The DDB backup jobs for the auxiliary copy operation are disabled by default, and these jobs appear as unavailable when viewed from the primary copy.
- Allowing DDB Backup Tasks from Being Copied to Secondary Copy describes how to enable or prohibit DDB backup jobs from being copied to secondary copy during the auxiliary copy procedure.
646. Why do you think database testing is important in the field of software testing?
你认为在软件测试领域中,数据库测试为什么重要?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60d3 | 官方: 否 | 付费: 否
答案:
Database testing ensures that the data in the database that is received from various sources are correct and as per the business requirements or not. It helps to analyse the risks associated with incorrect data, protect from data losses due to incorrect transactions and also properly check for unauthorized access to the data. In most of the applications, the User Interface is given the most importance while testing to validate the correctness of the data. But in cases where there is a lack of UI or view, it is very much essential to test the quality of the information in the database.
数据库测试确保从各种来源接收的数据库中的数据是正确的,并符合业务需求。它有助于分析与错误数据相关的风险,防止因错误事务导致的数据丢失,并正确检查对数据的未授权访问。在大多数应用程序中,测试时用户界面最受重视以验证数据的正确性。但在缺乏UI或视图的情况下,测试数据库中信息的质量就非常必要。
Consider the example of a banking application where lots of users use it to perform transactions. While testing the database, it is very much important to note the following points: - Does the application store the relevant transaction information and display the data correctly to the correct user?
考虑一个银行应用程序的示例,许多用户用它执行事务。在测试数据库时,非常重要的是要注意以下几点:- 应用程序是否存储相关的事务信息,并将数据正确显示给正确的用户?
- Ensure that information is not lost during the transaction process.
- Ensure that the system doesn’t store partially performed transactions or aborted transactions that are not saved.
Ensure that only authorized users have access to the relevant information.
To perform these validations, it is very much needed to possess the art of data testing or database testing.要执行这些验证,非常需要掌握数据测试或数据库测试的艺术。
647. Write the step-by-step process to test the database?
写出测试数据库的逐步过程?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60d6 | 官方: 否 | 付费: 否
答案:
The process to perform database testing is very similar to the steps that we follow for testing any other applications. Following are the steps that are followed:
执行数据库测试的过程与我们测试其他应用程序所遵循的步骤非常相似。以下是遵循的步骤:
Prepare the test environment and test scripts 2. Run the script 3. Check for the test results 4. Validate the results against the expected results. 5. Report the validation findings to the developers and the stakeholders.
- 准备测试环境和测试脚本 2. 运行脚本 3. 检查测试结果 4. 将结果与预期结果进行验证。 5. 将验证发现报告给开发人员和利益相关者。
648. What is structural database testing?
什么是结构性数据库测试?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60d9 | 官方: 否 | 付费: 否
答案:
This testing involves testing database structures that depend on schema, tables, triggers, functions, procedures and also the servers used for databases. Following are the types of structural testing: - Schema Testing: Here, the exact schema name should map between both front-end and backend. The schema validation is very important because in some cases, the schema of the tables would be different from the actual business requirement and the front-end applications. This also involves verifying unmapped tables or views or columns.
这种测试涉及测试依赖模式、表、触发器、函数、过程以及用于数据库的服务器等数据库结构。以下是结构性测试的类型:- 模式测试:在此,精确的模式名称应该在前端和后端之间映射。模式验证非常重要,因为在某些情况下,表的模式会与实际业务需求以及前端应用程序不同。这也涉及验证未映射的表、视图或列。
- Tables Testing: This testing involves testing table names and testing columns. The names mapped to frontend and backend should be the same and the datatype and sizes of the columns should be as per the requirements specified by the business. It also involves testing constraints applied to the tables and columns. Furthermore, testing of indexes based on the property of clustered or non-clustered and their functionality should also be tested accordingly.
Procedure and Function Testing: Here, the testers have to test the procedures and functions available in the database and validate for the list of points below:
Did the team follow the business requirements correctly? Is the code following good practices and proper naming conventions? Are the parameters for input and output of these as per the expected requirements? Are the exceptions handled? Are the procedures and functions inserting data to required tables properly? Are the procedures and functions updating/modifying data in the required tables properly? - Trigger testing: The testing rules are similar to the procedure or functional testing. In addition to those rules, we have to check if the triggers are getting triggered/executed at required instants.团队是否正确遵循了业务需求?代码是否遵循良好实践和适当的命名约定?这些过程的输入和输出参数是否符合预期要求?是否处理了异常?过程和函数是否正确地插入数据到所需表中?过程和函数是否正确更新/修改所需表中的数据?- 触发器测试:测试规则类似于过程或功能测试。除了这些规则,我们还必须检查触发器在所需时刻是否被触发/执行。
- Database Server Testing: Test whether the database configurations, RAM, capacity of processors, storage capacity etc based on the business requirements.
649. How do you test the database triggers and procedures?
如何测试数据库触发器和过程?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60dc | 官方: 否 | 付费: 否
答案:
For testing the database triggers and procedures, it is required to know the input parameters to these functionalities and know what would be the expected output for these. The EXEC statement can be used for determining the behaviour of the tables when the procedures or triggers are run.
为了测试数据库触发器和存储过程,需要了解这些功能的输入参数,并知道预期的输出结果。可以使用 EXEC 语句来确定在运行过程或触发器时表的行为。
You can also achieve this by creating SQL unit tests for checking the database objects modified due to the execution of the triggers or procedures. The SQL unit tests follow the 3 rules as shown below:
你也可以通过创建 SQL 单元测试来检查因执行触发器或过程而修改的数据库对象。SQL 单元测试遵循以下 3 条规则:
The test case should check whether the objects exist in the database or not. It should check or validate what the normal outputs would be for success scenarios. It should also check for the behaviour of the system under the influence of negative test cases.
测试用例应检查对象是否存在于数据库中。它应检查或验证成功场景下的正常输出。它还应检查系统在负面测试用例影响下的行为。
650. What are the possible test scenarios that need to be tested when a database gets migrated from one SQL server to another?
当数据库从一个 SQL 服务器迁移到另一个时,需要测试哪些可能的测试场景?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60df | 官方: 否 | 付费: 否
答案:
Firstly, when migration happens, we need to be aware of all the changes and enhancements are done in the new SQL server. Based on this information, design your test case suite by considering the following points: - What is the data type used?
首先,当迁移发生时,我们需要了解新 SQL 服务器中完成的所有更改和增强功能。基于此信息,通过考虑以下要点来设计测试用例套件: - 使用了什么数据类型?
- What is the length of the fields used in the server?
- Are the database objects created as expected in the new SQL server?
- Perform stress testing on the new SQL server to identify any risks associated with the migrated environment.
651. Why are SQL constraints used in a database?
为什么在数据库中使用 SQL 约束?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60e2 | 官方: 否 | 付费: 否
答案:
SQL Constraints are used for setting the rules for the records in the database table. If any constraints are not satisfied, then the action can be aborted. The constraints are defined when we create the database objects. It can also be altered by using the ALTER commands. SQL has 6 major constraints, they are:
SQL 约束用于设置数据库表中记录。如果任何约束未满足,则操作可能会被中止。约束是在创建数据库对象时定义的。也可以使用 ALTER 命令进行更改。SQL 有 6 种主要约束,它们是:
NOT NULL: This constraint is used for specifying that a column cannot have NULL values. 2. UNIQUE: This constraint specifies that each column has a unique value, meaning the values are not repeated. 3. PRIMARY KEY: This constraint also combines NOT NULL and UNIQUE constraints and indicates that one or more combinations having this key is used for uniquely identifying a record in the database table. 4. FOREIGN KEY: It is used for ensuring the referential integrity of that record in the database table. It matches the value of a column in one table with the value defined as the primary key in the other table. 5. CHECK: It is used for ensuring whether the column values fulfil given specified conditions. 6. DEFAULT: This constraint is used for adding default values to the column whenever needed. If the user specifies any value in the DEFAULT constraint, then at the time of record creation, if we do not specify values to that column, the default value will be saved in the table.
- NOT NULL:此约束用于指定列不能具有 NULL 值。 2. UNIQUE:此约束指定每列具有唯一值,即值不重复。 3. PRIMARY KEY:此约束还结合了 NOT NULL 和 UNIQUE 约束,并指示具有此键的一个或多个组合用于唯一标识数据库表中的记录。 4. FOREIGN KEY:它用于确保数据库表中该记录的引用完整性。它将一个表中的列值与另一个表中定义为主键的值进行匹配。 5. CHECK:它用于确保列值满足给定的指定条件。 6. DEFAULT:此约束用于在需要时向列添加默认值。如果用户在 DEFAULT 约束中指定了任何值,则在记录创建时,如果我们没有为该列指定值,默认值将保存在表中。
652. How will you perform data load testing?
你将如何执行数据加载测试?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60e5 | 官方: 否 | 付费: 否
答案:
Data load testing requires the testers to know about source databases and the destination databases and their objects like tables, columns, design, constraints etc. While performing tests, we need to validate the compatibility of the source and destination databases using the DTS package in SQL Enterprise Manager. We can follow the below steps for the same: - Open the DTS package and run it.
数据加载测试要求测试人员了解源数据库和目标数据库及其对象,如表、列、设计、约束等。在执行测试时,我们需要使用 SQL 企业管理器中的 DTS 包来验证源数据库和目标数据库的兼容性。我们可以按照以下步骤进行: - 打开 DTS 包并运行它。
- Compare the column data of the source and destination tables.
- Check for the number of rows in source and destination tables.
- Post updating data in source tables, check if the same changes are reflected in the destination database.
- Check about the data quality whether the destination data received any junk characters and NULL values.
- Check for the maximum processable volume on the servers and evaluate the response times and speed of data load from the source to destination.
653. How can you test Transactions in SQL Databases?
如何在 SQL 数据库中测试事务?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60e8 | 官方: 否 | 付费: 否
答案:
Transactions require the ACID properties to be satisfied. To achieve that, we use the below statements:
事务需要满足 ACID 属性。为了实现这一点,我们使用以下语句:
BEGIN TRANSACTION TRANSACTION#
BEGIN TRANSACTION TRANSACTION#
END TRANSACTION TRANSACTION#
END TRANSACTION TRANSACTION#
ROLLBACK TRANSACTION#
ROLLBACK TRANSACTION#
The Rollback command ensures that the database changes are rolled back to the previous stable commit and ensures consistency. Once the transactions are executed, we can make use of SELECT queries to run on the tables where the transaction took place and validate the data.
Rollback 命令确保数据库更改回滚到之前的稳定提交点,并确保一致性。一旦事务执行完成,我们可以使用 SELECT 查询对发生事务的表进行运行并验证数据。
654. How can you validate the ACID properties? Explain with an example.
如何验证ACID属性?请举例说明。
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60eb | 官方: 否 | 付费: 否
答案:
Consider a simple SQL code below:
考虑下面这个简单的SQL代码:
CREATE TABLE ACID_DEMO (X INTEGER, Y INTEGER, CHECK (X + Y = 50));
CREATE TABLE ACID_DEMO (X INTEGER, Y INTEGER, CHECK (X + Y = 50));
We will test for the ACID properties for two columns X and Y. There is also a constraint added on the table that the sum of values in columns X and Y should always be 50. - Atomicity: Here, we test that the transactions done on the table is either successful or failed. No records should be updated if the transactions fail.
我们将测试两列X和Y的ACID属性。表中还添加了一个约束,即列X和Y中的值之和应始终为50。- 原子性:这里,我们测试表上的事务要么成功,要么失败。如果事务失败,不应更新任何记录。
- Consistency: Here, we test that the values in columns X and Y are updated correctly by following the constraint that the sum of these two values is always 50. The insertion or updation should not be allowed if the sum is not equal to 50.
- Isolation: Here, in the presence of multiple transactions, we need to test they are happening in isolation.
- Durability: Here, the test cases should consider that if a transaction has been committed, it should remain even after the incidents of power losses, crashes and errors. If we are using sharded or distributed database applications, rigorous testing needs to be done to ensure the data is not lost.
655. How can you test the data integrity in database testing?
如何在数据库测试中测试数据完整性?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60ee | 官方: 否 | 付费: 否
答案:
Whenever there are different modules in the application that are using the same data and also perform different operations on them, it is very much necessary to have the latest data to be shown everywhere. The most recent value of the data should be used by the systems. This is called Data Integrity. Following image shows 5 characteristics of data following data integrity:
每当应用程序中有不同的模块使用相同的数据并对其执行不同的操作时,非常有必要在处处显示最新数据。系统应使用数据的最新值。这称为数据完整性。下图显示了遵循数据完整性的数据的5个特征:
We can apply the following test cases for testing out the integrity of the data: - Are all the triggers working fine to update the records in the reference tables?
我们可以应用以下测试用例来测试数据的完整性:- 所有触发器是否正常工作,以更新引用表中的记录?
- Are there any invalid data in the columns of each database?
- Insert wrong data into the tables and see how the insertion behaves.
- What would happen if you try to insert the child record before inserting the parent record in the main table?
- Is there any failure if you are trying to delete records referenced by another table?
- Are the replicated servers in sync? The data should not be out of sync in two or more replicated servers as it would defy the intent of replication.
656. What are the most commonly occurring issues that are faced during database testing and how can they be solved?
在数据库测试过程中遇到的最常见问题是什么,以及如何解决它们?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60f1 | 官方: 否 | 付费: 否
答案:
Significant overhead can be involved to determine the state of transactions.
Solution: Plan the process that is efficient in both time and cost. A fine balance needs to be present while managing the quality of the database testing and the application project duration.解决方案:规划在时间和成本上都高效的流程。在管理数据库测试质量和应用程序项目工期之间需要保持良好平衡。
Post the clean up of old test data, testers need to come up with a design of new data.
Solution: Plan a methodology and design test cases that can easily take up different data sets without much effort.解决方案:规划方法论并设计测试用例,以便轻松处理不同的数据集,无需太多努力。
To validate the SQL queries, there is a need for an SQL generator that can help to validate the data and can easily help in handling different test cases. This maintenance, if not done correctly, can result in messy and unmanageable scenarios.
Solution: Overall process of testing should be well planned and the queries should be well maintained in a way that continuous updates are supported.解决方案:整体测试过程应经过良好规划,查询应良好维护,以便支持持续更新。
657. What are the best practices that need to be followed while performing database testing?
在执行数据库测试时需要遵循的最佳实践是什么?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60f5 | 官方: 否 | 付费: 否
答案:
Following are some good practices that need to be followed while performing database testing: - Validate every single piece of data that includes metadata and functional data based on the requirement specifications.
以下是在执行数据库测试时需要遵循的一些良好实践:- 根据需求规格说明,验证每一块数据,包括元数据和功能数据。
- Test data should be verified and created after consultation with the development team and only then the validation needs to be done.
- Output data needs to be validated by using both automated and manual processes.
- Perform boundary value analysis, graphing techniques, equivalence partitioning techniques to get the required test data inputs.
- The referential integrity of the data in the tables also needs to be carefully evaluated.
- The selection of default values in the table needs to be validated too to check for consistency of data.
- Check if appropriate logging events have been tracked and added to the database.
- Are the jobs scheduled to run are executed on time?
- Ensure that timely backup of the test database is taken to ensure test cases do not fail.
- Ensure that the test server is periodically refreshed with close to real-time data so that testing can be as accurate as possible.
658. How can you validate the tables and columns in the database?
如何验证数据库中的表和列?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60f8 | 官方: 否 | 付费: 否
答案:
We can test the tables and columns in the databases by applying the following test cases: - Are the database fields mapped correctly and is compatible with the required mappings in the front-end or backend requirements?
我们可以通过应用以下测试用例来测试数据库中的表和列:- 数据库字段是否正确映射,并与前端或后端需求中所需的映射兼容?
- Are the fields following proper naming conventions and have lengths and sizes as per the requirements?
- Check if there are any unused or unmapped tables and columns.
- Check if the table design and the referential integrities and constraints on the columns are applied effectively and are scalable to different requirements.
659. How do you check for an error in a stored procedure consisting of 1000s of lines of code?
如何检查包含数千行代码的存储过程中的错误?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60fb | 官方: 否 | 付费: 否
答案:
We can test using the following methods: - At compilation time, check if there are any compile-time errors.
我们可以使用以下方法进行测试:- 在编译时,检查是否存在任何编译时错误。
- Add proper comments and loggers that would give you hints about the stages completed and help you narrow down the region of error.
660. Is it possible to have multiple primary keys in a table?
一个表中可以有多个主键吗?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba60fe | 官方: 否 | 付费: 否
答案:
No. A table can allow one composite primary key that consists of two or more columns. But it does not allow for multiple primary keys.
不可以。一个表允许有一个由两列或多列组成的复合主键,但不允许多个主键。
661. How will you fetch the values from TableA that are not present in TableB without using the NOT keyword?
在不使用 NOT 关键字的情况下,如何从 TableA 中获取 TableB 中不存在的值?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba6101 | 官方: 否 | 付费: 否
答案:
| TableA |
|---|
| 20 |
| 21 |
| 25 |
| 45 |
| TableA |
|---|
| 20 |
| 21 |
| 25 |
| 45 |
| TableB |
|---|
| 20 |
| 45 |
| TableB |
|---|
| 20 |
| 45 |
The result should have 21 and 25.
结果应包含 21 和 25。
We can do it easily by using the SELECT and EXCEPT keywords as shown below:
我们可以通过使用 SELECT 和 EXCEPT 关键字轻松实现,如下所示:
SELECT FROM TableA EXCEPT SELECT FROM TableB;
SELECT FROM TableA EXCEPT SELECT FROM TableB;
662. What are the differences between GUI Testing and Database Testing?
GUI 测试和数据库测试之间有什么区别?
- 知识点: 数据库 / 测试 (主题: database-testing;标签: interviewbit, database-testing, topic-specific)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6158d557c902ba6104 | 官方: 否 | 付费: 否
答案:
| GUI Testing GUI 测试 | Database Testing 数据库测试 |
|---|---|
| User Interface Testing is also known as Front-end Testing. 用户界面测试也称为前端测试。 | Backend Testing or also known as data testing. 后端测试,也称为数据测试。 |
| Tests all testable items that are visible to the user in the application such as forms, buttons, menus etc. 测试应用程序中用户可见的所有可测试项,如表单、按钮、菜单等。 | Tests all testable items that are not visible to the users but are essential for the proper functioning of the system. 测试用户不可见但系统正常运作所必需的所有可测试项。 |
| Tester need not know SQL. 测试人员无需了解 SQL。 | Tester needs to know the database technologies like SQL to run the queries and validate the data. 测试人员需要了解数据库技术,如 SQL,以运行查询和验证数据。 |
| Majorly deals with the look and feel of the software application. 主要处理软件应用程序的外观和感觉。 | Mostly deals with the data integrity, validation of schema of the structures where the data resides, validating data duplication, referential integrity and everything that deals with data. 主要处理数据完整性、数据存储结构的模式验证、数据重复验证、引用完整性以及与数据相关的一切。 |
| Some of the tools that we use for GUI testing are: Katalon Studio, RAPISE by Inflectra, TestComplete, Abbot Java GUI Test Framework, AutoIt UI testing 我们用于 GUI 测试的一些工具包括:Katalon Studio、Inflectra 的 RAPISE、TestComplete、Abbot Java GUI 测试框架、AutoIt UI 测试 | Some of the tools are Database Rider, Db stress, DbUnit, DB Test Driven etc 一些工具包括 Database Rider、Db stress、DbUnit、DB Test Driven 等 |
Conclusion
结论
The need for correct data has grown exponentially in the software development field. It is very crucial to use the right data, perform the right set of operations on it and show the results to the right set of people. Due to this, database testing helps to validate the correctness, integrity and truthfulness of the data. In this article, we have seen the most commonly asked questions in database testing that deals with RDBMS database systems to both freshers and experienced people.
在软件开发领域,对正确数据的需求呈指数级增长。使用正确的数据、对其执行正确的操作并展示给正确的人员至关重要。因此,数据库测试有助于验证数据的正确性、完整性和真实性。在本文中,我们看到了数据库测试中最常见的问题,这些问题涉及 RDBMS 数据库系统,适用于新手和有经验的人员。
Useful Resources: - DBMS Interview
有用资源:- DBMS 面试
- SQL Interview
- MYSQL Interview
- Selenium Tester Interview Questions
- Automation Testing
- Manual Testing Interview
- Database Testing
- DBMS Tutorial
- Technical Interview Questions
663. Explain the difference between a 2-tier and 3-tier architecture in a DBMS.
解释 DBMS 中二层架构和三层架构的区别。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: system-design
- 分类: fullstack
- id: 69b37a6b58d557c902ba6732 | 官方: 否 | 付费: 否
答案:
The 2-tier architecture refers to the client-server architecture in which applications at the client end directly communicate with the database at the server end without any middleware involved. Example – Contact Management System created using MS-Access or Railway Reservation System, etc.
二层架构指的是客户端-服务器架构,其中客户端端的应用程序直接与服务器端的数据库通信,无需任何中间件参与。例如——使用 MS-Access 创建的联系人管理系统或铁路订票系统等。
The above picture represents a 2-tier architecture in a DBMS.
上述图片展示了 DBMS 中的二层架构。
The 3-tier architecture contains another layer between the client and the server to provide GUI to the users and make the system much more secure and accessible. In this type of architecture, the application present on the client end interacts with an application on the server end which further communicates with the database system.
三层架构在客户端和服务器之间增加了另一层,以向用户提供图形用户界面(GUI),并使系统更加安全和易于访问。在这种架构中,客户端端的应用程序与服务器端的应用程序交互,后者再进一步与数据库系统通信。
Example – Designing registration form which contains a text box, label, button or a large website on the Internet, etc.
例如——设计包含文本框、标签、按钮的注册表单或互联网上的大型网站等。
The above picture represents a 3-tier architecture in a DBMS.
上述图片展示了 DBMS 中的三层架构。
Recommended Tutorials: - DBMS MCQ with Answers
推荐教程:- DBMS 选择题及答案
- DBMS Architecture
- Top Applications of DBMS
- SQL Interview Questions
- SQL Server Interview Questions
- SQL Queries Interview Questions
- MySQL Interview Questions
- MongoDB Interview Questions
- PL SQL Interview Questions
- Database Testing Interview Questions
- File System vs DBMS
- Interview Preparation Guide
664. Explain different types of keys in a database.
解释数据库中不同类型的键。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6735 | 官方: 否 | 付费: 否
答案:
There are mainly 7 types of keys in a database: - Candidate Key: The candidate key represents a set of properties that can uniquely identify a table. Each table may have multiple candidate keys. One key amongst all candidate keys can be chosen as a primary key. In the below example since studentId and firstName can be considered as a Candidate Key since they can uniquely identify every tuple.
数据库中的键主要分为 7 种类型:- 候选键:候选键表示一组可以唯一标识表的属性。每个表可能有多个候选键。在所有候选键中,可以选择一个键作为主键。在下面的示例中,由于 studentId 和 firstName 可以唯一标识每个元组,因此可以视为候选键。
- Super Key: The super key defines a set of attributes that can uniquely identify a tuple. Candidate key and primary key are subsets of the super key, in other words, the super key is their superset.
- Primary Key: The primary key defines a set of attributes that are used to uniquely identify every tuple. In the below example studentId and firstName are candidate keys and any one of them can be chosen as a Primary Key. In the given example studentId is chosen as the primary key for the student table.
- Unique Key: The unique key is very similar to the primary key except that primary keys don’t allow NULL values in the column but unique keys allow them. So essentially unique keys are primary keys with NULL values.
- Alternate Key: All the candidate keys which are not chosen as primary keys are considered as alternate Keys. In the below example, firstname and lastname are alternate keys in the database.
- Foreign Key: The foreign key defines an attribute that can only take the values present in one table common to the attribute present in another table. In the below example courseId from the Student table is a foreign key to the Course table, as both, the tables contain courseId as one of their attributes.
- Composite Key: A composite key refers to a combination of two or more columns that can uniquely identify each tuple in a table. In the below example the studentId and firstname can be grouped to uniquely identify every tuple in the table.
665. Explain different types of Normalization forms in a DBMS.
解释 DBMS 中不同类型的规范化形式。
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6738 | 官方: 否 | 付费: 否
答案:
Following are the major normalization forms in a DBMS:
以下是 DBMS 中的主要规范化形式:
Considering the above Table-1 as the reference example for understanding different normalization forms. - 1NF: It is known as the first normal form and is the simplest type of normalization that you can implement in a database. A table to be in its first normal form should satisfy the following conditions:
将上述表-1 作为理解不同规范化形式的参考示例。 - 1NF:这被称为第一范式,是您可以在数据库中实现的最简单的规范化类型。表中的每个列必须满足以下条件才能处于第一范式:
Every column must have a single value and should be atomic. Duplicate columns from the same table should be removed. Separate tables should be created for each group of related data and each row should be identified with a unique column.
每一列必须具有单一值,并且应为原子值。应从同一表中删除重复的列。应为每组相关数据创建单独的表,并且每一行应通过唯一的列进行标识。
Table-1 converted to 1NF form - 2NF: It is known as the second normal form. A table to be in its second normal form should satisfy the following conditions:
表1转换为1NF形式 - 2NF:它被称为第二范式。一个表要满足第二范式,应符合以下条件:
The table should be in its 1NF i.e. satisfy all the conditions of 1NF. Every non-prime attribute of the table should be fully functionally dependent on the primary key i.e. every non-key attribute should be dependent on the primary key in such a way that if any key element is deleted then even the non_key element will be saved in the database.
该表应处于1NF,即满足1NF的所有条件。表中的每个非主属性都应完全函数依赖于主键,即每个非键属性应依赖于主键,使得如果删除任何键元素,非键元素仍能保存在数据库中。
Breaking Table-1 into 2 different tables to move it to 2NF. - 3NF: It is known as the third normal form. A table to be in its third normal form should satisfy the following conditions:
将表1拆分为2个不同的表以将其移动到2NF。 - 3NF:它被称为第三范式。一个表要满足第三范式,应符合以下条件:
The table should be in its 2NF i.e. satisfy all the conditions of 2NF. There is no transitive functional dependency of one attribute on any attribute in the same table.
该表应处于2NF,即满足2NF的所有条件。在同一表中,不存在一个属性对任何其他属性的传递函数依赖。
Breaking Table-1 into 3 different tables to move it to 3NF. - BCNF: BCNF stands for Boyce-Codd Normal Form and is an advanced form of 3NF. It is also referred to as 3.5NF for the same reason. A table to be in its BCNF normal form should satisfy the following conditions:
将表1拆分为3个不同的表以将其移动到3NF。 - BCNF:BCNF代表Boyce-Codd范式,是3NF的高级形式。因此它也被称为3.5NF。一个表要处于BCNF范式,应符合以下条件:
The table should be in its 3NF i.e. satisfy all the conditions of 3NF. For every functional dependency of any attribute A on B(A->B), A should be the super key of the table. It simply implies that A can’t be a non-prime attribute if B is a prime attribute.
该表应处于3NF,即满足3NF的所有条件。对于任何属性A对B(A->B)的每个函数依赖,A应为该表的超键。这简单意味着如果B是主属性,则A不能是非主属性。
DBMS Indexing & Query Optimization
666. What is selectivity/cardinality and why does it matter for indexing?
什么是选择性/基数,为什么它对索引很重要?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba673b | 官方: 否 | 付费: 否
答案:
Selectivity refers to how unique the values in a column are. High selectivity means most values are unique, like user IDs. Low selectivity means many rows share the same value, like status flags. Indexes work best on high-selectivity columns. Indexing low-selectivity columns often gives little benefit. Understanding data distribution helps decide which columns should be indexed.
选择性指的是列中值的唯一程度。高选择性意味着大多数值唯一,如用户ID。低选择性意味着许多行共享相同值,如状态标志。索引在高选择性列上效果最好。对低选择性列建索引往往收益甚微。理解数据分布有助于决定哪些列应该建索引。
667. What is an index and why can indexing slow down INSERT/UPDATE/DELETE?
什么是索引,为什么索引会减慢INSERT/UPDATE/DELETE操作?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba673e | 官方: 否 | 付费: 否
答案:
An index is a data structure that helps the database find rows faster without scanning the full table. It improves read performance by reducing the amount of data searched. However, every time you insert, update, or delete data, the index also needs to be updated. This extra work slows down write operations. The more indexes a table has, the slower writes become. That’s why indexing is always a balance between read speed and write performance.
索引是一种数据结构,帮助数据库更快地查找行,而无需扫描整个表。它通过减少搜索的数据量来提高读性能。然而,每次插入、更新或删除数据时,索引也需要更新。这种额外工作会减慢写操作。表上的索引越多,写入变得越慢。这就是为什么索引始终是读速度和写性能之间的平衡。
668. Difference between clustered and non-clustered index
聚集索引和非聚集索引的区别
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6741 | 官方: 否 | 付费: 否
答案:
A clustered index defines the physical order of data in the table. Because of this, a table can have only one clustered index. Non-clustered indexes store a separate structure that points to the actual rows. They don’t change how data is stored on disk. Clustered indexes are faster for range queries, while non-clustered indexes are better for lookups. Choosing the wrong type can lead to inefficient queries.
聚集索引定义了表中数据的物理顺序。因此,一个表只能有一个聚集索引。非聚集索引存储一个指向实际行的单独结构。它们不改变数据在磁盘上的存储方式。聚集索引在范围查询上更快,而非聚集索引更适合查找操作。选择错误的类型可能导致查询效率低下。
669. When does a query not use an index even if one exists?
什么情况下查询即使存在索引也不会使用它?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6744 | 官方: 否 | 付费: 否
答案:
A query may ignore an index if the optimizer thinks a full table scan is faster. This often happens when a large percentage of rows match the condition. Using functions on indexed columns can also prevent index usage. Mismatched data types or implicit conversions can break index access. Poorly written queries confuse the optimizer. Indexes help only when the query structure allows them to be used.
如果优化器认为全表扫描更快,查询可能会忽略索引。当匹配条件的行占比很大时,这经常发生。对索引列使用函数也会阻止索引的使用。数据类型不匹配或隐式转换会破坏索引访问。编写不良的查询会混淆优化器。只有查询结构允许时,索引才有帮助。
670. What is a composite index and the leftmost prefix rule?
什么是复合索引和最左前缀规则?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6747 | 官方: 否 | 付费: 否
答案:
A composite index is an index created on multiple columns together. The leftmost prefix rule means the index is used only if the query filters starting from the first column. For example, an index on (user_id, order_date) works for queries filtering by user_id, but not only by order_date. Column order matters a lot in composite indexes. Designing them without understanding query patterns leads to wasted indexes. Always match index order with real query usage.
复合索引是在多个列上一起创建的索引。最左前缀规则意味着索引仅在查询从第一列开始过滤时才会被使用。例如,在(user_id,order_date)上的索引适用于按user_id过滤的查询,但不适用于仅按order_date过滤的查询。列顺序在复合索引中非常重要。不理解查询模式而设计索引会导致索引浪费。始终使索引顺序与实际查询使用相匹配。
671. What is a covering index and how does it reduce table lookups?
什么是覆盖索引,它如何减少表查找?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba674a | 官方: 否 | 付费: 否
答案:
A covering index contains all the columns needed by a query. This allows the database to fetch results directly from the index without accessing the table. As a result, fewer disk reads are needed. This significantly improves performance for read-heavy queries. Covering indexes are especially useful for reporting queries. However, they increase index size and slow down writes.
覆盖索引包含查询所需的所有列。这允许数据库直接从索引中获取结果,而无需访问表。因此,所需的磁盘读取次数更少。这显著提升了读密集型查询的性能。覆盖索引对报表查询尤其有用。然而,它们会增加索引大小并减慢写入速度。
672. What is an execution plan and what do you check first?
什么是执行计划,你首先检查什么?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba674d | 官方: 否 | 付费: 否
答案:
An execution plan shows how the database executes a query step by step. It tells you which indexes are used and how tables are accessed. The first thing to check is whether indexes are being used or ignored. Look for full table scans on large tables. Also check estimated vs actual row counts. A bad execution plan usually points to missing or incorrect indexes.
执行计划展示了数据库如何一步步执行查询。它告诉你使用了哪些索引以及表是如何被访问的。首先要检查的是索引是否被使用或被忽略。留意大型表上的全表扫描。同时检查预估行数与实际行数的对比。糟糕的执行计划通常指向缺失或不正确的索引。
673. Index scan vs index seek and when they occur
索引扫描与索引查找及其发生时机
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6750 | 官方: 否 | 付费: 否
答案:
An index seek happens when the database jumps directly to matching rows using the index. This is fast and efficient. An index scan means the database scans a large part or all of the index. Scans happen when many rows match the condition. Seeks usually indicate good indexing and selective filters. Scans are not always bad, but frequent scans on large datasets can hurt performance.
索引查找发生在数据库使用索引直接跳到匹配行时。这快速且高效。索引扫描意味着数据库扫描索引的大部分或全部。当很多行匹配条件时会发生扫描。查找通常表明索引良好且过滤条件具有选择性。扫描不一定总是坏事,但大型数据集上的频繁扫描会损害性能。
674. What is index fragmentation or bloat and its impact?
什么是索引碎片化或膨胀及其影响?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6753 | 官方: 否 | 付费: 否
答案:
Index fragmentation happens when index pages become disorganized over time. This is caused by frequent inserts, updates, and deletes. Fragmented indexes require more disk reads. As a result, query performance slowly degrades. Rebuilding or reorganizing indexes helps fix this. Regular maintenance is important for long-running production systems.
索引碎片化发生在索引页随时间变得混乱时。这由频繁的插入、更新和删除操作引起。碎片化的索引需要更多的磁盘读取。因此,查询性能逐渐下降。重建或重组索引有助于解决此问题。定期维护对于长期运行的生产系统至关重要。
675. Common production reasons for slow queries and debugging flow
生产环境中查询变慢的常见原因及调试流程
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6756 | 官方: 否 | 付费: 否
答案:
Slow queries are often caused by missing indexes, bad joins, or large data growth. Sometimes queries were fast initially but slow down as data increases. The first step is checking query execution time and execution plans. Then look for full scans, high I/O, or blocking locks. Index tuning usually fixes most issues. Performance debugging is about data size, not just SQL syntax.
慢查询通常由缺失索引、错误的连接或数据量大规模增长引起。有时查询初始时很快,但随着数据增加而变慢。第一步是检查查询执行时间和执行计划。然后寻找全扫描、高 I/O 或阻塞锁。索引调优通常能解决大多数问题。性能调试涉及数据规模,而不仅仅是 SQL 语法。
DBMS Security & Governance Interview Question
676. Risk of giving apps superuser DB permissions
给应用超级用户数据库权限的风险
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba6759 | 官方: 否 | 付费: 否
答案:
Superuser access allows full control over the database. If an app is compromised, attackers gain unlimited power. This can lead to data loss or system damage. It also increases the impact of bugs or bad queries. Production apps should never use superuser accounts. Limiting permissions reduces risk significantly.
超级用户访问权限允许对数据库拥有完全控制权。如果应用被攻破,攻击者将获得无限权力。这可能导致数据丢失或系统损坏。它还会增加错误或糟糕查询的影响。生产应用绝不应使用超级用户账户。限制权限能显著降低风险。
677. What is SQL injection and how do parameterized queries prevent it?
什么是 SQL 注入,参数化查询如何防止它?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6b58d557c902ba675c | 官方: 否 | 付费: 否
答案:
SQL injection happens when user input is treated as part of a SQL command. An attacker can modify the query to access or change data. Parameterized queries separate the SQL logic from user input. The database treats inputs only as values, not executable code. This completely blocks injection attacks. It is the safest and most common defense.
SQL 注入发生在用户输入被视为 SQL 命令的一部分时。攻击者可以修改查询以访问或更改数据。参数化查询将 SQL 逻辑与用户输入分离。数据库只将输入视为值,而非可执行代码。这完全阻止了注入攻击。这是最安全且最常见的防御手段。
678. 2. DB authentication vs authorization and roles in practice
- 数据库身份验证与授权及角色在实践中的应用
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba675f | 官方: 否 | 付费: 否
答案:
Authentication checks who you are, usually using a username and password. Authorization decides what actions you are allowed to perform. Roles group permissions like read, write, or admin access. Users are assigned roles instead of individual privileges. This makes access easier to manage and audit. Most production systems rely heavily on role-based access.
身份验证检查你是谁,通常使用用户名和密码。授权决定你被允许执行哪些操作。角色将权限分组,如读、写或管理员访问权限。用户被分配角色而非单独特权。这使得访问更易于管理和审计。大多数生产系统高度依赖基于角色的访问控制。
679. What is row-level security and a real use-case?
什么是行级安全性,以及一个真实用例?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6762 | 官方: 否 | 付费: 否
答案:
Row-level security restricts which rows a user can see in a table. The same query returns different results for different users. A common use-case is multi-tenant systems. Each customer sees only their own data. The logic is enforced by the database itself. This prevents accidental data leaks at the app layer.
行级安全性限制了用户在表中可以看到的行。相同的查询对不同用户返回不同的结果。一个常见的用例是多租户系统。每个客户只能看到自己的数据。这种逻辑由数据库本身强制执行。这防止了应用层的意外数据泄露。
680. Encryption at rest vs encryption in transit
静态加密与传输中加密
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6765 | 官方: 否 | 付费: 否
答案:
Encryption at rest protects data stored on disk. It prevents data theft if disks or backups are accessed. Encryption in transit protects data moving between the app and database. It uses protocols like TLS. Both are required for full security. One does not replace the other.
静态加密保护存储在磁盘上的数据。如果磁盘或备份被访问,它可以防止数据被盗。传输中加密保护在应用和数据库之间移动的数据。它使用TLS等协议。两者都是全面安全所必需的。一个不能替代另一个。
681. How do you store DB credentials safely?
你如何安全地存储数据库凭据?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6768 | 官方: 否 | 付费: 否
答案:
DB credentials should never be hardcoded in source code. They are stored in a secrets manager or secure vault. Applications fetch credentials at runtime. Access is controlled using IAM or service identities. Secrets can be rotated without code changes. This reduces the risk of leaks.
数据库凭据绝不应硬编码在源代码中。它们存储在密钥管理器或安全保险库中。应用程序在运行时获取凭据。访问通过IAM或服务身份进行控制。密钥可以在不更改代码的情况下轮换。这降低了泄露的风险。
682. What does least privilege mean in DB access control?
在数据库访问控制中,最小权限原则意味着什么?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba676b | 官方: 否 | 付费: 否
答案:
Least privilege means giving only the permissions that are strictly required. Applications should not have admin or schema-altering access. Read-only users should not be able to write data. This limits damage if credentials are compromised. It also reduces the chance of human error. Least privilege is a basic security principle.
最小权限原则意味着只授予严格必需的权限。应用程序不应具有管理员或更改架构的访问权限。只读用户不应能够写入数据。这限制了凭据被泄露时的损害。它还减少了人为错误的可能性。最小权限是一个基本的安全原则。
683. What is auditing and what should be logged?
什么是审计,应该记录什么?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba676e | 官方: 否 | 付费: 否
答案:
Auditing tracks important actions performed in the database. This includes logins, permission changes, and schema updates. Sensitive data access is also commonly logged. Audit logs help in security investigations and compliance. They provide visibility into who did what and when. Logs must be protected from tampering.
审计跟踪在数据库中执行的重要操作。这包括登录、权限更改和架构更新。敏感数据访问通常也会被记录。审计日志有助于安全调查和合规性。它们提供了谁在何时做了什么的可见性。日志必须防止被篡改。
684. How do you protect PII data?
你如何保护PII数据?
- 知识点: 数据库 (主题: dbms, database;标签: interviewbit, dbms, topic-specific, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37a6c58d557c902ba6771 | 官方: 否 | 付费: 否
答案:
PII can be protected using masking, tokenization, or encryption. Masking hides parts of the data for non-privileged users. Tokenization replaces sensitive values with safe references. Encryption protects data at rest and in backups. Different techniques are used for different access needs. The goal is minimizing exposure.
PII可以通过掩码、令牌化或加密来保护。掩码为非特权用户隐藏部分数据。令牌化用安全的引用替换敏感值。加密保护静态数据和备份。不同的技术用于不同的访问需求。目标是尽量减少暴露。
685. Explain Tokenizer in ElasticSearch.
解释ElasticSearch中的Tokenizer(分词器)。
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9861 | 官方: 否 | 付费: 否
答案:
When a tokenizer receives a stream of characters (text), it tokenizes them (usually by breaking them up into individual words or tokens), and outputs the stream of words/tokens. Elasticsearch comes with several tokenizers that you can use to build your custom analyzers. A whitespace tokenizer, for example, breaks text into individual tokens whenever it encounters any whitespace. The text "Scaler by InterviewBit!" would be converted into terms or tokens [Scaler, by, InterviewBit].
当分词器接收到一个字符流(文本)时,它会将其分词(通常通过将其拆分为单独的单词或令牌),并输出单词/令牌流。Elasticsearch自带几个分词器,你可以用来构建自定义分析器。例如,空白分词器会在遇到任何空白时将文本拆分为单独的令牌。文本“Scaler by InterviewBit!”会被转换为术语或令牌[Scaler, by, InterviewBit]。
686. What is an Analyzer ElasticSearch?
什么是ElasticSearch中的分析器?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9864 | 官方: 否 | 付费: 否
答案:
When indexing data in ElasticSearch, the data is internally transformed by the Analyzer assigned to the index. In essence, an analyzer indicates how text should be indexed and searched in ElasticSearch. Elasticsearch comes with several ready-to-use analyzers built into it. You can also create custom analyzers by combining the built-in character filters, tokenizers, and token filters. - Character filter: Used to remove unused characters or change some characters.
在ElasticSearch中索引数据时,数据会被分配给索引的分析器内部转换。本质上,分析器指示文本应如何在ElasticSearch中被索引和搜索。Elasticsearch自带几个现成的分析器。你也可以通过组合内置的字符过滤器、分词器和令牌过滤器来创建自定义分析器。- 字符过滤器:用于移除未使用的字符或更改某些字符。
- Tokenizer: Divides or breaks text into tokens (or words) based on some criteria (e.g. whitespace).
- Token filter: The filter receives tokens and applies filters to them (such as changing uppercase terms into lowercase).
687. What is an Inverted index in ElasticSearch?
ElasticSearch中的倒排索引是什么?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9867 | 官方: 否 | 付费: 否
答案:
ElasticSearch utilizes a hashmap-like data structure known as an inverted index that allows for rapid full-text searches. The inverted index lists all the unique words that appear in one or more documents and identifies all the documents those words appear in. With it, you can conduct quick searches across millions of documents to find relevant data.
ElasticSearch利用一种类似哈希映射的数据结构,称为倒排索引,它支持快速的全文搜索。倒排索引列出了一篇或多篇文档中出现的所有唯一单词,并标识出这些单词出现在哪些文档中。借助它,你可以在数百万篇文档中进行快速搜索以找到相关数据。
Example: Let's assume we have two different documents: - Scaler is a good Ed-tech company.
示例:假设我们有两个不同的文档:- Scaler是一家好的教育科技公司。
InterviewBit is one of the good companies.
The above texts have been tokenized first into separate terms for indexing purposes. All the unique terms are then stored in the index, along with information such as which document the term appears in, its position, as well as how many times it appeared. Accordingly, the inverted index is as follows:上述文本首先被分词为单独的术语以便索引。所有唯一术语随后存储在索引中,连同诸如该术语出现在哪个文档、其位置以及出现次数等信息。因此,倒排索引如下:
| Term 术语 | Frequency 频率 | Document 文档 | Document: Position 文档:位置 |
|---|---|---|---|
| Scaler | 1 | 1 | 1:1 |
| is | 2 | 1,2 | 1:2,2:2 |
| a | 1 | 1 | 1:3 |
| good | 2 | 1,2 | 1:4,2:6 |
| Ed-tech | 1 | 1 | 1:5 |
| Company | 1 | 1 | 1:6 |
| InterviewBit | 1 | 2 | 2:1 |
| one | 1 | 2 | 2:3 |
| of | 1 | 2 | 2:4 |
| the | 1 | 2 | 2:5 |
| companies | 1 | 2 | 2:7 |
Let's say you are looking for a term company or companies. With this inverted index, queries can search for terms and quickly identify documents that contain these terms.
假设你在查找术语company或companies。使用这个倒排索引,查询可以搜索术语并快速识别包含这些术语的文档。
688. Describe the functionality of the cat API in ElasticSearch.
描述ElasticSearch中cat API的功能。
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: coding
- 分类: fullstack
- id: 69b37abc58d557c902ba986a | 官方: 否 | 付费: 否
答案:
Elasticsearch API results are usually displayed in JSON format, which is not always easy to read. Human eyes require compact and aligned text, especially when looking at a terminal. In order to meet this need, cat APIs (compact and aligned text APIs) have been developed. Thus, the cat APIs feature offered by Elasticsearch facilitates an easier-to-read and comprehend printing format for Elasticsearch results. Cat APIs return plain text instead of traditional JSON, which is comprehensible by users. You can view the available operations in the cat API by running the following commands:
Elasticsearch API的结果通常以JSON格式显示,这并不总是易于阅读。人眼需要紧凑且对齐的文本,尤其是在查看终端时。为了满足这一需求,cat API(紧凑且对齐的文本API)被开发出来。因此,Elasticsearch提供的cat API功能使得Elasticsearch结果的打印格式更易于阅读和理解。Cat API返回纯文本而非传统的JSON,用户能够理解。你可以通过运行以下命令查看cat API中的可用操作:
GET _cat
GET _cat
Additionally, you may use the following parameters with your query. - Verbose (v?): Gives results in a nice format or more verbose output. Use this parameter to see what each column represents.Syntax:
此外,你可以在查询中使用以下参数。- Verbose(v?):以整洁格式或更详细的输出提供结果。使用此参数查看每列代表什么。语法:
GET _cat/<operation_name>?v - Help (?help): Provides a list of the available headers and columns for a given operation. You can view all available headers by using this parameter.Syntax:
GET _cat/<操作名>?v - Help(?help):提供给定操作的可用标题和列列表。通过此参数可以查看所有可用标题。语法:
GET _cat/<operation_name>?help - Headers (?h): Limit the output to specified headers or columns in the command.Syntax:
GET _cat/<操作名>?help - Headers(?h):将输出限制为命令中指定的标题或列。语法:
GET _cat/<operation_name>?h=<header_name_1>,<header_name_2>&v - Numeri format (?format): Provide different types of numeric output, such as bytes, size, and time value.
GET _cat/<操作名>?h=<标题名_1>,<标题名_2>&v - Numeri格式(?format):提供不同类型的数字输出,如字节、大小和时间值。
- Sort (?sort): Sorts the table by the specified columns as the parameter value.
689. What are the different ElasticSearch commands available in the cat API?
cat API中有哪些不同的ElasticSearch命令?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba986d | 官方: 否 | 付费: 否
答案:
There are different commands available in the Elasticsearch cat API. Here are a few: - Count: Displays the total number of documents in your cluster.
Elasticsearch cat API中有不同的命令。以下是一些:- Count:显示集群中文档的总数。
GET _cat/count?v - Allocation: Displays the disk space allocated to indices and the number of shards per node.
GET _cat/count?v - Allocation:显示分配给索引的磁盘空间以及每个节点的分片数量。
GET _cat/allocation?v - Field data: Shows the memory usage of each field per node.
GET _cat/allocation?v - 字段数据:显示每个节点中各字段的内存使用情况。
GET _cat/fielddata?v - Indices: Displays information about indices, including how much space they take up, how many shards they have, etc.
GET _cat/fielddata?v - 索引:显示索引的信息,包括它们占用多少空间、拥有多少个分片等。
GET _cat/indices?v - Node Attributes: Displays the attributes associated with custom nodes.
GET _cat/indices?v - 节点属性:显示与自定义节点关联的属性。
GET _cat/nodeattrs?v
GET _cat/nodeattrs?v
690. Explain ELK stack and its architecture.
解释ELK栈及其架构。
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: system-design
- 分类: fullstack
- id: 69b37abc58d557c902ba9870 | 官方: 否 | 付费: 否
答案:
The "ELK" acronym refers to three open-source products i.e., Elasticsearch, Logstash, and Kibana, which are all produced, managed, and maintained by Elastic company. With the introduction of Beats, this stack became a four-legged project called BELK or Elastic Stack. - ElasticSearch: Elasticsearch is an open-source, modern, full-text search engine based or built on Apache Lucene. ElasticSearch enables you to store, search, and analyze vast or huge amounts of data in near real-time, providing results in milliseconds.
“ELK”这个缩写指的是三个开源产品,即Elasticsearch、Logstash和Kibana,它们都由Elastic公司生产、管理和维护。随着Beats的引入,这个栈变成了一个名为BELK或Elastic Stack的四组件项目。- ElasticSearch:Elasticsearch是一个基于或构建于Apache Lucene之上的开源、现代、全文搜索引擎。ElasticSearch使您能够以近实时的方式存储、搜索和分析海量数据,并在毫秒内提供结果。
- Logstash: Logstash is a data processing pipeline tool, which collects data from different sources, performs several transformations and enhancements, and then sends the data to stash or wherever you want it to go.
- Kibana: Kibana is a visualization tool built on top of Elasticsearch, enabling users to analyze and view data. The Kibana dashboard lets you visualize complex queries through interactive diagrams, geospatial data, and graphs.
Beats: Beats are lightweight data shipping agents (data shippers) that collect different types of data and forward it to Logstash or ElasticSearch. There are different types of Beats, each focused on a specific type of data, such as metrics, log files, network packets, audit data, Windows events, uptime monitoring data, and cloud data.
These components are typically used in conjunction to monitor, troubleshoot, and secure IT environments. The Beats and Logstash tools handle the collection and processing of data, while Elasticsearch stores and indexes the data, and Kibana provides a graphical UI (user interface) for querying and visualizing the data.这些组件通常结合使用,用于监控、故障排除和保护IT环境。Beats和Logstash工具负责数据的收集和处理,而Elasticsearch则存储和索引数据,Kibana则提供图形化用户界面(UI)用于查询和可视化数据。
691. What configuration management tools does Elasticsearch support?
Elasticsearch支持哪些配置管理工具?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9873 | 官方: 否 | 付费: 否
答案:
Elasticsearch supports the following configuration management tools: - Chef: cookbook-elastic search.
Elasticsearch支持以下配置管理工具:- Chef:cookbook-elastic search。
- Puppet: puppet-elastic search.
- Ansible: ansible-elastic search.
692. Is it necessary to install X-Pack for Elasticsearch? What are some essential X-pack commands?
是否必须为Elasticsearch安装X-Pack?有哪些关键的X-pack命令?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abc58d557c902ba9876 | 官方: 否 | 付费: 否
答案:
Yes, if you are using ElasticSearch, you must install X-Pack. In essence, X-Pack is an Elastic Stack extension that combines or bundles alerting, reporting, monitoring, security, and graph capabilities into a single package that can be installed quickly and easily. Although the components of the X-Pack work seamlessly together, you can enable or disable the features you need. Since X-Pack is an Elastic Stack extension, you will need to install both Elasticsearch and Kibana before installing X-Pack. The version of X-Pack must match Elasticsearch and Kibana versions.
是的,如果您使用ElasticSearch,您必须安装X-Pack。本质上,X-Pack是Elastic Stack的一个扩展,它将告警、报告、监控、安全和图形功能组合或捆绑到一个单一包中,可以快速轻松安装。尽管X-Pack的组件能够无缝协同工作,但您可以根据需要启用或禁用某些功能。由于X-Pack是Elastic Stack的扩展,在安装X-Pack之前,您需要先安装Elasticsearch和Kibana。X-Pack的版本必须与Elasticsearch和Kibana的版本相匹配。
The following are a few X-Pack commands that can help you configure security and perform other tasks: - elasticsearch-certgen
以下是一些可以帮助您配置安全和执行其他任务的X-Pack命令:- elasticsearch-certgen
- elasticsearch-certutil
- elasticsearch-reset-password
- elasticsearch-setup-passwords
- elasticsearch-syskeygen
- elasticsearch-users, etc.
693. What do you mean by aggregation in ElasticSearch?
在ElasticSearch中,聚合是什么意思?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abd58d557c902ba9879 | 官方: 否 | 付费: 否
答案:
Aggregations in Elasticsearch enable you to group data and calculate statistics on your data with a simple search query. In ElasticSearch, aggregations are categorized into three types: - Bucket aggregations: Documents can be grouped into buckets by using bucket aggregations. You can use them to create data buckets or group data. A bucket can be formed based on existing field values, ranges, etc.
Elasticsearch中的聚合使您能够通过简单的搜索查询对数据进行分组并计算统计信息。在ElasticSearch中,聚合分为三种类型:- 桶聚合:通过桶聚合可以将文档分组到桶中。您可以用它们来创建数据桶或对数据进行分组。桶可以基于现有字段值、范围等形成。
- Metric aggregations: This aggregation helps to calculate metrics (such as a sum, or average) based on field values.
- Pipeline aggregations: This type of aggregation takes inputs from the output results of other aggregates rather than individual documents or fields.
694. Does ElasticSearch have a schema?
ElasticSearch是否有模式(schema)?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abd58d557c902ba987c | 官方: 否 | 付费: 否
答案:
Yes, it is possible for ElasticSearch to have a schema. The schema is a description of one or more fields in a document that describe what type of document it is and how different fields of a document are to be handled. In Elasticsearch, a schema describes the fields in JSON documents, their data types, and how they should be indexed in the Lucene indexes. As such, we call this schema a "mapping" in Elasticsearch.ch.
是的,ElasticSearch可以有模式。模式是文档中一个或多个字段的描述,说明文档的类型以及如何处理文档的不同字段。在Elasticsearch中,模式描述了JSON文档中的字段、它们的数据类型以及它们应如何在Lucene索引中被索引。因此,在Elasticsearch中,我们将这种模式称为“映射”(mapping)。
But Elasticsearch can also be schema-less, meaning that documents can be indexed without the need to provide a schema explicitly. If a mapping isn't specified, Elasticsearch will by default generate one when newly added fields are detected during indexing.
但Elasticsearch也可以是无模式的,这意味着文档可以在无需显式提供模式的情况下被索引。如果未指定映射,Elasticsearch在索引期间检测到新添加的字段时,会默认生成一个映射。
695. How can we perform a search in Elasticsearch?
我们如何在Elasticsearch中执行搜索?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abd58d557c902ba987f | 官方: 否 | 付费: 否
答案:
Below are a few ways to perform a search in Elasticsearch: - Applying search API: You can search and aggregate data that is stored in Elasticsearch data streams and indices using the search API.
以下是在Elasticsearch中执行搜索的几种方式:- 应用搜索API:您可以使用搜索API对存储在Elasticsearch数据流和索引中的数据进行搜索和聚合。
- Search using a URI (Uniform Resource Identifier): The search request is executed using a URI (Uniform Resource Identifier) by providing request parameters.
- Request body search: The search request should be executed using DSL (Domain Specific Language) within the body.
696. Explain Query DSL in ElasticSearch.
解释ElasticSearch中的查询DSL。
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abd58d557c902ba9882 | 官方: 否 | 付费: 否
答案:
Elasticsearch generally provides a query Domain Specific Language (DSL) based on JSON to define queries. Query DSL contains two kinds of clauses: - Leaf query clause: A leaf query clause looks for specific values in a field or fields. They can be used independently. Matches, terms, and range queries are some examples of these queries.
Elasticsearch通常提供一种基于JSON的查询领域特定语言(DSL)来定义查询。查询DSL包含两种子句:- 叶子查询子句:叶子查询子句在一个或多个字段中查找特定值。它们可以独立使用。匹配、词项和范围查询是这些查询的一些示例。
Compound query clause: A compound query clause is a combination of a leaf query and other compound queries. These queries combine multiple queries to produce their intended results.
The behaviour of query clauses differs depending on whether it is used in a filter context or a query context.查询子句的行为根据其是在过滤上下文还是查询上下文中使用而有所不同。
697. What types of queries does ElasticSearch support?
ElasticSearch支持哪些类型的查询?
- 知识点: 数据库 (主题: elasticsearch, search;标签: interviewbit, elasticsearch, topic-specific, search)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37abd58d557c902ba9886 | 官方: 否 | 付费: 否
答案:
Elasticsearch supports a wide range of queries. The query begins with a query keyword, which is followed by conditions and filters in the form of a JSON object. Here are a few of the queries: - Match All Query: This is a basic query that retrieves all the documents in the specified index.
Elasticsearch支持广泛的查询类型。查询以查询关键字开头,后跟以JSON对象形式表示的条件和过滤器。以下是几种查询:- 匹配所有查询:这是一种基本查询,用于检索指定索引中的所有文档。
- Full-text queries: There are high-level queries for executing full-text searches over full-text fields. Full-text queries usually work depending on the analyzer associated with a particular document or index. Full-text queries can be of different types, such as match query, multi-match query, query-string query, etc.
Term Level Queries: Instead of full-text field searches, term-level queries deal with structured data like numbers, enums, dates, etc. Term level queries can be of different types, such as range, exists, prefix, wildcard, fuzzy, type, etc.
Conclusion结论
In recent years, it has evolved into one of the most popular search engines that are used for business analytics, log analytics, security intelligence, operational intelligence, full-text searches, etc. Research has shown that Elasticsearch has a market share of about 0.24%, so there is a lot of opportunity for many renowned companies. Thus, you are still able to advance in your career as an ElasticSearch Engineer. Almost every area of ElasticSearch, along with the ELK stack, has been covered in the interview questions, including questions about the analyzers, filters, tokenizers, index, token filters, and APIs used in ElasticSearch.
近年来,它已发展成为最流行的搜索引擎之一,用于业务分析、日志分析、安全情报、运营情报、全文搜索等。研究表明,Elasticsearch的市场份额约为0.24%,因此许多知名公司都有很大的机会。因此,您仍然可以作为一名ElasticSearch工程师在职业生涯中取得进步。面试问题涵盖了ElasticSearch的几乎所有领域,包括ELK堆栈,涉及分析器、过滤器、分词器、索引、词元过滤器和ElasticSearch中使用的API等。
Here, we have compiled a list of insightful interview questions that give ample information vital to the interview process. Being familiar with these frequently asked interview questions increases your chances of getting hired.
这里,我们整理了一份富有洞察力的面试问题列表,为面试过程提供了充分的关键信息。熟悉这些常见面试问题可以增加您被聘用的机会。
Hopefully, we have answered any questions or concerns that you may have had. All the best with your future endeavours.
希望我们已经回答了您可能拥有的任何问题或疑虑。祝您未来的努力一切顺利。
Additional Interview Preparation Resources
其他面试准备资源
- AWS Interview Questions
- SQL Interview Questions
- REST API Interview Questions
- Other Technical Interview Questions
698. What do you mean by Transactions?
你所说的“事务”是什么意思?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37bd558d557c902bb4d0f | 官方: 否 | 付费: 否
答案:
A transaction is a logical unit of processing in a database that includes one or more database operations, which can be read or write operations. Transactions provide a useful feature in MongoDB to ensure consistency. MongoDB provides two APIs to use transactions. - Core API: It is a similar syntax to relational databases (e.g., start_transaction and commit_transaction)
事务是数据库中处理的一个逻辑单元,包含一个或多个数据库操作,这些操作可以是读操作或写操作。事务在MongoDB中提供了一种有用的功能,以确保一致性。MongoDB提供了两个用于使用事务的API。 - 核心API:其语法与关系数据库类似(例如,start_transaction和commit_transaction)
- Call-back API: This is the recommended approach to using transactions. It starts a transaction, executes the specified operations, and commits (or aborts on the error). It also automatically incorporates error handling logic for "TransientTransactionError" and"UnknownTransactionCommitResult".
699. What are MongoDB Charts?
什么是MongoDB Charts?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37bd558d557c902bb4d12 | 官方: 否 | 付费: 否
答案:
MongoDB Charts is a new, integrated tool in MongoDB for data visualization. MongoDB Charts offers the best way to create visualizations using data from a MongoDB database. It allows users to perform quick data representation from a database without writing code in a programming language such as Java or Python. The two different implementations of MongoDB Charts are: - MongoDB Charts PaaS (Platform as a Service)
MongoDB Charts是MongoDB中一个全新的集成工具,用于数据可视化。MongoDB Charts提供了使用MongoDB数据库中的数据创建可视化效果的最佳方式。它允许用户无需使用Java或Python等编程语言编写代码,即可快速从数据库中进行数据表示。MongoDB Charts的两种不同实现是: - MongoDB Charts PaaS(平台即服务)
- MongoDB Charts Server
700. What is the Aggregation Framework in MongoDB?
MongoDB中的聚合框架是什么?
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37bd558d557c902bb4d15 | 官方: 否 | 付费: 否
答案:
- The aggregation framework is a set of analytics tools within MongoDB that allow you to do analytics on documents in one or more collections.
- The aggregation framework is based on the concept of a pipeline. With an aggregation pipeline, we take input from a MongoDB collection and pass the documents from that collection through one or more stages, each of which performs a different operation on its inputs (See figure below). Each stage takes as input whatever the stage before it produced as output. The inputs and outputs for all stages are documents—a stream of documents.
701. Explain the concept of pipeline in the MongoDB aggregation framework.
解释MongoDB聚合框架中管道(pipeline)的概念。
- 知识点: 数据库 (主题: mongodb, nosql, database;标签: interviewbit, mongodb, topic-specific, nosql, database)
- 类型: technical | 难度: hard | 子类型: concept
- 分类: fullstack
- id: 69b37bd558d557c902bb4d18 | 官方: 否 | 付费: 否
答案:
An individual stage of an aggregation pipeline is a data processing unit. It takes in a stream of input documents one at a time, processes each document one at a time, and produces an output stream of documents one at a time (see figure below).
聚合管道中的单个阶段是一个数据处理单元。它一次接收一个输入文档流,一次处理每个文档,并一次生成一个输出文档流(见下图)。
评论