SQL Flashcards
What is an RDBMS?
- It stands for Relational Database Management System which is a program that allows
you to create, update, and save data in a relational database. - Some examples are Oracle, PostgreSQL, MySQL, SQLite.
What is SQL?
- SQL stands for Structured Query Language and it is a programming language used to
communicate with the data stored in relational database management system. - SQL has sublanguages that are used specifically to either create/alter/drop tables,
add/update/delete row entries in those tables, control what data you are retrieving from
the tables, control user permissions, and handle transactions.
What are subtypes/sublanguages of SQL?
- Sublanguages are a group of commands in SQL used to work with specific parts of a
database table. - DDL, DML, DQL, DCL TCL
What is DDL? What are the keywords?
- It stands for Data Definition Language and it is used to define tables and set their
properties. With it, you can create a table, alter the properties of the table and drop the
table. - The keywords are CREATE, ALTER, DROP, TRUNCATE
What is DML? What are the keywords?
- DML stands for Data Manipulation Language, The commands of SQL that are used to
insert data into the database, modify the data of the database and to delete data from
the database are collectively called as DML. - You can insert rows into the table, update rows and delete rows
- The keywords are INSERT, UPDATE, DELETE
What is DCL? What are the keywords?
- DCL stands for Data Control Language, and it is the sub language that is used to grant
and revoke users of their rights and permissions to a database - The keywords are GRANT and REVOKE
What is DQL? What are the keywords?
- DQL stands for Data Query Language. 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. - The keyword with DQL is SELECT
- DQL is sometimes included in DML
What is TCL? What are the keywords?
- TCL stands for Transaction Control Language.
- TCL commands are used to manage transactions in database. These are used to
manage the changes made by DML-statements. - The keywords are COMMIT, ROLLBACK, SAVEPOINT
What is a Database?
- It is a structured collection of data that is stored in a computer or server and can be
accessed and manipulated in various ways.
What are Objects in SQL?
- Objects in SQL are any defined object that can store or reference data.
- Some objects may encompass other SQL objects.
- The database itself is a SQL object itself that encompasses all other data objects.
- The database contains Schema objects that contain table objects and views.
- Columns are the smallest data object.
What are Triggers? When can they execute?
- Triggers are a database object/ block of code that executes one or more SQL
statements when a specified operation/ event is executed. - You can define when a trigger fires when you define the trigger
- Events are any DML (Delete, Update, Insert)
- Can specify a chronological relationship to these events (whether they occur before or
after their execution)
What is a Schema?
- A schema is a collection of database objects associated with one particular
database username. - The username is called the schema owner, or the owner of the related group of objects.
- You can have multiple schemas in a database.
Schema types - Snowflake - normalized; different relationships between tables.
- Star - not normalized; all tables point back to one fact table.
What is an Index?
- An index is used to speed up the performance of queries.
- It does so by reducing the number of database data pages that have to be
scanned/visited. - In SQL Server, a clustered index determines the physical order of data in a table.
- There can only be one clustered index per table (the clustered index is the table).
What is a Sequence?
- A sequence is a user-defined, schema-bound object that generates a sequence of
numeric values according to the specification with which the sequence was
created. - The sequence of numeric values is generated in an ascending order or descending order
at a defined interval and can be configured to restart when exhausted. - You can use a sequence to define a row by a unique value.
What are the different relationships in SQL?
- One-to-one - both tables can have only one record on either side of the relationship.
- One-to-many - one table can only have one record on its side of the relationship while
others can have many records of the relationship - Many-to-many - both sides can have many records on either side of the relationship.
What are the different types of Joins?
- Inner Join - Returns data that occurs in both tables, only where there is a match in
both tables. - Left Join - Returns the data that occurs in the left table and the values that matched
records in the right table. - Right Join - Returns the data from the right table and the matching data from the left
table. - Full Outer Join - Returns all records from both tables and matches them when
possible. - Self Join - Regular join where you join a table with itself.
- Cross Join - Produces a result set in which the number of rows in the first table
multiplied by the number of rows in the second table if no WHERE clause is used
along with CROSS JOIN. This kind of result is called a Cartesian Product.
What are the set operators?
Set operators combine the results of two component queries into a single result.
Queries containing set operators are called compound queries.
- Include:
-
- UNION ALL
- INTERSECT
- MINUS
What are the Transaction Properties?
ACID
- Atomicity.
- Consistency.
- Isolation.
- Durability.
What is Atomicity?
- Atomicity - each transaction is all or nothing, if any part of the transaction fails the
whole of it fails, and then the database is rolled back to its last consistent state.