Section 1

Preview this deck

What are nested queries/subqueries and why do we use them?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (26)

Section 1

(26 cards)

What are nested queries/subqueries and why do we use them?

Front

A Subquery or Inner query or a Nested query is a query within another SQL query and embedded within the WHERE clause. A subquery is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved. Subqueries can be used with the SELECT, INSERT, UPDATE, and DELETE statements along with the operators like =, <, >, >=, <=, IN, BETWEEN, etc. These must be in (), Ex. SELECT * FROM CUSTOMERS WHERE ID IN (SELECT ID FROM CUSTOMERS WHERE SALARY > 4500) ;

Back

What are triggers and when can I set them to activate?

Front

Triggers are stored programs, which are automatically executed or fired when some events occur. Triggers are, in fact, written to be executed in response to any of the following events − A database manipulation (DML) statement (DELETE, INSERT, or UPDATE) A database definition (DDL) statement (CREATE, ALTER, or DROP).

Back

What is the DAO pattern?

Front

Data Access Object Pattern or DAO pattern is used to separate low level data accessing API or operations from high level business services. Following are the participants in Data Access Object Pattern. Design components BusinessObject : The BusinessObject represents the data client. It is the object that requires access to the data source to obtain and store data. A BusinessObject may be implemented as a session bean, entity bean or some other Java object in addition to a servlet or helper bean that accesses the data source. DataAccessObject : The DataAccessObject is the primary object of this pattern. The DataAccessObject abstracts the underlying data access implementation for the BusinessObject to enable transparent access to the data source. DataSource : This represents a data source implementation. A data source could be a database such as an RDBMS, OODBMS, XML repository, flat file system, and so forth. A data source can also be another system service or some kind of repository. TransferObject : This represents a Transfer Object used as a data carrier. The DataAccessObject may use a Transfer Object to return data to the client. The DataAccessObject may also receive the data from the client in a Transfer Object to update the data in the data source.

Back

Constraints

Front

They are constraints placed upon a column of a table within the DDL portion. (Create, Alter). There are many types of constraints. NOT NULL - Makes sure that the value inputted is not null UNIQUE- Makes sure that all values are distinct from one another PRIMARY KEY- Combination of UNIQUE and NOT NULL FOREIGN KEY- Makes it so that the value is uniquely identified as a value from another table CHECK- Makes it so the value passes some sort of condition DEFAULT- Presets a default for a void insert INDEX- Makes it run fast

Back

What is the difference between clustered and unclustered indexes?

Front

Clustered Index Only one per table Faster to read than non clustered as data is physically stored in index order Non Clustered Index Can be used many times per table Quicker for insert and update operations than a clustered index

Back

How do you prevent SQL injection in JDBC?

Front

Prepared Statements

Back

What are indexes?

Front

The CREATE INDEX statement is used to create indexes in tables. Indexes are used to retrieve data from the database very fast. The users cannot see the indexes, they are just used to speed up searches/queries by giving the query several reference points like an index in a book

Back

What are cursors?

Front

A cursor is a temporary work area created in the system memory when a SQL statement is executed. A cursor contains information on a select statement and the rows of data accessed by it. This temporary work area is used to store the data retrieved from the database, and manipulate this data. A cursor can hold more than one row, but can process only one row at a time. The set of rows the cursor holds is called the active set.

Back

What is the difference between WHERE and HAVING?

Front

WHERE Clause helps you to filter out records based on the data available in a Database table. E.G. Select Population from state where city = 'NEW YORK'. New York is a value stored in the table State. And we get the population of New York by including the above filter. HAVING Clause on the other hand helps you to filter records on the basis of results of Aggregation Functions (i.e. Group By clause) E.G. Select State and Total Population from state where sum(population) is greater than 10000. The table state has three columns State, City and Population. Now as you can see, there is no column to store population agaist the state. So we take sum of population for different states, and then filter on the basis of that sum.

Back

What is an ERD?

Front

An Entity Relationship Diagram (ERD) is a snapshot of data structures. An Entity Relationship Diagram shows entities (tables) in a database and relationships between tables within that database. For a good database design it is essential to have an Entity Relationship Diagram. There are three basic elements in ER-Diagrams: Entities are the "things" for which we want to store information. An entity is a person, place, thing or event. Attributes are the data we want to collect for an entitiy. Relationships describe the relations between the entities.

Back

What are the JDBC interfaces?

Front

Back

How do you add a column to a table?

Front

ALTER TABLE table_name ADD column_name column_definition; Ex. ALTER TABLE employees ADD last_name VARCHAR(50);

Back

What are aggregate and scalar functions?

Front

Aggregate functions: These functions are used to do operations from the values of the column and a single value is returned. AVG() COUNT() FIRST() LAST() MAX() MIN() SUM() Scalar functions: These functions are based on user input, these too returns single value. UCASE() LCASE() MID() LEN() ROUND() NOW() FORMAT()

