Week 8 Flashcards

1
Q

What does DCL stand for?

A

DCL stands for Data Control Language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two main commands of DCL?

A

The two main commands of DCL are GRANT and REVOKE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of the GRANT command in DCL?

A

The purpose of the GRANT command in DCL is to give users specific privileges or permissions on database objects such as tables, views, or procedures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of the REVOKE command in DCL?

A

The purpose of the REVOKE command in DCL is to take back or remove previously granted permissions or privileges from users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does DCL help in database security?

A

DCL helps in database security by controlling user access to database objects and enforcing restrictions, thus preventing unauthorized operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does TCL stand for?

A

TCL stands for Transaction Control Language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the main commands of TCL?

A

The main commands of TCL are COMMIT, ROLLBACK, SAVEPOINT, and SET TRANSACTION.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of the COMMIT command in TCL?

A

The purpose of the COMMIT command in TCL is to permanently save the changes made during a transaction to the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of the ROLLBACK command in TCL?

A

The purpose of the ROLLBACK command in TCL is to undo changes made during a transaction before they are committed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between SAVEPOINT and ROLLBACK?

A

The difference between SAVEPOINT and ROLLBACK is that SAVEPOINT sets a point in a transaction to which you can later rollback, whereas ROLLBACK undoes all changes made since the beginning of the transaction or since a specified savepoint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a transaction in a database system?

A

A transaction in a database system is a unit of work that is performed against the database, which can include multiple operations like insertions, updates, and deletions, and must be executed in full or not at all.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the four properties of a transaction?

A

The four properties of a transaction are ACID: Atomicity, Consistency, Isolation, and Durability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why are transactions important for database integrity?

A

Transactions are important for database integrity because they ensure that the database remains in a consistent state, even in cases of failures, by allowing only complete operations to be committed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does a transaction help ensure data consistency?

A

A transaction helps ensure data consistency by ensuring that all operations within the transaction are successfully executed before changes are committed, or none at all.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens if a transaction fails?

A

If a transaction fails, the database can revert to its previous state using ROLLBACK, undoing all operations within the transaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does ACID stand for in the context of transactions?

A

ACID stands for Atomicity, Consistency, Isolation, and Durability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the ‘Atomicity’ property in ACID?

A

The Atomicity property ensures that all operations within a transaction are completed successfully or none are applied at all.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the ‘Consistency’ property in ACID?

A

The Consistency property ensures that a transaction brings the database from one valid state to another, maintaining database integrity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the ‘Isolation’ property in ACID?

A

The Isolation property ensures that transactions are executed independently without interference from other concurrent transactions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the ‘Durability’ property in ACID?

A

The Durability property ensures that once a transaction is committed, its changes are permanently stored in the database, even in the case of a system failure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the COMMIT command do in a transaction?

A

The COMMIT command in a transaction saves all changes made during the transaction to the database permanently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the ROLLBACK command do in a transaction?

A

The ROLLBACK command in a transaction undoes all changes made since the beginning of the transaction or since a savepoint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are transaction isolation levels?

A

Transaction isolation levels define the degree to which transactions are isolated from each other in terms of visibility of data changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the ‘Read Uncommitted’ isolation level?

A

The Read Uncommitted isolation level allows a transaction to read uncommitted changes made by other transactions, potentially leading to dirty reads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the ‘Read Committed’ isolation level?

A

The Read Committed isolation level ensures that a transaction can only read committed data changes made by other transactions, avoiding dirty reads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the ‘Repeatable Read’ isolation level?

A

The Repeatable Read isolation level ensures that if a transaction reads the same data multiple times, the data remains consistent throughout the transaction, preventing non-repeatable reads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the ‘Serializable’ isolation level?

A

The Serializable isolation level ensures complete isolation from other transactions, preventing dirty reads, non-repeatable reads, and phantom reads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Which isolation level offers the highest level of data integrity?

A

The Serializable isolation level offers the highest level of data integrity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is an aggregate function in SQL?

A

An aggregate function in SQL performs a calculation on a set of values and returns a single value, such as SUM or AVG.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does the COUNT function do?

A

The COUNT function returns the number of rows in a set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does the SUM function do?

A

The SUM function returns the total sum of a numeric column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does the AVG function do?

A

The AVG function returns the average value of a numeric column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does the MAX function do?

A

The MAX function returns the maximum value from a set of values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What does the MIN function do?

A

The MIN function returns the minimum value from a set of values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a scalar function in SQL?

A

A scalar function in SQL returns a single value based on the input values, such as UPPER or LOWER.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does the UPPER function do?

A

