Category Archives: SQL Server

Free ebook: Introducing Microsoft SQL Server 2008 R2

9780735693883f 2 246x300 Free ebook: Introducing Microsoft SQL Server 2008 R2Introduction

Download link “Introducing Microsoft SQL Server 2008 R2

Our purpose in Introducing Microsoft SQL Server 2008 R2 is to point out both
the new and the improved in the latest version of SQL Server. Because this
version is Release 2 (R2) of SQL Server 2008, you might think the changes are
relatively minor—more than a service pack, but not enough to justify an entirely
new version. However, as you read this book, we think you will find that there are a
lot of exciting enhancements and new capabilities engineered into SQL Server 2008 R2
that will have a positive impact on your applications, ranging from improvements
in operation to those in management. It is definitely not a minor release!

Who Is This Book For?

This book is for anyone who has an interest in SQL Server 2008 R2 and wants to
understand its capabilities. In a book of this size, we cannot cover every feature
that distinguishes SQL Server from other databases, and consequently we assume
that you have some familiarity with SQL Server already. You might be a database
administrator (DBA), an application developer, a power user, or a technical
decision maker. Regardless of your role, we hope that you can use this book to
discover the features in SQL Server 2008 R2 that are most beneficial to you.

How Is This Book Organized?

SQL Server 2008 R2, like its predecessors, is more than a database engine. It is a
collection of components that you can implement either separately or as a group
to form a scalable data platform. In broad terms, this data platform consists of
two types of components—those that help you manage data and those that help
you deliver business intelligence (BI). Accordingly, we have divided this book into
two parts to focus on the new capabilities for each of these areas.

Part I, “Database Administration,” is written with the DBA in mind and introduces
readers to the numerous innovations in SQL Server 2008 R2. Chapter 1, “SQL
Server 2008 R2 Editions and Enhancements,” discusses the key enhancements,
what’s new in the different editions of SQL Server 2008 R2, and the benefits of
running SQL Server 2008 R2 on Windows Server 2008 R2. In Chapter 2, “Multi-
Server Administration,” readers learn how centralized management capabilities
are improved with the introduction of the SQL Server Utility Control Point. Step-by-
step instructions show DBAs how to quickly designate a SQL Server instance as
a Utility Control Point and enroll instances for centralized multi-server management.
Chapter 3, “Data-Tier Applications,” focuses on how to streamline deployment
and manage and upgrade database applications with the new data-tier application
feature. Chapter 4, “High Availability and Virtualization Enhancements,”
covers high availability enhancements and includes step-by-step implementations
for ensuring business continuity with SQL Server 2008 R2, Windows Server 2008
R2, and Hyper-V Live Migration. Finally, in Chapter 5, “Consolidation and Monitoring,”
a discussion on consolidation strategies teaches readers how to improve
resource optimization. This chapter also explains how to use the new dashboard
and viewpoints to gain insight into application and database utilization, and it also
covers how to use capacity policy violations to help identify consolidation opportunities,
maximize investments, and ultimately maintain healthier systems.

In Part II, “Business Intelligence Development,” readers discover components
new to the SQL Server data platform, as well as significant enhancements to the
reporting component. Chapter 6, “Scalable Data Warehousing,” introduces the
data warehouse appliance known as SQL Server 2008 R2 Parallel Data Warehouse
by explaining its architecture, reviewing data layout strategies for optimal query
performance, and describing the integration points with SQL Server BI components.
In Chapter 7, “Master Data Services,” readers learn about master data
management concepts and the new Master Data Services component. Chapter 8,
“Complex Event Processing with StreamInsight,” describes scenarios that benefit
from complex event analysis, and it illustrates how to develop applications that
use the SQL Server StreamInsight engine for complex event processing. Chapter
9, “Reporting Services Enhancements,” reviews all the new features available in
SQL Server 2008 R2 Reporting Services that support self-service reporting and
address common report design problems. Last, Chapter 10, “Self-Service Analysis
with PowerPivot,” continues the theme of self-service by explaining how users can
integrate disparate data for analysis by using SQL Server PowerPivot for Excel, and
how to centralize and share the results of this analysis by using SQL Server Power-
Pivot for SharePoint.

Stored Procedure Optimization Tips

Great post by Pinal Dave! He shares some tips how to get most of the stored procedures.

Dont miss it here.

Top Features of MS SQL 2008

