注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
最近准备面试总结了一波面试中常见的SQL概念,路过求大米啊,好多面经都看不到~~
. From 1point 3acres bbs1.DDL, DQL, DML, DCL and TCL Commands. 1point3acres
(1)DDL - Data Definition Language - deals with database schemas and descriptions, of how the data should reside in the database. create and modify the structure of database objects in the database.
①CREATE – to create database and its objects like (table, index, views, store procedure, function and triggers)
②ALTER – alters the structure of the existing database
③DROP – delete objects from the database
④TRUNCATE – remove all records from a table, including all spaces allocated for the records are removed
⑤COMMENT – add comments to the data dictionary
⑥RENAME – rename an object
(2)DQl - Data Query Language
①SELECT – retrieve data from the a database.. .и
(3)DML - Data Manipulation Language - deals with data manipulation
①INSERT – insert data into a table
②UPDATE – updates existing data within a table
③DELETE – Delete records from a database table
④MERGE – UPSERT operation (insert or update)
⑤CALL – call a PL/SQL or Java subprogram
⑥EXPLAIN PLAN – interpretation of the data access path
⑦LOCK TABLE – concurrency Contro
(4)DCL - Data Control Language - mostly concerned with rights, permissions and other controls of the database system.
①GRANT – allow users access privileges to database ..
②REVOKE – withdraw users access privileges given by using the GRANT command.--
(5)TCL - Transaction Control Language - deals with transaction within a database.
①COMMIT – commits a Transaction
②ROLLBACK – rollback a transaction in case of any error occurs
③SAVEPOINT – to rollback the transaction making points within groups
④SET TRANSACTION – specify characteristics for the transaction
2.OLAP and OLTP
OLAP - Online Analytical Processing - online database query system
Low frequency of online transaction, complex queries, use for data mining and maintain aggregated, historical data multidimensional schema.
Ex.: viewing financial and sales reports, extracting budgeting information, and viewing marketing management details. A personalized Amazon homepage with item recommendations are also instances of an OLAP system at play.
OLTP - Online transaction processing - online database modifying system
Designed for large audience of users who conduct short transactions, queries are usually simple, need fast response times and return relatively fewer records.
Pros: - Powerful for administering day-to-day transactions
- Simplifies individual processes, thus allowing an organization to increase its consumer base. 1point 3acres
Cons: -Allows multiple users to access and modify the same data, hence causing issues
- Online transactions get several affected by hardware failures
Ex.: ATM.
. From 1point 3acres bbs
Key Differences Between OLTP and OLAP
(1)The point that distinguishes OLTP and OLAP is that OLTP is an online transaction system whereas, OLAP is an online data retrieval and analysis system.
(2)Online transactional data becomes the source of data for OLTP. However, the different OLTPs database becomes the source of data for OLAP.
(3)OLTP’s main operations are insert, update and delete whereas, OLAP’s main operation is to extract multi dimensional data for analysis..
(4)OLTP has short but frequent transactions whereas, OLAP has long and less frequent transaction.
(5)Processing time for the OLAP’s transaction is more as compared to OLTP.
(6)OLAPs queries are more complex with respect OLTPs.
(7)The tables in OLTP database must be normalized (3NF) whereas, the tables in OLAP database may not be normalized..
(8)As OLTPs frequently executes transactions in database, in case any transaction fails in middle it may harm data’s integrity and hence it must take care of data integrity. While in OLAP the transaction is less frequent hence, it does not bother much about data integrity.
https://www.softwaretestinghelp. ... -questions-answers/
3.Data modeling
Data Modelling is the visual representation showing the entities and their relationships. It is the initial step towards database design. We first create the conceptual model, then logical model and finally move to the physical model. Generally, the data models are created in data analysis & design phase of software development life cycle.
(1)Conceptual model: defines what system contains, high-level, user view of data. Establish the entities, their attributes.
(2)Logical model: defines how the system should be implemented regardless DBMS. It defines the structure of the data elements and set the relationships between them. Will be showing up entity names, entity relationships, attributes, primary keys and foreign keys in each entity.
(3)Physical data model: describes how the system will be implemented using a specific DBMS system, how data is physically stored in a database. Will be showing primary keys, foreign keys, table names, column names and column data types. This view actually elaborates how the model will be actually implemented in the database.
The level of complexity and detail increases from conceptual to logical to a physical data model. The conceptual model shows a very basic high level of design while the physical data model shows a very detailed view of design.
4.Star schema & Snowflake schema
The star schema architecture is the simplest data warehouse schema.
A fact table typically has two types of columns: foreign keys to dimension tables and measures those that contain numeric facts. A fact table can contain fact's data on detail or aggregated level.
. Waral dи,A dimension is a structure usually composed of one or more hierarchies that categorizes data. The primary keys of each of the dimension tables are part of the composite primary key of the fact table. Dimensional attributes help to describe the dimensional value..google и
Simple structure -> easy to understand schema
Great query effectives -> small number of tables to join
Relatively long time of loading data into dimension tables -> de-normalization, redundancy data caused that size of the table could be large.
Star and snowflake schemas are similar at heart: a central fact table surrounded by dimension tables. In the Star Schema, the center of the star can have one fact table and a number of associated dimension tables. A Snowflake Schema is an extension of a Star Schema, and it adds additional dimensions. The dimension tables are normalized which splits data into additional tables. Star schema does not use normalization whereas snowflake schema uses normalization to eliminate redundancy of data.
5.UNION and UNION ALL. From 1point 3acres bbs
(1)UNION: no duplicate rows
(2)UNION ALL: may have duplicate rows
6.NATURAL JOIN and (INNER) JOIN
(1)NATURAL JOIN: no duplicate rows (do not use ‘on’)
(2)(INNER) JOIN: may have duplicate rows
7.WHERE and HAVING
(1)WHERE: . ----
①Filter rows before grouping. ----
②Used to check conditions before aggregation takes place. 1point 3acres
③Can’t have aggregation function in WHERE.
(2)HAVING: . check 1point3acres for more.
①Can only be used after GROUP BY
②Used to check conditions after aggregation takes place
③Can have aggregation function in HAVING
EX.: SELECT City, CNT = count(1)
FROM Address
WHERE State = ‘MA’. From 1point 3acres bbs
GROUP BY City;
//Gives you a table of all cities in MA, and the number of address in each city.
SELECT City, CNT = count(1)
FROM Address
WHERE State = ‘WA’
GROUP BY City
HAVING COUNT(1) > 5;
//Cities in MA with more than 5 addresses and the number of addresses in each city.
..
8.DELETE and TRUNCATE and DROP
(1)DELETE: delete rows from a table - DML
(2)TRUNCATE: delete all the rows from the table, free the space of all records - DDL
(3)DROP: remove an object from the datebase - DDL
https://blog.csdn.net/u013468917/article/details/61933994
9.ON & WHERE. 1point3acres.com
The ON clause defines the relationship between the tables.-baidu 1point3acres
The WHERE clause describes which rows you are interested in.
Many times you can swap them and still get the same result, however this is not always the case with a left outer join.
. Waral dи,- If the ON clause fails you still get a row with columns from the left table but with nulls in the columns from the right table.
- If the WHERE clause fails you won't get that row at all.
(1)如果SQL用的是Left Join ,On后面的条件对Left的表没有作用,只对Right的表有过滤作用,Where语句可以对Left的表有过滤作用
(2)如果SQL用的是Right Join ,On后面的条件对Right的表没有作用,只对Left的表有过滤作用,Where语句可以对Right的表有过滤作用
(3)如果SQL用的是Inner Join (也可以缩写成Join),On的条件对两个表都起作用。
https://www.dotnettricks.com/lea ... ction-in-sql-server
11.Function & procedure
(1)The function must return a value but in Stored Procedure it is optional. Even a procedure can return zero or n values.
(2)Functions can have only input parameters for it whereas Procedures can have input or output parameters.
(3)Functions can be called from Procedure whereas Procedures cannot be called from a Function..--
12.Window function.--
A window function performs an aggregate-like operation on a set of query rows. However, whereas an aggregate operation groups query rows into a single result row, a window function produces a result for each query row:
mysql> SELECT SUM(profit) AS total_profit
FROM sales;
+--------------+
| total_profit |
+--------------+
| 7535 | . Χ
+--------------+
mysql> SELECT country, SUM(profit) AS country_profit
FROM sales
GROUP BY country
ORDER BY country;
+-----------+-----------------+
| country | country_profit |
+-----------+-----------------+
| Finland | 1610 |
| India | 1350 |
| USA | 4575 |
+------------+----------------+
USE schooldb
SELECT id, name, Aggregation.gender, Aggregation.Total_students, Aggregation.Average_Age, Aggregation.Total_Score
FROM student. Waral dи,
INNER JOIN
(SELECT gender, count(gender) AS Total_students, AVG(age) AS Average_Age, SUM(total_score) AS Total_Score
FROM student
GROUP BY gender) AS Aggregation
on Aggregation.gender = student.gender.--
. 1point 3 acres
USE schooldb
SELECT id, name, gender,
COUNT(gender) OVER (PARTITION BY gender) AS Total_students,
AVG(age) OVER (PARTITION BY gender) AS Average_Age,. Χ
SUM(total_score) OVER (PARTITION BY gender) AS Total_Score. ----
FROM student
求大米求大米~~谢谢大家~~
|