The UPPER function converts a string to uppercase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does the LOWER function do?

A

The LOWER function converts a string to lowercase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What does the LEN function do?

A

The LEN function returns the length of a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What does the ROUND function do?

A

The ROUND function rounds a numeric value to a specified number of decimal places.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What does the GETDATE function return?

A

The GETDATE function returns the current date and time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is a sequence in SQL?

A

A sequence in SQL is an object that generates a sequence of numeric values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

How is a sequence created in SQL?

A

A sequence is created using the CREATE SEQUENCE statement in SQL.

29
Q

What is the purpose of a sequence in database management?

A

The purpose of a sequence in database management is to automatically generate unique values, often for primary keys.

30
Q

How can you retrieve the next value of a sequence in SQL?

A

You can retrieve the next value of a sequence in SQL using the NEXTVAL keyword.

31
Q

What is the difference between a sequence and an auto-increment?

A

The difference between a sequence and an auto-increment is that a sequence is more flexible and can be used across multiple tables, while auto-increment is tied to a single column in a table.

31
Q

What is a trigger in a database?

A

A trigger in a database is a stored procedure that is automatically executed in response to certain events on a table, such as insertions or updates.

32
Q

What is a BEFORE trigger?

A

A BEFORE trigger is fired before an event occurs on a table.

33
Q

What is an AFTER trigger?

A

An AFTER trigger is fired after an event occurs on a table.

34
Q

What is an INSTEAD OF trigger?

A

An INSTEAD OF trigger is fired in place of an event, allowing you to override the default behavior.

35
Q

What are common use cases of triggers?

A

Common use cases of triggers include auditing changes, enforcing business rules, and updating related tables.

35
Q

What is a User Defined Function (UDF)?

A

A User Defined Function (UDF) is a function created by a user to perform specific calculations or actions within SQL queries.

36
Q

What are the benefits of using UDFs in SQL?

A

Benefits of using UDFs in SQL include reusability, modularity, and the ability to perform complex calculations within queries.

37
Q

What is the difference between a UDF and a stored procedure?

A

The difference between a UDF and a stored procedure is that a UDF can be used within SQL queries like a scalar function, while a stored procedure cannot.

38
Q

How do you create a UDF in SQL?

A

You create a UDF in SQL using the CREATE FUNCTION statement.

39
Q

What is a stored procedure in a database?

A

A stored procedure in a database is a precompiled set of one or more SQL statements stored under a name and executed as a unit.

40
Q

What are the benefits of using stored procedures?

A

Benefits of using stored procedures include better performance, reusability, and security.

40
Q

How do you pass parameters to a stored procedure?

A

You pass parameters to a stored procedure using input, output, or both types of parameters defined in the procedure.

40
Q

How do you create a stored procedure in SQL?

A

You create a stored procedure in SQL using the CREATE PROCEDURE statement.

41
Q

What is the Optional class in Java used for?

A

The Optional class in Java is used to represent a value that may or may not be present.

42
Q

How do you create an empty Optional in Java?

A

You create an empty Optional in Java using Optional.empty().

43
Q

How do you check if a value is present in an Optional?

A

You check if a value is present in an Optional using the isPresent() method.

44
Q

What is the purpose of Optional.of() in Java?

A

The purpose of Optional.of() in Java is to create an Optional with a non-null value.

45
Q

How can Optional.ifPresent() be used?

A

Optional.ifPresent() can be used to execute a block of code if a value is present.

46
Q

What is the Stream API in Java?

A

The Stream API in Java is used to process collections of objects in a functional style.

47
Q

What are the two types of operations in the Stream API?

A

The two types of operations in the Stream API are intermediate operations (e.g., map, filter) and terminal operations (e.g., forEach, reduce).

48
Q

How do you create a stream from a collection in Java?

A

You create a stream from a collection in Java using the stream() method.

49
Q

What is the difference between map and filter in the Stream API?

A

The difference between map and filter in the Stream API is that map transforms elements, while filter selects elements based on a condition.

50
Q

What does the reduce method do in the Stream API?

A

The reduce method in the Stream API combines elements of a stream into a single result.

51
Q

What is the Reflection API in Java?

A

The Reflection API in Java allows programs to inspect and manipulate classes, methods, and fields at runtime.

52
Q

What is the main use of the Reflection API?

A

The main use of the Reflection API is for dynamic class loading, inspecting or modifying the behavior of methods and fields at runtime.

53
Q

How can you obtain a class object using reflection?

A

You can obtain a class object using reflection with Class.forName(“ClassName”).

53
Q

How can you get methods of a class using the Reflection API?

A

