Relational Databases

Ace your homework & exams now with Quizwiz!

What are character manipulation functions?

Character manipulation functions can edit, change, or reformat character strings. For example, you can concatenate two character strings by passing them into the CONCAT function using a SELECT query.

What is a FOREIGN KEY constraint?

A FOREIGN KEY is a column or collection of fields in a table referencing a PRIMARY KEY in another table. This is how we link tables relationaly. The table containing the primary key is known as the parent table, and the table containing the foreign key is called the child table.

What is a self join?

A JOIN clause combines rows from two or more tables based on a related column between them. A self join is a regular join, but the table is joined with itself - this is extremely useful for comparisons within a table. Joining a table with itself means that each table row is combined with itself and with every other row of the table.

What is a PRIMARY KEY constraint?

A PRIMARY KEY constraint is a column (or combination of columns) used to distinguish each table row with a unique identifier. You can think of a primary key as having a similar function to national government-issued identification numbers, a citizen's Social Security Number, or a vehicle identification number (VIN).

What is a database?

A database is an organized collection or data, stored in a computer system.

What is a query?

A set of instructions written in a query language like SQL that allows an individual to access information held in a database. "A query is a way of telling the database that I want to read some of its data. I can send a request that shows me employee attendance records for the past week, for example."

What is a subquery?

A subquery or nested query is a query within a query.

What is collation? What are the different collation sensitivity?

Collation is a configuration setting that specifies how a database sorts and compares data. Different collation rules can be configured to determine the correct character sequence used to sort the character data. Collation sensitivity can be used to specify how different characters are treated. Accent sensitivity differentiates between a and á. Case sensitivity differentiates between A and a. Kana sensitivity differentiates between Japanese Hiragana and Katakana. Width sensitivity treats characters of different widths (single-byte and double-byte) differently.

Explain the different types of SQL commands.

Data Definition Language (DDL), used to create and restructure relational database objects, such as tables. Data Manipulation Language (DML), Used to manipulate data within relational database objects. Data Query Language (DQL), with only one command, DQL is used to perform queries within a relational database. Data Control Language (DCL), used to control access to data within a relational database. Transactional control commands, used to manage transactions within a relational database.

What are SQL joins? What are the different types of joins?

In SQL, a JOIN clause combines rows of data in different tables with a shared column. You can SELECT and return records with matching values in both tables based on this relationship. There are four kinds of JOIN clauses in SQL.

What are aggregate functions?

In SQL, aggregate functions (also known as group functions) are applied to a group of values (or all values) to calculate and return a single value.

What is a cross join (Cartesian join)?

In SQL, the cross join combines each row of the first table with each row of the second table. It is also known as the Cartesian join since it returns the Cartesian product of the sets of rows from the joined tables.

What is an RDBMS, and how is it different from a traditional DBMS

In a Relational Database Management System data is organized into tables. Where the data elements related to each other. An RDBMS lets your define, create, and maintain relational databases in addition to providing controlled access to the data within. A Database Management System functions similarly to the RDBMS described above. However, DBMS data elements are stored as files rather than in tabular form, and there is no relationship between different data elements.

What is a stored procedure?

Instead of writing the same SQL query multiple times, you can save it as a stored procedure and call on it whenever necessary to execute it. Store an SQL query: CREATE PROCEDURE procedure_nameASsql_statementsGO; Execute a stored procedure: EXEC procedure_name;

What are some case manipulation functions in SQL?

LOWER or LCASE takes in a given character string and converts it to lower case. UPPER or UCASE takes in a given character string and converts it to upper case.

What is a UNIQUE constraint?

Like the PRIMARY KEY, the UNIQUE constraint also ensures that each value is different from the others in its column. However, tables can have multiple columns with UNIQUE constraints, unlike the PRIMARY KEY constraint, limited to just one.

What are Normalization and Denormalization?

Normalization refers to the methods used to remove redundancies and inconsistencies in a database. Normalization introduces more tables to a database, whereas Denormalization refers to methods used to improve the performance of queries. Denormalization reduces the number of tables.

