Database and Data Access Flashcards

1
Q

What is ADO.NET?

A

ADO.NET is a data access technology in .NET that provides a set of classes for connecting to databases, executing queries, and managing data.

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

How does ADO.NET manage data access?

A

ADO.NET uses data providers to connect to various types of data sources. The core data providers are SqlConnection for SQL Server, OleDbConnection for OLE DB, and OracleConnection for Oracle.

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

Explain the difference between DataSet and DataReader in ADO.NET.

A

DataSet is an in-memory representation of data that supports relational data, relationships, and multiple tables. DataReader is a forward-only, read-only stream of data that’s more memory-efficient for reading large datasets.

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

What is Entity Framework (EF)?

A

Entity Framework is an Object-Relational Mapping (ORM) framework that simplifies database access by allowing you to work with database entities as if they were regular .NET objects.

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

What are the different approaches for working with EF?

A

EF supports two approaches: Database-First (where the database schema is generated from the existing database) and Code-First (where the database schema is generated from your C# classes).

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

What is a SQL JOIN?

A

A SQL JOIN combines rows from two or more tables based on a related column between them. Common types include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN.

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

Explain stored procedures in the context of databases.

A

A stored procedure is a precompiled set of one or more SQL statements that can be executed by calling the procedure’s name. They offer reusability, security, and performance benefits.

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

What is an ORM?

A

ORM stands for Object-Relational Mapping. It’s a technique for mapping database tables and relationships to programming language objects, making database interactions more object-oriented.

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

How does Entity Framework handle lazy loading?

A

Lazy loading is a technique where related entities are loaded from the database only when accessed for the first time. EF supports lazy loading through proxy objects.

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

What is the purpose of the DbContext class in Entity Framework?

A

The DbContext class is the main entry point to the Entity Framework. It represents the session with the database and provides methods to query, insert, update, and delete data.

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

What is the Entity Framework Core (EF Core)?

A

EF Core is a lightweight and cross-platform version of Entity Framework, designed for building applications that run on .NET Core and .NET 5+.

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

How does Entity Framework Core differ from Entity Framework (EF)?

A

EF Core is a reimagined and modernized version of EF, with improved performance, support for different platforms, and a simplified API. It’s optimized for microservices and cloud-based applications.

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

What are migrations in Entity Framework?

A

Migrations are a way to manage database schema changes over time. They allow you to apply changes to the database schema as your model evolves.

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

What is LINQ to SQL?

A

LINQ to SQL is a component of ADO.NET that allows you to use LINQ (Language Integrated Query) syntax to query and manipulate SQL Server databases.

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

Explain the concept of database normalization.

A

Database normalization is the process of organizing a database’s schema to reduce data redundancy and improve data integrity. It involves breaking down tables into smaller, related tables.

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

How can you prevent SQL injection when executing raw SQL queries in ADO.NET or Entity Framework?

A

To prevent SQL injection, use parameterized queries. Parameters ensure that user input is treated as values and not executable code.

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

What is the purpose of an Object-Relational Mapping (ORM) tool like Entity Framework?

A

An ORM simplifies the process of interacting with databases by abstracting the details of SQL queries and providing a higher-level, object-oriented interface for database operations.

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

How can you optimize database performance in Entity Framework applications?

A

Optimize performance by minimizing the number of database queries, using appropriate indexes, avoiding the N+1 query problem, and using appropriate caching strategies.

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

Explain the concept of a database transaction.

A

A database transaction is a sequence of one or more SQL statements executed as a single unit of work. It ensures data integrity by either committing all changes or rolling them back if an error occurs.

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

What is the difference between an INNER JOIN and a LEFT JOIN?

A

An INNER JOIN returns only the matching rows from both tables based on the specified condition. A LEFT JOIN returns all rows from the left table and matching rows from the right table, filling in with NULLs where no match is found.

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

Explain the purpose of a foreign key in a database.

A

A foreign key establishes a link between two tables by referencing the primary key of another table. It enforces referential integrity and maintains relationships between data.

22
Q

What are the advantages of using stored procedures over inline SQL queries?

A

Stored procedures provide encapsulation, security, and performance benefits. They can be precompiled, cached, and centrally managed.

23
Q

Describe the ACID properties of a database transaction.

A

ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure that transactions are reliable, consistent, and maintain data integrity.

24
Q

What is lazy loading in Entity Framework?

A

Lazy loading is a feature in EF that delays the loading of related entities until they are explicitly accessed. This can help improve performance by reducing unnecessary data retrieval.

24
Q

Explain the concept of connection pooling.

A

Connection pooling involves reusing database connections to reduce the overhead of opening and closing connections. It enhances the performance of database interactions.

24
Q

How can you improve Entity Framework performance when dealing with a large number of entities?

A

Use paging techniques to limit the number of retrieved records, implement proper indexing, utilize caching mechanisms, and consider asynchronous programming for responsiveness.

24
Q

What is the role of a DataAdapter in ADO.NET?

A

A DataAdapter acts as a bridge between a dataset and a data source. It facilitates data retrieval and manipulation between the dataset and the database.

25
Q

Explain the concept of code-first migrations in Entity Framework.

A

Code-first migrations allow you to create and update the database schema based on changes to your C# classes. Migrations are generated based on the differences between the model and the existing schema.

26
Q

What is a self-referencing table in a database?

A

A self-referencing table is a table that has a foreign key column referencing its own primary key column. This can be used to represent hierarchical or recursive relationships.

27
Q

What is database indexing, and why is it important?

A

Database indexing is a technique that improves data retrieval speed by creating optimized data structures. Indexes allow the database system to quickly locate rows based on specific column values.

28
Q

What is the Entity Framework Database First approach?

A

The Database First approach involves generating C# classes and a model based on an existing database schema. It’s suitable when working with an existing database that you want to integrate into your application.

29
Q

How does Entity Framework handle database relationships and navigation properties?

A

EF uses navigation properties to define relationships between entities. These properties allow you to navigate from one entity to another without writing explicit SQL queries.

30
Q

What is the purpose of a connection string in ADO.NET or Entity Framework?

A

A connection string contains information needed to connect to a database. It includes details like the database server’s address, credentials, and database name.

31
Q

What is SQL Injection, and how can you prevent it?

A

SQL Injection is a security vulnerability where malicious SQL code is injected into input fields. Prevent it by using parameterized queries or prepared statements to sanitize user input.

32
Q

Explain the concept of LINQ (Language Integrated Query).

A

LINQ is a feature in C# that allows you to write queries against collections, databases, XML, and more using a consistent syntax. It brings query capabilities directly into the language.

33
Q

What is normalization, and how does it relate to database design?

A

Normalization is the process of organizing data in a database to minimize redundancy and dependency issues. It helps maintain data integrity and reduces anomalies.

34
Q

How can you ensure data consistency when dealing with multiple related tables in a database?

A

Use transactions to group related operations into a single unit of work. Transactions ensure that either all changes are applied or none of them are, maintaining data integrity.

35
Q

Explain the concept of database denormalization and when it might be used.

A

Denormalization involves intentionally introducing redundancy into a database design for performance optimization. It’s used when read performance is more critical than data modification efficiency.

36
Q

What are views in a database, and why are they used?

A

Views are virtual tables created by defining a SELECT statement. They simplify complex queries, abstract underlying table structures, and offer an additional security layer.

37
Q

What are the benefits of using an ORM like Entity Framework over writing raw SQL queries?

A

ORMs abstract away low-level database interactions, making code more readable and maintainable. They also provide a higher level of abstraction and support for various database systems.

38
Q

What is an identity column in a database table?

A

An identity column is a column that automatically generates unique values for each new row added to a table. It’s commonly used as a primary key.

39
Q

What is the role of the DatabaseContext in Entity Framework Code-First?

A

The DbContext class is the main entry point to the Entity Framework when using the Code-First approach. It represents the session with the database and manages interactions with it.

40
Q

Explain the concept of database indexes and their types.

A

Indexes are data structures that improve data retrieval efficiency. Types include clustered (determines the physical order of data) and non-clustered (additional data structure).

41
Q

What are stored procedures and how can they enhance database performance?

A

Stored procedures are precompiled sets of SQL statements that can be executed with a single call. They can reduce network traffic and improve security by centralizing data access logic.

42
Q

How can you handle database concurrency issues when multiple users are modifying the same data simultaneously?

A

Techniques include optimistic concurrency (using version numbers or timestamps) and pessimistic concurrency (using locks) to prevent conflicting changes.

43
Q

Explain the concept of LINQ to Entities in Entity Framework.

A

LINQ to Entities allows you to use LINQ queries to retrieve data from a database through EF. The LINQ query is translated into SQL and executed on the database.

44
Q

What is the purpose of the Database class in Entity Framework?

A

The Database class in EF provides methods for working directly with the database, such as creating, deleting, and checking for its existence

45
Q

What are transactions in database operations, and why are they important?

A

Transactions ensure the atomicity and consistency of multiple related database operations. They either complete all changes or roll them back if an error occurs.

46
Q

Explain the difference between a primary key and a unique key in a database.

A

A primary key uniquely identifies a row in a table and ensures data integrity. A unique key enforces uniqueness but doesn’t necessarily serve as the primary identifier for a row.

47
Q

Explain the concept of database connection pooling and its benefits.

A

Database connection pooling is a technique where a pool of database connections is maintained and reused to minimize the overhead of opening and closing connections. This improves application performance by reducing the time required to establish a new connection each time.

48
Q
A
49
Q
A