background preloader

Database

Facebook Twitter

iBATIS, Hibernate, and JPA: Which is right for you? Object-relational mapping in Java is a tricky business, and solutions like JDBC and entity beans have met with less than overwhelming enthusiasm. But a new generation of ORM solutions has since emerged. These tools allow for easier programming and a closer adherence to the ideals of object-oriented programming and multi-tiered architectural development. Learn how Hibernate, iBATIS, and the Java Persistence API compare based on factors such as query-language support, performance, and portability across different relational databases. In this article we introduce and compare two of the most popular open source persistence frameworks, iBATIS and Hibernate. We also discuss the Java Persistence API (JPA). If you are a beginning Java programmer new to persistence concepts, reading this article will serve as a primer to the topic and to the most popular open source persistence solutions.

There are different ways to achieve persistence. iBATIS, Hibernate, and JPA: Which is right for you? What is Normalization? 1NF, 2NF, 3NF & BCNF with Examples. What is Normalization? 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 link them using relationships. In this tutorial, you will learn- The inventor of the relational model Edgar Codd proposed the theory of normalization with the introduction of First Normal Form and he continued to extend theory with Second and Third Normal Form.

Later he joined with Raymond F. Theory of Data Normalization in Sql is still being developed further. Database Normalization Examples - Assume a video library maintains a database of movies rented out. Table 1 Here you see Movies Rented column has multiple values. Database Normal Forms Now let's move in to 1st Normal Forms 1NF (First Normal Form) Rules Each table cell should contain single value. The above table in 1NF- 1NF Exmple Table 1 : In 1NF Form Before we proceed lets understand a few things -- What is a KEY ? What is a primary Key? Summary. Memo: Avoid Nested Queries in MySQL at all costs | Down Home Country Coding With Scott Selikoff and Jeanne Boyarsky. Some of my readers may be aware that nested subqueries such as “SELECT * FROM widgets WHERE id IN (SELECT …)”, don’t work all that well in MYSQL.

While the syntax is usually correct, the performance issues in practice can be horrendous. This article delves deeper into this issue, and why MySQL performs so poorly with nested subqueries, but not so deep as to drive us all crazy. Background The first complex query I learned how to write was a nested subquery, or just nested query for short.

In the example above, we first query the widgetOrders table for all unique widgets that have been sold based on widgetId (the DISTINCT doesn’t change the output of the query, but can help performance). First off, why do people like nested queries? So why is this scarier? Why nested joins are bad in theory The first big question of this article revolves around how query optimizers work. This brings us to nested queries. Why nested joins are really bad in MySQL But Scott, I need a nested query! The Future. Memo: Avoid Nested Queries in MySQL at all costs | Down Home Country Coding With Scott Selikoff and Jeanne Boyarsky. Five simple database design tips. A flawed database can affect all areas of your application, so getting the design right is of paramount importance.

Check out Builder's five simple design tips, and share some of your own. If an enterprise’s data is its lifeblood, then the database design can be the most important part of an application. Volumes have been written on this topic, and entire college degrees have been built around it. However, as has been said time and time again here on Builder.com, there’s no teacher like experience. I’ll get the show started by listing my five favorite tips and giving a brief explanation of the rationale behind each one. If you have a general design tip (try not to be specific to a particular system) you’d like to share, post it to the discussion. Where possible, explain the reasoning behind your tip by including an example or anecdote.

Unless you are using a system that restricts you to short field names, make them as descriptive as possible—within reason, of course. A Visual Explanation of SQL Joins. I love the concept, though, so let's see if we can make it work. Assume we have the following two tables. Table A is on the left, and Table B is on the right. We'll populate them with four records each. id name id name -- ---- -- ---- 1 Pirate 1 Rutabaga 2 Monkey 2 Pirate 3 Ninja 3 Darth Vader 4 Spaghetti 4 Ninja Let's join these tables by the name field in a few different ways and see if we can get a conceptual match to those nifty Venn diagrams. There's also a cartesian product or cross join, which as far as I can tell, can't be expressed as a Venn diagram: SELECT * FROM TableA CROSS JOIN TableB This joins "everything to everything", resulting in 4 x 4 = 16 rows, far more than we had in the original sets. A Visual Explanation of SQL Joins. Ten Common SQL Programming Mistakes.

Database delivery patterns & practices STAGE 2 Continuous Integration: Fundamentals It is not always easy to spot "antipatterns" in your SQL, especially in more complex queries. In this article, Plamen demonstrates some of the most common SQL coding errors that he encounters, explains their root cause, and illustrates potential solutions. Programming in SQL can be both a fun and a challenging task. My intention with this article was to highlight some of the more common mistakes that I've seen people make when coding SQL. SELECT TOP(10) mistake FROM CommonSQLProgrammingMistakes Without further ado, here is the list: NULLs and the NOT IN predicate Functions on indexed columns in predicates Incorrect subquery column Data type mismatch in predicates Predicate evaluation order Outer joins and placement of predicates Subqueries that return more than one value Use of SELECT * Scalar user-defined functions Overuse of cursors Colors table: color Black Blue Green Red Products table: 1 Ball Red 2 Bike Blue.

How to share data between stored procedures. An SQL text by Erland Sommarskog, SQL Server MVP. Most recent update 2013-11-02. Introduction This article tackles two related questions: How can I use the result set from one stored procedure in another, also expressed as How can I use the result set from a stored procedure in a SELECT statement? In this text I will discuss a number of possible solutions and point out their advantages and drawbacks. Here is a summary of the methods that I will cover. At the end of the article, I briefly discuss the particular situation when your stored procedures are on different servers, which is a quite challenging situation.

A related question is how to pass table data from a client, but this is a topic which is outside the scope for this text. Examples in the article featuring tables such as authors, titles, sales etc run in the old sample database pubs. OUTPUT Parameters This method can only be used when the result set is one single row. Rewrite this procedure as: Table-valued Functions Inline Functions.

Using Connection String Keywords with SQL Server Native Client. There are two ways OLE DB applications can initialize data source objects: IDBInitialize::Initialize IDataInitialize::GetDataSource In the first case, a provider string can be used to initialize connection properties by setting the property DBPROP_INIT_PROVIDERSTRING in the DBPROPSET_DBINIT property set.

In the second case, an initialization string can be passed to IDataInitialize::GetDataSource method to initialize connection properties. Both methods initialize the same OLE DB connection properties, but different sets of keywords are used. The set of keywords used by IDataInitialize::GetDataSource is at minimum the description of properties within the initialization property group. Any provider string setting that has a corresponding OLE DB property set to some default value or explicitly set to a value, the OLE DB property value will override the setting in the provider string. connection-string ::= empty-string[;] | attribute[;] | attribute; connection-string empty-string ::= Five simple database design tips. Ten Common Database Design Mistakes. No list of mistakes is ever going to be exhaustive. People (myself included) do a lot of really stupid things, at times, in the name of “getting it done.”

This list simply reflects the database design mistakes that are currently on my mind, or in some cases, constantly on my mind. I have done this topic two times before. If you’re interested in hearing the podcast version, visit Greg Low’s super-excellent SQL Down Under. Before I start with the list, let me be honest for a minute. So, the list: Poor design/planning Ignoring normalization Poor naming standards Lack of documentation One table to hold all domain values Using identity/guid columns as your only key Not using SQL facilities to protect data integrity Not using stored procedures to access data Trying to build generic objects Lack of testing Poor design/planning “If you don’t know where you are going, any road will take you there” – George Harrison Ignoring Normalization Are there always 12 payments?

Poor naming standards Security.