SQL Questions IV Flashcards
Write down various types of relationships in SQL?
There are various relationships, namely:
One-to-One Relationship.
One to Many Relationships.
Many to One Relationship.
Self-Referencing Relationship.
What is a trigger?
The trigger is a statement that a system executes automatically when there is any modification to the database.
In a trigger, we first specify when the trigger is to be executed and then the action to be performed when the trigger executes. Triggers are used to specify certain integrity constraints and referential constraints that cannot be specified using the constraint mechanism of SQL.
What is a Live Lock?
Livelock occurs when two or more processes continually repeat the same interaction in response to changes in the other processes without doing any useful work.
Livelock to sytuacja w systemach wielowątkowych, rozproszonych lub baz danych, w której operacje systemowe są aktywnie wykonywane, ale nie prowadzą do postępu w realizacji celu, czyli nie rozwiązują problemu, dla którego zostały zaprojektowane.
These processes are not in the waiting state, and they are running concurrently. This is different from a deadlock because in a deadlock all processes are in the waiting state.
What is Case WHEN in SQL?
Control statements form an important part of most languages since they control the execution of other sets of statements. These are found in SQL too and should be exploited for uses such as query filtering and query optimization through careful selection of tuples that match our requirements. In this post, we explore the Case-Switch statement in SQL. The CASE statement is SQL’s way of handling if/then logic.
CASE case_value
WHEN when_value
THEN statement_list
[WHEN when_value THEN statement_list] …
[ELSE statement_list]
END CASE
Name different types of case manipulation functions available in SQL.
LOWER: The purpose of this function is to return the string in lowercase. It takes a string as an argument and returns the string by converting it into lower case.
UPPER: The purpose of this function is to return the string in uppercase. It takes a string as an argument and returns the string by converting it into uppercase.
NITCAP: The purpose of this function is to return the string with the first letter in uppercase and the rest of the letters in lowercase.
What are local and global variables and their differences?
Global Variable: In contrast, global variables are variables that are defined outside of functions. These variables have global scope, so they can be used by any function without passing them to the function as parameters.
Local Variable: Local variables are variables that are defined within functions. They have local scope, which means that they can only be used within the functions that define them.
Name the function which is used to remove spaces at the end of a string?
In SQL, the spaces at the end of the string are removed by a trim function.
Define SQL Order by the statement?
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns.
By default ORDER BY sorts the data in ascending order.
We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
Explain SQL Having statement?
HAVING is used to specify a condition for a group or an aggregate function used in the select statement. The WHERE clause selects before grouping. The HAVING clause selects rows after grouping. Unlike the HAVING clause, the WHERE clause cannot contain aggregate functions.
Define BETWEEN statements in SQL?
The SQL BETWEEN condition allows you to easily test if an expression is within a range of values (inclusive). The values can be text, date, or numbers. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement. The SQL BETWEEN Condition will return the records where the expression is within the range of value1 and value2.
COMMIT
OMMIT permanently saves the changes made by the current transaction.
The transaction can not undo changes after COMMIT execution.
When the transaction is successful, COMMIT is applied.
ROLLBACK
ROLLBACK undo the changes made by the current transaction.
Transaction reaches its previous state after ROLLBACK.
When the transaction is aborted, ROLLBACK occurs.
What are ACID properties?
A transaction is a single logical unit of work that accesses and possibly modifies the contents of a database. Transactions access data using read-and-write operations. In order to maintain consistency in a database, before and after the transaction, certain properties are followed.
These are called ACID properties. ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties that guarantee that database transactions are processed reliably. For more details please read ACID properties in the DBMS article.
ACID
Atomicity, Consistency, Isolation, Durability
Are NULL values the same as zero or a blank space?
In SQL, zero or blank space can be compared with another zero or blank space. whereas one null may not be equal to another null.
null means data might not be provided or there is no data.