SQL Flashcards
What is SQL?
Structured Query Language is a domain specific language used in programming and designed for managing data held in a rational data management system
What is a data management system? A relational database system?
The software used to store, manage, query, and retrieve data stored in a relational database. Provides an interface between users and applications and the database, as well as administrative functions for managing data storage, access, and performance
What is a database?
An organized collection of data stored and accessed electronically. Most databases contain multiple tables, which may each include several different fields. For example, a company database may include tables for products, employees, and financial records
What are the sublanguages of SQL?
SQL statements are classified into sublanguages: a data query language (DQL), a data definition language (DDL), a data control language (DCL), and a data manipulation language (DML).
What is multiplicity?
Specifies the number of instances of an EntityType that can be associated with another EntityType, or the number of instances of an EntityType that can be associated with another EntityType.
Can be divided into four types: one-to-one, one-to-many, many-to-one, and many-to-many. A one-to-one relationship: Each entity instance is related to a single instance of another. Multiple instances of the same entity can be associated with one entity instance.
What is cardinality?
Refers to the uniqueness of data in a specific column of a table. A table would be said to have less cardinality if it has more duplicated data in a column. So, the more cardinality the less data duplication (in a column) of SQL database table
What is a candidate key?
A specific type of field in a relational database that can identify each unique record independently of any other data. It is a super key with no repeated data. Ex. Primary or foreign keys for creating associations between tables
Data query language (DQL)
The commands of SQL that are used to retrieve data from the database are collectively called as DQL. So all Select statements comes under DQL. Select.
Data definition language (DDL)
DDL is Data Definition Language which is used to define data structures. For example: create table, alter table are instructions in SQL.
Data control language (DCL)
DCL includes commands such as GRANT and REVOKE which mainly deal with the rights, permissions, and other controls of the database system. GRANT: This command gives users access privileges to the database
Data manipulation language (DML)
DML is Data Manipulation Language which is used to manipulate data itself. For example: insert, update, delete are instructions in SQL
What are Tables and Fields?
A table is a set of data that are organized in a model with Columns and Rows. Columns can be categorized as vertical, and Rows are horizontal. A table has specified number of column called fields but can have any number of rows which is called record.
What is a Primary Key?
A primary key is a combination of fields which uniquely specify a row. This is a special kind of unique key, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.
What is a Unique Key?
A Unique key constraint uniquely identified each record in the database. This provides uniqueness for the column or set of columns.
A Primary key constraint has automatic unique constraint defined on it. But not, in the case of Unique Key.
There can be many unique constraint defined per table, but only one Primary key constraint defined per table.
What is a Foreign Key?
A foreign key is one table which can be related to the primary key of another table. Relationship needs to be created between two tables by referencing foreign key with the primary key of another table.
What is a JOIN?
This is a keyword used to query data from more tables based on the relationship between the fields of the tables. Keys play a major role when JOINs are used.
What are the types of JOINS? Explain.
There are various types of join which can be used to retrieve data and it depends on the relationship between tables.
· Inner Join.
Inner join return rows when there is at least one match of rows between the tables.
· Right Join.
Right join return rows which are common between the tables and all rows of Right hand side table. Simply, it returns all the rows from the right hand side table even though there are no matches in the left hand side table.
· Left Join.
Left join return rows which are common between the tables and all rows of Left hand side table. Simply, it returns all the rows from Left hand side table even though there are no matches in the Right hand side table.
· Full Join.
Full join return rows when there are matching rows in any one of the tables. This means, it returns all the rows from the left hand side table and all the rows from the right hand side table.
What is Normalization
Normalization is the process of minimizing redundancy and dependency by organizing fields and table of a database. The main aim of Normalization is to add, delete or modify field that can be made in a single table.
What is Denormalization?
DeNormalization is a technique used to access the data from higher to lower normal forms of database. It is also process of introducing redundancy into a table by incorporating data from the related tables.
What are all the different normalizations?
The normal forms can be divided into 5 forms, and they are explained below -.
· First Normal Form (1NF):.
This should remove all the duplicate columns from the table. Creation of tables for the related data and identification of unique columns.
· Second Normal Form (2NF):.
Meeting all requirements of the first normal form. Placing the subsets of data in separate tables and Creation of relationships between the tables using primary keys.
· Third Normal Form (3NF):.
This should meet all requirements of 2NF. Removing the columns which are not dependent on primary key constraints.
· Fourth Normal Form (4NF):.
Meeting all the requirements of third normal form and it should not have multi- valued dependencies.
What is a View?
A view is a virtual table which consists of a subset of data contained in a table. Views are not virtually present, and it takes less space to store. View can have data of one or more tables combined, and it is depending on the relationship.
What is an Index?
An index is performance tuning method of allowing faster retrieval of records from the table. An index creates an entry for each value and it will be faster to retrieve data.