QuickRef.org - all your docs are belong to us - PHP, Perl, CSS, HTML, Java, JavaScript, MySQL, Ruby, Python, and more
Converting a delimited string of values into columns
I have seen a few questions asking how to transform a delimited values into columns, so I thought I would talk about it here. In most cases it is recommended to use a string parser function to split the string; however, today I want to talk about another method. This method takes advantage of the XML data type that was introduced in SQL Server 2005. What is nice about the XML data type is it preserves the document order. The document order is critical because it guarantees the string is kept in the same order when it is converted to XML. DECLARE @t TABLE( ProductId INT, ProductName VARCHAR(25), SupplierId INT, Descr VARCHAR(50) INSERT INTO @t VALUES (1,'Product1',1,'A1,10in,30in,2lbs'); INSERT INTO @t VALUES (2,'Product2',2,'T6,15in,30in,'); INSERT INTO @t VALUES (3,'Product3',1,'A2,1in,,0.5lbs'); Okay now we have our sample data, let’s talk about our data. Now that we have laid all the ground work, it is time to start building our query. [ProductId], [ProductName], [SupplierId], FROM @t FROM cte
Star schema
The star schema gets its name from the physical model's[2] resemblance to a star with a fact table at its center and the dimension tables surrounding it representing the star's points. Model[edit] The star schema separates business process data into facts, which hold the measurable, quantitative data about a business, and dimensions which are descriptive attributes related to fact data. Examples of fact data include sales price, sale quantity, and time, distance, speed, and weight measurements. Related dimension attribute examples include product models, product colors, product sizes, geographic locations, and salesperson names. A star schema that has many dimensions is sometimes called a centipede schema.[3] Having dimensions of only a few attributes, while simpler to maintain, results in queries with many table joins and makes the star schema less easy to use. Fact tables[edit] Fact tables record measurements or metrics for a specific event. Dimension tables[edit] Benefits[edit]
Optimizing Data Warehouse Query Performance Through Bitmap Filtering
Most data warehouse queries are designed to follow a star schema and can process hundreds of millions of rows in a single query. By default, the query optimizer detects queries against star schemas and creates efficient query plans for them. One method the optimizer can use to generate an efficient plan is to use bitmap filtering. A bitmap filter uses a compact representation of a set of values from a table in one part of the operator tree to filter rows from a second table in another part of the tree. In SQL Server 2008, bitmap filtering can be introduced in the query plan after optimization, as in SQL Server 2005, or introduced dynamically by the query optimizer during query plan generation. Optimized bitmap filtering is available only on the Enterprise, Developer, and Evaluation editions of SQL Server. The bitmap filter compares favorably to the bitmap index. Comparing Bitmap Filtering with Optimized Bitmap Filtering Optimized bitmap filters have the following advantages: Example
SQL Server Index Basics
Given the fundamental importance of indexes in databases, it always comes as a surprise how often the proper design of indexes is neglected. It often turns out that the programmer understands detail, but not the broad picture of what indexes do. Bob Sheldon comes to the rescue with a simple guide that serves either to remind or educate us all! One of the most important routes to high performance in a SQL Server database is the index. Indexes speed up the querying process by providing swift access to rows in the data tables, similarly to the way a book’s index helps you find information quickly within that book. Index Structures Indexes are created on columns in tables or views. You can create indexes on most columns in a table or a view. An index is made up of a set of pages (index nodes) that are organized in a B-tree structure. Figure 1: B-tree structure of a SQL Server index Clustered Indexes A clustered index stores the actual data rows at the leaf level of the index. Index Types
Versioning & Optimistic Locking in Hibernate - Intertech Blog
By Jim White (Directory of Training and Instructor) A few weeks ago while teaching Hibernate, a student (thanks Dan) asked me about whether version numbers can be generated by the database. The answer is – Yes, in some cases. I thought the question and an expanded discussion of Hibernate’s versioning property would be a good topic for this week’s blog entry. The <version> property (or @Version annotation) For those of you that use Hibernate today, you are probably aware that Hibernate can provide optimistic locking through a version property on your persistent objects. To specify a version for your persistent object, simply add a version (or timestamp) property in your mapping file and add a version attribute to your persistent class. For those using annotations, just mark the version property’s getter in the class with the @Version annotation. @Version public long getVersion() { return version; } Hibernate: /* update com.intertech.domain.Product */ update Product set version=?
Java Persistence/ElementCollection
JPA 2.0 defines an ElementCollection mapping. It is meant to handle several non-standard relationship mappings. An ElementCollection can be used to define a one-to-many relationship to an Embeddable object, or a Basic value (such as a collection of Strings). In JPA an ElementCollection relationship is defined through the @ElementCollection annotation or the <element-collection> element. The ElementCollection values are always stored in a separate table. Embedded Collections[edit] An ElementCollection mapping can be used to define a collection of Embeddable objects. The limitations of using an ElementCollection instead of a OneToMany is that the target objects cannot be queried, persisted, merged independently of their parent object. Example of an ElementCollection relationship database[edit] EMPLOYEE (table) PHONE (table) Example of an ElementCollection relationship annotations[edit] @Entitypublic class Employee { @Id @Column(name="EMP_ID") private long id; ... Basic Collections[edit]
java - How to load lazy fetched items from Hibernate/JPA in my controller
Divided We Stand: The SQL of Relational Division
Businesses often require reports that require more than the classic set operators. Surprisingly, a business requirement can often be expressed neatly in terms of the DIVISION relationship operator: How can this be done with SQL Server? Joe Celko opens up the 'Manga Guide to Databases', meets the Database Fairy, and is inspired to explain DIVISION. I’ve just got a copy of THE MANGA GUIDE TO DATABASES (ISBN 978-1-59327-190-9); it is one of a series of “Manga Guides” (the others are Calculus and Statistics). The book has a section on basic RDBMS in which they mention Codd’s eight original operations on tables. But the one in the collection that seems weird on first glance is relational division. The name “relational division” comes from the symbol for a Cartesian product (aka CROSS JOIN), which is X or multiplication. This is easier to explain with an example. CREATE TABLE PilotSkills(pilot_name CHAR(15) NOT NULL,plane_name CHAR(15) NOT NULL,PRIMARY KEY (pilot_name, plane_name)); 's3' 'p2'