What are scalar functions?

Scalar functions are defined by the user and return a single value (i.e., int, char, float, etc.) based on the input value.

What is SQL?

Structured Query Language is a non-procedural programming language (all the instructions are not written in a specific order, in other words - the user only needs to tell the computer what they want to be done, not how it should be done) used by almost all relational databases to write queries, access, edit, and retrieve data. This language is how database administrators communicate with a database and manage its contents. For example, I use a particular string of commands and variables, called a query, to look up values in the database."

What are ACID properties?

The ACID properties refer to properties that must be followed for transactions in a database management system to remain consistent. Atomicity: The entire transaction takes place at once or not at all. Consistency: A database must be consistent before and after a transaction takes place. Isolation: Transactions occur independently and can run concurrently with others. Durability: Updates to the database must be stored in and written to disk so that transaction records can persist in the event of a system failure.

What's the difference between a WHERE clause and a HAVING clause?

The WHERE clause can be used to establish the first condition that groups and returns only the rows that meet that condition into a result set. Then, secondary conditions can be applied using the HAVING clause to return only the groups within that set that meet your new criteria.

What is an alias command?

The alias (AS) command makes columns or tables easier to read by giving them temporary names for the duration of a query.

What is the difference between CHAR and VARCHAR datatypes in SQL?

The character or CHAR datatype stores fixed length character strings. The variable character or VARCHAR datatype stores variable length character strings. CHAR has better performance than VARCHAR, but VARCHAR can be useful for anticipating data values without a set length.

What is the default ordering of data using the order by clause? How could it be changed?

The default ordering of data is ascending (ASC). You can change the order by using the descending (DESC) keyword with the ORDER BY clause like so: SELECT * FROM table_name ORDER BY column_name DES

What's the standard syntax for group functions?

The general syntax is: SELECT column_name, group_function(column_name) FROM table_nameWHERE condition WHERE condition GROUP BY column_name HAVING condition ORDER BY column_name

What is the difference between a clustered index and a non-clustered index?

The order of rows in a clustered index corresponds to the order of rows in the database. A table can only have one clustered index at a time. A non-clustered index functions similarly to a clustered index, but is slower and creates a separate entity within the table that references the original table. A table can have multiple non-clustered indices.

What are user-defined functions in SQL? What are the various types?

There are two types of functions in SQL: System Defined Functions (SDF) and User-Defined Functions (UDF) User-Defined Functions (UDFs) are similar to functions found in programming languages. UDFs accept parameters, perform complex calculations, and return their results. There are three types of UDFs: Scalar Functions return only a single value (scalar value) of any data type except text, ntext, image, cursor, and timestamp. Inline Table-Valued Functions return a table of values. Only one SELECT statement can be prepared by the return statement, and this statement defines the structure of the table that function returns. Multi-Statement Table-Valued Functions also return a table of values, but can contain multiple statements, and its table structure is defined by the user.

What is an SQL Server cursor? How do you use it?

When you want to process result sets one row at a time, you can use a database cursor, a control structure that allows you to traverse records in a database. Cursors can be used to point to individual rows in a group of rows. You can DECLARE a cursor after any variable declaration. DECLARE variable_name CHAR(20) DECLARE cursor_name CURSOR FORSELECT column_name FROM table_name

How do you create empty tables with the same structure as another table?

You can use shallow cloning to create a copy of an existing table's data structure and column attributes. CREATE TABLE new_table LIKE table_1; This command creates an empty table based on the parent table.

What is an index?

An SQL index is a lookup table used by the database search engine to find and retrieve data quickly. An index can help makeSELECT and WHERE clauses faster but can slow down the use of UPDATE and INSERT statements. To create an index: CREATE INDEX index_name ON table_name;

What is a schema?

An SQL schema is an abstract representation of logically structured data elements. Database schemas in SQL are defined at the logical level by a database user known as the schema owner.

What are entities and relationships?

An entity can be a real-world object that can be identified by a collection of related attributes or properties. An example of an entity in a zoo database might include zookeepers, veterinarians, different public outreach initiatives, or species of animals. Relationships are connections between entities that are associated with each other. The logical relationship between entities creates a database.