Back

Why create a DAO interface?

Front

Back

Explain multi-version concurrency control and what it is used for.

Front

It is a way to separate code into blocks while working upon the same database. The blocked code will not render until it is completed, making so that each person working within the database has their own version of the database until it is updated by pushing the block method once it is completed

Back

What is a View?

Front

In SQL, a view is a virtual table based on the result-set of an SQL statement. A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single table. Ex. CREATE VIEW [view_name] AS SELECT column, column, ... FROM table_name WHERE condition;

Back

Normalization

Front

Normalization is a database design technique which organizes tables in a manner that reduces redundancy and dependency of data. It divides larger tables to smaller tables and links them using relationships.

Back

How to get a connection in JDBC?

Front

Back

What is referential Integrity

Front

It is a relational database concept which basically says that within relationships between tables must always be consistent. The relationship between Primary and Foreign must be consistent.

Back

How are tables related/connected to each other in a relational database?

Front

In a relational database, the information about customers is entered only once, in a table that both departments can access. A relational database is a set of related tables. You use primary and foreign keys to describe relationships between the information in different tables.

Back

Union vs Join

Front

Visually, a union would add all the data into one column, while a join displays them side by side.

Back

What is JDBC? What is its package name? What kind of exceptions does it throw?

Front

Back

Order By vs Group By?

Front

Group By is a statement used after the WHERE of a SELECT statement. It groups the pulled data by a certain column value, and is usually used with other key-words such as MAX, SUM, MIN, AVG, COUNT Order By is a statement used, usually after Group By, which sorts the given data by ascending, or descending order

Back

Difference between Statement, PreparedStatement, and CallableStatement?

Front

Once a connection is obtained we can interact with the database. The JDBC Statement, CallableStatement, and PreparedStatement interfaces define the methods and properties that enable you to send SQL or PL/SQL commands and receive data from your database. They also define methods that help bridge data type differences between Java and SQL data types used in a database. Statement--Use this for general-purpose access to your database. Useful when you are using static SQL statements at runtime. The Statement interface cannot accept parameters. PreparedStatement--Use this when you plan to use the SQL statements many times. The PreparedStatement interface accepts input parameters at runtime. CallableStatement--Use this when you want to access the database stored procedures. The CallableStatement interface can also accept runtime input parameters.

Back

What are the transaction isolation levels and what anomalies do they protect against?

Front

As we know that, in order to maintain consistency in a database, it follows ACID properties. Among these four properties (Atomicity, Consistency, Isolation and Durability) Isolation determines how transaction integrity is visible to other users and systems. It means that a transaction should take place in a system in such a way that it is the only transaction that is accessing the resources in a database system. Isolation levels define the degree to which a transaction must be isolated from the data modifications made by any other transaction in the database system. A transaction isolation level is defined by the following phenomena - Dirty Read - A Dirty read is the situation when a transaction reads a data that has not yet been committed. For example, Let's say transaction 1 updates a row and leaves it uncommitted, meanwhile, Transaction 2 reads the updated row. If transaction 1 rolls back the change, transaction 2 will have read data that is considered never to have existed. Non Repeatable read - Non Repeatable read occurs when a transaction reads same row twice, and get a different value each time. For example, suppose transaction T1 reads data. Due to concurrency, another transaction T2 updates the same data and commit, Now if transaction T1 rereads the same data, it will retrieve a different value. Phantom Read - Phantom Read occurs when two same queries are executed, but the rows retrieved by the two, are different. For example, suppose transaction T1 retrieves a set of rows that satisfy some search criteria. Now, Transaction T2 generates some new rows that match the search criteria for transaction T1. If transaction T1 re-executes the statement that reads the rows, it gets a different set of rows this time. Based on these phenomena, The SQL standard defines four isolation levels : Read Uncommitted - Read Uncommitted is the lowest isolation level. In this level, one transaction may read not yet committed changes made by other transaction, thereby allowing dirty reads. In this level, transactions are not isolated from each other. Read Committed - This isolation level guarantees that any data read is committed at the moment it is read. Thus it does not allows dirty read. The transaction holds a read or write lock on the current row, and thus prevent other transactions from reading, updating or deleting it. Repeatable Read - This is the most restrictive isolation level. The transaction holds read locks on all rows it references and writes locks on all rows it inserts, updates, or deletes. Since other transaction cannot read, update or delete these rows, consequently it avoids non-repeatable read. Serializable - This is the Highest isolation level. A serializable execution is guaranteed to be serializable. Serializable execution is defined to be an execution of operations in which concurrently executing transactions appears to be serially executing.

Back

Difference between implicit and explicit cursors?

Front

SQL declares a cursor implicitly for all SQL data manipulation statements, including queries that return only one row. ... Explicit cursors are used to process multi-row SELECT statements An implicit cursor is used to process INSERT, UPDATE, DELETE and single row SELECT. . INTO statements.

Back