logo header sql08 dg Top Features of MS SQL 2008Microsoft SQL Server 2008 R2 is the latest release of SQL Server. This article will introduce the top 10 features and benefits of SQL Server 2008 R2. The “R2” tag indicates this is an intermediate release of SQL Server and not a major revision. However, there are a number of interesting new features for both DBAs and developers alike. At the time of this article, R2 is available as a CTP (Community Technology Preview). In addition to new features, there are two new editions as well, SQL Server 2008 R2 Datacenter and SQL Server 2008 R2 Parallel Data Warehouse.

Report Builder 3.0

Report Builder is a tool set for developing rich reports that can be delivered over the web. Some of the features of Report Builder include the ability to create reports containing graphs, charts, tables, and printing controls. In addition, Report Builder also supports drill downs and sorting. If you are familiar with the third party tool Crystal Reports, then you have good idea of what to expect from Report Builder.

New features in SQL 2008 R2 / Report Builder 3.0 include: Map Layers, which can hold spatial and analytical data and will integrate with Microsoft Virtual Earth. Indicators, these are gauges used to show the state of one value. Report Parts, this object can be reused or shared between multiple reports. Aggregate Calculating, this allows you to calculate the total value of other aggregate calculated totals.

SQL Server 2008 R2 Datacenter

The new Datacenter edition of SQL Server 2008 R2 is targeted towards Enterprise Edition users who require a greater performance platform. The new edition will support 256 logical processors, high numbers of instances, and as much memory as the operating system will support.

SQL Server 2008 R2 Parallel Data Warehouse

Another new SQL Server edition, Parallel Data Warehouse, formally codenamed “Madison”, specializes in handling extremely large amounts of data. This new version uses massively parallel processing to spread large tables over multiple SQL nodes. The multiple nodes are handled by a propriety Microsoft technology called Ultra Shared Nothing. This new technology is described as a Control Node spreading queries to Computer Nodes, evenly distributed, then collecting the results.

StreamInsight

New in SQL Server 2008 R2 is component called StreamInsight. This interesting component allows streaming data to be analyzed on the fly. Meaning the data is processed directly from the source stream prior to being saved in a SQL Server table. This could be extremely handy if you’re running a real time system and need to analyze data but can’t afford the latency of a committed write to a table first. Examples usually cited for this application include stock trading streams, click stream web analytics, and industrial process controls. Multiple input streams can be simultaneously monitored.

Master Data Services

Master Data Services (MDS) is both a concept and a product. The concept of a Master Data Service is that there is a central data gate keeper of core business data. Data items such as customer billing addresses, employee/customer names, and product names should be centrally managed so that all consuming applications have the same information. The Microsoft example given is a company that has a customer address record in the customer table but a different address in the mailing table. A Master Data Service application would ensure that all tables would have only one correct address. While an MDS can be a homegrown application, SQL Server 2008 R2 includes an application and an interface to manage the central data.

PowerPivot for SharePoint

PowerPivot is an end-user tool that works in conjunction with SharePoint, SQL Server 2008 R2, and Excel 2010 to process large amounts of data in seconds. PowerPivot works like an Excel Pivot Table, and includes analytical capabilities.

Data-Tier Application

A Data-Tier Application (abbreviated as DAC –no idea what the C stands for, and not to be confused with the Windows Data Access Components also abbreviated as DAC ) is an object that stores all the needed database information for a project, such as login, tables, and procedures into one package that can be consumed by Visual Studio. By creating a Data-Tier Application, a SQL Server package version could be saved with each Visual Studio build of your application. This would allow application code builds to be married to a database build in an easily managed way.

Unicode Compression

SQL Server 2008 R2 uses a new algorithm known as Simple Compression Scheme for Unicode storage. This reduces the amount of disk spaced used by Unicode characters. This new format happens automatically and is managed by the SQL Server engine so no programming changes are required of the DBA.

SQL Server Utility

The new SQL Server Utility is a repository object for centrally controlling multiple SQL Server instances. Performance data and configuration policies can be stored in a single Utility. The Utility also includes an Explorer tool where multi-server dashboards can be created.

Multi Server Dashboards

While the SQL Server Management Studio could always connection to multiple servers, each was managed independently with no central view of all of them. Now with SQL Server 2008 R2, Dashboards showing combined server data can be created.

Two interesting database related articles

logo header sql08 dg Two interesting database related articlesThe first one is about INSERT with SQL 2008 By Don Schlichting. Here is a short introduction.
This article will explore the various methods of using an INSERT statement with SQL Server 2008. After database Tables are created, a method to perform basic data manipulation tasks like inserting, modifying and deleting data is needed. Such data manipulation is accomplished through SQL Server’s own dialect of Structured Query Language (SQL) called Transact SQL or (T-SQL). TSQL Commands can be executed by typing them in directly to SQL Server, or graphically though the SQL Server Management Studio. The SQL Server Management Studio (SSMS) is an easy to use and intuitive graphical tool that lets you build and manage your database graphically. This article will explore the INSERT command of T-SQL’s Data Manipulation Language (DML).
To read the whole please follow the link above.

