| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 大数据 -> SQL interview Questions -> 正文阅读 |
|
[大数据]SQL interview Questions |
? SQL Cheat Sheet What is SQLDataa collection of facts related to some objectDatabasea collection of small units of data arranged in a systematic manner.RDBMSa collection of tools that allows the users to manipulate,organize and visualize the contents of a database while following some standard rules that facilate fast response between the database and the user side.SQLStructured Query LanguageSQL FeaturesSQL allows us to interact with the databases and bring out/manipulate data within them. Using SQL, we can create our own databases and then add data into these databases in the form of tables.The following functionalities can be performed on a database using SQLCreate or Delete a DatabaseCreate or Alter or Delete some tables in a DatabaseSelect data from tablesINSERT data into tablesUpdate data in tablesDelete data from tablesCreate Views in the databaseExecute various aggregate functionsSQL Advanced ConceptsCreate Table:CREATE TABLE student(?? ID INT NOT NULL,?? Name varchar(25),?? Phone varchar(12),?? Class INT);Delete Table:To delete a table from a database, we use the DROP command.DROP TABLE student;SQL DataTypes:String Datatypes:Numeric Datatypes:Date/Time Datatypes:SQL Commands:Data Definition Language(DDL): It changes a table’s structure by adding, deleting and altering its contents. Its changes are auto-committed(all changes are automatically permanently saved in the database).
????? CREATE TABLE STUDENT(Name VARCHAR2(20), Email VARCHAR2(100), DOB DATE);?
????? ALTER TABLE STUDENT ADD(ADDRESS VARCHAR2(20));? ALTER TABLE STUDENT MODIFY (ADDRESS VARCHAR2(20));?
????? DROP TABLE STUDENT;?
????? TRUNCATE TABLE STUDENT; Data Manipulation Language(DML): It is used for modifying a database, and is responsible for any form of change in a database. These commands are not auto-committed, i.e all changes are not automatically saved in the database.
????? INSERT INTO STUDENT (Name, Subject) VALUES ("Scaler", "DSA");?
????? UPDATE STUDENT?? SET User_Name = 'Interviewbit'??? WHERE Student_Id = '2'?
????? DELETE FROM STUDENT WHERE Name = "Scaler"; Data Control Language(DCL): These commands are used to grant and take back access/authority (revoke) from any database user.
????? GRANT SELECT, UPDATE ON TABLE_1 TO USER_1, USER_2;?
????? REVOKE SELECT, UPDATE ON TABLE_1 FROM USER_1, USER_2;? Transaction Control Language: These commands can be used only with DML commands in conjunction and belong to the category of auto-committed commands.
????? DELETE FROM STUDENTSWHERE AGE = 16;? COMMIT;?
????? DELETE FROM STUDENTS WHERE AGE = 16;? ROLLBACK;
????? SAVEPOINT SAVED;DELETE FROM STUDENTS WHERE AGE = 16;? ROLLBACK TO SAVED; Data Query Language: It is used to fetch some data from a database.
????? SELECT Name? FROM Student? WHERE age >= 18; SQL ConstraintsNOT NULL: Specifies that this column cannot store a NULL value.
UNIQUE: Specifies that this column can have only Unique values, i.e the values cannot be repeated in the column.
Primary Key: It is a field using which it is possible to uniquely identify each row in a table. We will get to know about this in detail in the upcoming section.?Foreign Key: It is a field using which it is possible to uniquely identify each row in some other table. We will get to know about this in detail in the upcoming section.CHECK: It validates if all values in a column satisfy some particular condition or not.
DEFAULT: It specifies a default value for a column when no value is specified for that field.
Crud Operations in SQLCRUD is an abbreviation for Create, Read, Update and Delete. These 4 operations comprise the most basic database operations.INSERT: To insert any new data ( create operation - C ) into a database, we use the INSERT INTO statement.
SELECT: We use the select statement to perform the Read ( R ) operation of CRUD.
UPDATE: Update is the ‘U’ component of CRUD. The Update command is used to update the contents of specific columns of specific rows.
DELETE:The Delete command is used to delete or remove some rows from a table. It is the ‘D’ component of CRUD.
Important SQL KeywordsADDWill add a new column to an existing table.
ALTER TABLEAdds edits or deletes columns in a table
ALTER COLUMNCan change the datatype of a table's column
ASRenames a table/column with an alias existing only for the query duration
ASCUsed? in conjunction with order by to sort data in ascending order.
DESCUsed in conjunction with order by to sort data in descending order
CHECKConstraints the value which can be added to a column.
CREATE DATABASECreates a new database
DEFAULTSets the default value for? a given column
DELETEDelete values from a table
DROP COLUMNDeletes/Drops a column from a table
DROP DATABASECompletely deletes a database with all its content within
DROP DEFAULTRemoves a default value for a column.
DROP TABLEDeletes a table from a database
FROMDetermines which table to read or delete data from
INUsed with WHERE clause for multiple OR conditionals.
ORDER BYUsed to sort given data in Ascending or Descending order.
SELECT DISTINCTWorks in the same war as SELECT ,except that only unique values are included in the results.
TOPUsed in conjunction with SELECT to select a fixed number of records
VALUESUsed along with the INSERT INTO keyword to add new values to a table.
WHERE Filters given data based on some given condition.
UNIQUEEnsures that all values in a column are different.
UNIONUsed to combine the result-set of two or more SELECT statements.
UNION ALLCombines the result set of two or more SELECT statements(if allows duplicate values)
SELECT TOPUsed to specify the number of records to return.
LIMITPuts a restriction on how many rows are returned from a query.
UPDATEModifies the existing records in a table
SETUsed with UPDATE to specify which columns and values should be updated in a table.
IS NULLColumn values are tested for NULL values using this operator.
LIKE Used to search for a specified pattern in a column.
ROWNUMReturns a number indicating the order in which Oracle select row from a table or set of join rows.
GROUP BYGroups rows that have the same values into summary rows.
HAVINGEnables the user to specify conditions that filterwhich group results appear in the results.
Clauses in SQLWHEREUsed to select data from the database based on some conditions.
ANDUsed to combine 2 or more conditions and returns true if all the conditions are True.
ORSimilar to AND but returns true if any of the conditions are True.
LIKEUsed to search for a specified pattern in a column
LIMITPuts a restriction on how many rows are returned? from a query.
ORDER BYUsed to sort given data in Ascending or Descending from a query.
GROUP BYGroups rows that have the same values into summary rows.
HAVINGIt performs the same as the WHERE clause but can also be used with aggregate functions
Joins in SQLINNER JOIN: Returns any records which have matching values in both tables.
NATURAL JOIN: It is a special type of inner join based on the fact that the column names and datatypes are the same on both tables.
RIGHT JOIN: Returns all of the records from the second table, along with any matching records from the first.
LEFT JOIN: Returns all of the records from the first table, along with any matching records from the second table.
FULL JOIN: Returns all records from both tables when there is a match.
Triggers in SQLSQL codes automatically executed in response to a certain event occurring in a table of a database are called triggers. There cannot be more than 1 trigger with a similar action time and event for one table.Create Trigger Trigger_Name(Before | After)? [ Insert | Update | Delete]on [Table_Name][ for each row | for each column ][ trigger_body ]
DROP: This operation will drop an already existing trigger from the table
SHOW: This will display all the triggers that are currently present in the table.
SQL Stored ProceduresCREATE PROCEDURE procedure_name AS sql_statementGO;
EXEC procedure_name;SQL InjectionInsertion or ‘Injection’ of some SQL Query from the input data of the client to the application is called SQL Injection. They can perform CRUD operations on the database and can read to vulnerabilities and loss of data.Data is used to dynamically construct an SQL Query.Unintended data from an untrusted source enters the application.Here the hacker is injecting SQL code - :UNION SELECT studentName, rollNo FROM students |
|
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/23 13:16:12- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |