Interview Questions Flashcards
This set of questions came from edureka! on YouTube
DELETE and TRUNCATE
DELETE
- used to delete a row in a table
- you can rollback data after delete
- DML comand
- slower
TRUNCATE
- delete all the rows in a table
- cannot rollback data
- DDL command
- faster
Subsets of SQL
What do you mean by DBMS? What are its different types?
Hierarchial
Network
Relational
Object-Oriented
What do you mean by table and field in SQL?
Table refers to a collection of data in an organised manner in form of rows and columns
Field refers to the number of columns in a table
What are joins in SQL?
A JOIN clause is used to combine rows from two or more tables, based on a related column between them. It is used to merge two tables or retrieve data from there.
Inner Join
Full Join
Left Join
Right Join
CHAR and VARCHAR2 datatype difference
Char is used for strings of fixed length
Varchar2 is used for character strings of variable length
What is a Primary key?
A specific choice of a minimal set of attributes that uniquely specify a tuple in a relation.
What are constraints?
Constraints are used to specify the limit on the data type of the table. It can be specified while creating or altering the table statement.
NOT NULL
UNIQUE
CHECK
DEFAULT
INDEX
What is the difference between SQL and MySQL?
Structured Query Language
MySQL is an open-source relational database management system that works on many platforms. It provides multi-user access to support many storage engines and is backed by Oracle.
What is a unique key?
Uniquely identifies a single row in the table.
Multiple values allowed per table.
Null values are allowed.
Duplicate values are not allowed.
What is a foreign key?
Foreign key maintains referential integrity by enforcing a link between the data in two tables.
The foreign key in the child table references the primary key in the parent table.
The foreign key constraint prevents actions that would destroy links between the child and parent tables.
What do you mean by data integrity?
Accuracy of data
Consistency of data
Integrity Constraints to enforce buisness rules on data
What is the difference between clustered and non clustered index in SQL?
Clustered Index
- clustered index is used for easy retrieval of data from the database and is faster
- clustered index alters the way records are stored in a database as it sorts out rows by the column which is set to be clustered index
- one table can only have one clustered index
Non Clustered Index
- non-clustered index is used for easy retrieval of data from the database and is slower
- non-clustered index does not alter the way it was stored but it creates a separate object within a table which points back to the original table rows after searching
- one table can have many non-clustered indexes
Write a SQL query to display the current date?
GetDate()
SELECT GETDATE();
Result: ‘2019-03-18 18:17:26.160’
What are the different type of joins?
Inner Join
Full Join
Left Join
Right Join
What do you mean by Denormalization?
- Refers to a technique which is used to access data from higher to lower forms of a database.
- Increase the performance of the entire infrastructure as it introduces redundancy into a table.
- Adds the redundant data into a table by incorporating database queries that combine data from various tables into a single table.
What are Entities?
A person, place, or thing about which data can be stored in a database. Tables store data that represents one type of entity.
What are relationships?
Relation or links between entities that have something to do with each other.
What is an index?
- Performance tuning method
- Allows faster retrieval of records from the table
- Creates an entry for each value
Explain different types of index.
Unique Index
- This index does not allow the field to have duplicate values if the column is unique index. If a primary key is defined, a unique index can be applied automatically.
Clustered Index
- This index reorders the physical order of the table and searches based on the basis of key values. Each table can only have one clustered index.
Non-clustered Index
- Non-clustered index does not alter the physical order of the table and maintains a logical order of the data. Each table can have many non-clustered indexes.
What is Normalization and what are the advantages of it?
- Better database organization
- more tables with smaller rows
- efficient data access
- greater flexibility for queries
- quickly find the information
- easier to implement security
- allows easy modification
- reduction of redundant and duplicate data
- more compact database
- ensure consistent data after modification
What is the difference between DROP and TRUNCATE commands?
DROP removes a table and it cannot be rolled back from the database
TRUNCATE removes all rows from the table and cannot be rolled back into the database
Explain the different types of Normalization.
divides larger tables into smaller tables and links them together
1 NF
- each table cell should contain a single value
- each record needs to be unique
2 NF
- Be in 1 NF
- Single column primary key
3 NF
- Be in 2 NF
- has no transitive functional dependencies
BCNF
Stricter than 3 NF
A table is in BCNF if every functional dependency X → Y, X is the super key of the table.
What is ACID property in a database?
Atomicity
- Transactions are all or nothing
Consistency
- Only valid data is saved
Isolation
- Transactions do not affect each other
Durability
- Written data will not be lost
What do you mean by “Trigger” in SQL?
Trigger in SQL are a special type of stored procedies that are defined to execute automatically in plasce or after data modifications. It allows you to execute a batch of code when an insert, update, or any other query is executed against a specific table.
What are the different operators available in SQL?
Arithmetic
Bitwise
Comparison
Compound
Logical