logo mysql sun a Two interesting database related articlesThe second one is about Five Query Optimizations in MySQL By Sean Hull. Again here is a short expert:
Query optimization is the often overlooked part of applications. Development schedules being what they are, getting the right results and getting the application working are the main priorities. So thoroughly testing, and benchmarking queries is often left as an afterthought.

With our short introduction to query optimization in MySQL, we hope to encourage at least some attention to these issues up front. We’ll also help you identify some of the more common optimizations you may run across.

Both are quite interesting read. Enjoy!

Introducing SQL Server 2008

ms sql srv cvr Introducing SQL Server 2008 Here is a book by Peter DeBetta which is called “Introducing SQL Server 2008“.

Actually its two chapters available for download. But still its a good start icon smile Introducing SQL Server 2008

Get it free from here.

SQL Server best practices

logo header sql08 SQL Server best practicesNever under estimate the load on SQL Server because it might affect overall performance.
Pinal Dave shared with us his view on 14 best practices. Here is his list if anyone wants to add something write a comment below:

1. Store relevant and necessary information in the database instead of application structure or array.

2. Use normalized tables in the database. Small multiple tables are usually better than one large table.

3. If you use any enumerated field create look up for it in the database itself to maintain database integrity.

4. Keep primary key of lesser chars or integer. It is easier to process small width keys.

5. Store image paths or URLs in database instead of images. It has less overhead.

6. Use proper database types for the fields. If StartDate is database filed use datetime as datatypes instead of VARCHAR(20).

7. Specify column names instead of using * in SELECT statement.

8. Use LIKE clause properly. If you are looking for exact match use “=” instead.

9. Write SQL keyword in capital letters for readability purpose.

10. Using JOIN is better for performance then using sub queries or nested queries.

11. Use stored procedures. They are faster and help in maintainability as well security of the database.

12. Use comments for readability as well guidelines for next developer who comes to modify the same code. Proper documentation of application will also aid help too.

13. Proper indexing will improve the speed of operations in the database.

14. Make sure to test it any of the database programming as well administrative changes.

source

Using LINQ to SQL (Part 1)

It’s all about eductaion, thats what my mom used to say to me. Its all about education – thats what Scott Guthrie is doing. Again he posted great article describing how to use LING to SQL. Thats the first part of this series, here is the whole of it:

Developers can use LINQ with any data source. They can express efficient query behavior in their programming language of choice, optionally transform/shape data query results into whatever format they want, and then easily manipulate the results. LINQ-enabled languages can provide full type-safety and compile-time checking of query expressions, and development tools can provide full intellisense, debugging, and rich refactoring support when writing LINQ code.

LINQ supports a very rich extensibility model that facilitates the creation of very efficient domain-specific operators for data sources. The “Orcas” version of the .NET Framework ships with built-in libraries that enable LINQ support against Objects, XML, and Databases.

What Is LINQ to SQL?

LINQ to SQL is an O/RM (object relational mapping) implementation that ships in the .NET Framework “Orcas” release, and which allows you to model a relational database using .NET classes. You can then query the database using LINQ, as well as update/insert/delete data from it.

LINQ to SQL fully supports transactions, views, and stored procedures. It also provides an easy way to integrate data validation and business logic rules into your data model.


Modeling Databases Using LINQ to SQL:

Visual Studio “Orcas” ships with a LINQ to SQL designer that provides an easy way to model and visualize a database as a LINQ to SQL object model. My next blog post will cover in more depth how to use this designer (you can also watch this video I made in January to see me build a LINQ to SQL model from scratch using it).

Using the LINQ to SQL designer I can easily create a representation of the sample “Northwind” database like below:

step1 Using LINQ to SQL (Part 1)

My LINQ to SQL design-surface above defines four entity classes: Product, Category, Order and OrderDetail. The properties of each class map to the columns of a corresponding table in the database. Each instance of a class entity represents a row within the database table.

The arrows between the four entity classes above represent associations/relationships between the different entities. These are typically modeled using primary-key/foreign-key relationships in the database. The direction of the arrows on the design-surface indicate whether the association is a one-to-one or one-to-many relationship. Strongly-typed properties will be added to the entity classes based on this. For example, the Category class above has a one-to-many relationship with the Product class. This means it will have a “Categories” property which is a collection of Product objects within that category. The Product class then has a “Category” property that points to a Category class instance that represents the Category to which the Product belongs.