You can get methods of a class using the getMethods() or getDeclaredMethods() method in the Reflection API.

54
Q

What are some risks of using reflection?

A

Risks of using reflection include performance overhead and possible violation of encapsulation.

54
Q

What is the Thread class in Java?

A

The Thread class in Java represents a thread of execution.

55
Q

How do you start a new thread in Java using the Thread class?

A

You start a new thread in Java using the start() method of the Thread class.

55
Q

What method is used to stop a thread in Java?

A

The method used to stop a thread in Java is interrupt(), though thread stopping is generally managed via a flag.

56
Q

What is the difference between run() and start() in threads?

A

The difference between run() and start() is that start() creates a new thread, while run() simply executes code on the current thread.

57
Q

What is the Runnable interface in Java?

A

The Runnable interface in Java represents a task that can be executed by a thread.

57
Q

How is Runnable different from Thread?

A

Runnable is different from Thread in that Runnable is an interface for defining tasks, while Thread is a class that executes tasks.

57
Q

How do you implement the Runnable interface in Java?

A

You implement the Runnable interface in Java by creating a class that implements Runnable and providing the run() method.

58
Q

What are the different states of a thread in Java?

A

The different states of a thread in Java are NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED.

59
Q

What is the ‘NEW’ thread state in Java?

A

The NEW thread state is when a thread is created but has not started execution.

60
Q

What is the ‘RUNNABLE’ thread state in Java?

A

The RUNNABLE thread state is when a thread is executing or ready to execute.

61
Q

What is the ‘BLOCKED’ thread state in Java?

A

The BLOCKED thread state is when a thread is waiting to acquire a lock.

62
Q

What is the ‘WAITING’ thread state in Java?

A

The WAITING thread state is when a thread is waiting indefinitely for another thread to perform a particular action.

63
Q

What is the ‘TERMINATED’ thread state in Java?

A

The TERMINATED thread state is when a thread has completed execution.

64
Q

What is multithreading in Java?

A

Multithreading in Java allows multiple threads to execute concurrently, sharing resources.

65
Q

How does multithreading improve performance in Java?

A

Multithreading improves performance by allowing tasks to be executed simultaneously, making better use of CPU resources.

66
Q

What is the main challenge of multithreading?

A

The main challenge of multithreading is managing shared resources and avoiding conflicts like race conditions.

67
Q

What is synchronization in Java?

A

Synchronization in Java ensures that only one thread can access a shared resource at a time.

68
Q

Why is synchronization necessary in multithreaded programs?

A

Synchronization is necessary in multithreaded programs to prevent data corruption and inconsistent states.

69
Q

How do you synchronize a method in Java?

A

You synchronize a method in Java by using the synchronized keyword.

70
Q

What is a synchronized block in Java?

A

A synchronized block in Java allows you to synchronize only part of a method, rather than the whole method.

71
Q

What is a deadlock in Java?

A

A deadlock in Java occurs when two or more threads are blocked forever, each waiting on the other to release a resource.

72
Q

How does a deadlock occur in Java?

A

A deadlock occurs in Java when two threads hold locks on resources and each waits for the other to release its lock.

72
Q

What are the conditions required for a deadlock to occur?

A

The conditions required for a deadlock to occur are mutual exclusion, hold and wait, no preemption, and circular wait.

73
Q

How can you prevent deadlocks in Java?

A

You can prevent deadlocks in Java by avoiding circular wait conditions and using lock hierarchies.

74
Q

What is a livelock in Java?

A

A livelock in Java occurs when two threads keep responding to each other’s actions, but neither can proceed.

75
Q

How is a livelock different from a deadlock?

A

A livelock differs from a deadlock in that in a livelock, threads are actively trying to resolve the situation, but both fail, while in a deadlock, threads are simply stuck.

76
Q

What are the possible solutions for livelocks?

A

Solutions for livelocks include introducing randomness or retries with delays in actions.

77
Q

What is the Producer-Consumer problem in Java?

A

The Producer-Consumer problem in Java is a classic synchronization problem where producers create data and consumers consume it.

78
Q

How do you solve the Producer-Consumer problem using threads?

A

You solve the Producer-Consumer problem using threads by implementing synchronization techniques like wait() and notify().

79
Q

What is the role of synchronization in solving the Producer-Consumer problem?

A

Synchronization ensures that the producer and consumer threads do not access the shared resource (e.g., a buffer) at the same time.

80
Q

What is a bounded buffer in the Producer-Consumer problem?

A

A bounded buffer in the Producer-Consumer problem is a fixed-size data structure where producers place items and consumers retrieve them.