What are the different types of indexes?

Clustered indexes are clustered together with the main body of data. A clustered index sorts and stores rows of data in a table or view sequentially, based on key values of the table to match the order of the index. There can only be one clustered index per table. Non-clustered indexes are separate from, and cannot be used to store or sort data in the main table. The key values of the index, and not the table are used to define the order of a non-clustered index. Column store indexes are a standard form of index that efficiently stores data in a column-based format, rather than row-oriented. Filtered indexes are used to index a section of rows within a table. Hash indexes are arrays, and use the Hash function F(K, N), where K is critical and N is the number of slots containing a pointer and row. Unique indexes assign unique values to every row of data, so that the index key does not contain any duplicates.

What is the difference between a TRUNCATE command and a DELETE command?

DELETE is used to remove specific rows or tuples from tables or relations that can contain a WHERE clause. TRUNCATE is used to delete all rows or tuples from a table and cannot contain a WHERE clause. Unlike the DELETE command, data cannot be rolled back after using it to recover data that has been mistakenly deleted.

What is the difference between SQL and MySQL?

SQL is a programming language, while MySQL is a popular, open-source RDBMS. MySQL is used to store and organize data, while SQL is used to access, edit, update and maintain data in MySQL.

What is the difference between SQL and PL/SQL?

SQL is non-procedural and interacts directly with the database server. It's easy to learn and use, but if you need to solve more complicated SQL problems and are willing to learn some more complex concepts, then PL/SQL can be a powerful tool. PL/SQL is a procedural language that doesn't interact directly with the database server but offers a faster processing speed and an expanded range of supported features. You can accomplish everything you need to do in SQL and more using PL/SQL. PL/SQL: Can be used to write functions, packages, procedures, program blocks, and more. Supports for variables, conditional statements, and iterators. Supports error and exception handling.

How do you select unique records from a table?

The SELECT DISTINCT clause will only return unique values from a table.

What is the SELECT statement?

The SELECT statement is used in SQL queries to store specific data elements or fields from a table and return them in a result set. The SELECTsyntax: SELECT column_1, column_2, ...FROM table_name; To select all data elements from a table, use: SELECT * FROM table_name;

What are UNION, UNION ALL, MINUS, and INTERSECT set operators?

The UNION operation combines the results of two or more SELECT statements. For example, by getting the UNION of sets A and B, this operation would return all rows from both sets, excluding any duplicate rows. The UNION ALL operation does the same thing as UNION but includes duplicate rows in its result set. The INTERSECT operation combines the results of two SELECT statements but only returns the rows with matching values in both sets. The MINUS operation combines the results of two SELECT statements but only returns rows with values that belong to the first set of the result.

What are some common clauses used with SELECT queries in SQL?

The basic SQL SELECT statement contains three clauses: SELECT specifies the table columns to retrieve FROM specifies the tables to access WHERE is optional and specifies which rows in the FROM tables to use The GROUP BY clause is used with aggregate functions to group the result set according to specified columns. The HAVING clause functions similarly to the WHERE clause but allows the use of aggregate functions. The ORDER BY clause sorts the result set in ascending (ASC) or descending (DESC) order according to a specified column. When writing your SELECT queries, make sure that your syntax follows this order: SELECT column_name(s)FROM table_nameWHERE conditionGROUP BY column_name(s)HAVING conditionORDER BY column_name(s);


Related study sets

SQL - CH 2: Basic SQL SELECT Statements

View Set

Microbiology Ch 13 Reading Assignment

View Set

Social psychology - Prosocial behavior and altruism Ch 11

View Set

LSU CSC 4330 Software Engineering Final

View Set

Exam 1: Unit 7: Staffing and Scheduling

View Set

Intro to Coding - Using Flowcharts and Pseudocode

View Set

Lecture 6b: Chapter 4 & 5 Igneous rocks & volcanoes -Geology 301

View Set

TG-43: Brachytherapy Source Dose Calculation Formalism/ LDR Intracavitary

View Set