The right-hand method pane within the LINQ to SQL design surface above contains a list of stored procedures that interact with our database model. In the sample above I added a single “GetProductsByCategory” SPROC. It takes a categoryID as an input argument, and returns a sequence of Product entities as a result. We’ll look at how to call this SPROC in a code sample below.

Understanding the DataContext Class

When you press the “save” button within the LINQ to SQL designer surface, Visual Studio will persist out .NET classes that represent the entities and database relationships that we modeled. For each LINQ to SQL designer file added to our solution, a custom DataContext class will also be generated. This DataContext class is the main conduit by which we’ll query entities from the database as well as apply changes. The DataContext class created will have properties that represent each Table we modeled within the database, as well as methods for each Stored Procedure we added.

For example, below is the NorthwindDataContext class that is persisted based on the model we designed above:

step2 Using LINQ to SQL (Part 1)


LINQ to SQL Code Examples

Once we’ve modeled our database using the LINQ to SQL designer, we can then easily write code to work against it. Below are a few code examples that show off common data tasks:


1) Query Products From the Database

The code below uses LINQ query syntax to retrieve an IEnumerable sequence of Product objects. Note how the code is querying across the Product/Category relationship to only retrieve those products in the “Beverages” category:

C#:

step3 Using LINQ to SQL (Part 1)

VB:

step9 Using LINQ to SQL (Part 1)


2) Update a Product in the Database

The code below demonstrates how to retrieve a single product from the database, update its price, and then save the changes back to the database:

C#:

step5 Using LINQ to SQL (Part 1)

VB:

step11 Using LINQ to SQL (Part 1)

Note: VB in “Orcas” Beta1 doesn’t support Lambdas yet. It will, though, in Beta2 – at which point the above query can be rewritten to be more concise.


3) Insert a New Category and Two New Products into the Database

The code below demonstrates how to create a new category, and then create two new products and associate them with the category. All three are then saved into the database.

Note below how I don’t need to manually manage the primary key/foreign key relationships. Instead, just by adding the Product objects into the category’s “Products” collection, and then by adding the Category object into the DataContext’s “Categories” collection, LINQ to SQL will know to automatically persist the appropriate PK/FK relationships for me.

C#

step4 Using LINQ to SQL (Part 1)

VB:

step12 Using LINQ to SQL (Part 1)


4) Delete Products from the Database

The code below demonstrates how to delete all Toy products from the database:

C#:

step6 Using LINQ to SQL (Part 1)

VB:

step13 Using LINQ to SQL (Part 1)


5) Call a Stored Procedure

The code below demonstrates how to retrieve Product entities not using LINQ query syntax, but rather by calling the “GetProductsByCategory” stored procedure we added to our data model above. Note that once I retrieve the Product results, I can update/delete them and then call db.SubmitChanges() to persist the modifications back to the database.

C#:

step7 Using LINQ to SQL (Part 1)

VB:

step14 Using LINQ to SQL (Part 1)


6) Retrieve Products with Server Side Paging

The code below demonstrates how to implement efficient server-side database paging as part of a LINQ query. By using the Skip() and Take() operators below, we’ll only return 10 rows from the database – starting with row 200.

C#:

step8 Using LINQ to SQL (Part 1)

VB:

step10 Using LINQ to SQL (Part 1)


Summary

LINQ to SQL provides a nice, clean way to model the data layer of your application. Once you’ve defined your data model you can easily and efficiently perform queries, inserts, updates and deletes against it.

Hopefully the above introduction and code samples have helped whet your appetite to learn more. Over the next few weeks I’ll be continuing this series to explore LINQ to SQL in more detail.

read original

Writing to Word from SQL Server

Never a man to walk away from a challenge, Phil Factor set himself the task of automating the production of Word reports from SQL Server, armed only with OLE automation and a couple of stored procedures….

3 Writing to Word from SQL ServerHaving helped Robyn with her Excel Workbench, I couldn’t get out of my head the idea of achieving the same effect with MS Word. After all, from the data viewpoint, MS Word documents are just a series of paragraphs and tables aren’t they? Surely, it should be easy to read and write data between SQL Server and Word.
view original

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.
view original

The March of Technology

3 The March of TechnologyIn which Phil, under the influence of a surfeit of lobster, some fine wine and a large book, conjures up an imaginary Bill Gates, lets him know why people aren’t flocking to SQL 2005, and offers him a turning off of the path to ever more complex and bloated database software…
view original