Geoffrey Emery
Tech Goodness

PHP Driver for SQL Server

May 17, 2009 01:59 by gemery

image For those who are not already aware of the Web Platform Installer (WPI), it's a great tool for setting up a Windows machine for Web app development and deployment.  You can download the beta of WPI 2.0 or the WPI 1.0 release here.

PHP itself is available via the WPI 2.0 beta.  Installing PHP through the WPI 2.0 beta also automatically configures FastCGI as part of the installation.  Mai-lan from the API team has a great blog post here with more information about installing PHP via WPI.


Tags: ,
Categories: SQL Server
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

SQL Server The Geography Data type

April 22, 2009 17:57 by gemery
 

Overview

The most important feature of the geography data type is  that stores Geodetic Spatial Data.

image

this is geodetic model.

This model takes account of the curved shape of the earth. When you perform operations on spatial data using the geography data type, SQL server uses angular computations to work out the result.These computations are calculated based on the ellipsoid model of the earth defined by the spatial reference system of the data in question. For example, if you were to to define a line that connects two points on earths surface in the geography data type the line would curve to follow the surface of the earth

image

Every line drawn in the geography data types are actually great elliptic arc.

Coordinate System

The geography data type is based on a three dimensional, round model so you must use latitude and longitude for coordinates.

Units of Measure

Since we are using Latitude and Longitude to define our points the unit of measure is in degrees. Being degrees is helpful for locating a objects, but not very helpful telling us what the actual distance is between the them. For instance lets say we wanted to know the distance between Los Angeles and Dallas. It would not be very helpful to know that it is 13 degrees away. It would be much more valuable to know that it is 1439 miles away.

To account for this the clever folks at Microsoft tell us to put a spatial reference or SRID in of 4326

So lets take a look what kind of measurement we get when we take the distance for Los Angeles To Dallas

 

Declare @LosAngeles as geography = geography::Point(33.56,118.24,4326)
Declare @Dallas as geography = geography::Point(32.47,96.47,4326)
Select @LosAngeles.STDistance(@Dallas)

 

The Result  is

2033990.01214834 metes

2 033 990.01214834 meters = 1 263.8628 miles

We notice that this is different that the first measurement given that is because the first measurement didn't account for the measurement of the earth.

 

Size Limitations

Due to technical Limitations SQL Server limits the size of any single object must fit inside a single hemisphere of the earth. This also include any computation on these objects. To work around this you can break down these objects into smaller polygons and then and then combine those together.

Sweet so there is the first in a series of posts on SQL Server Spatial that are coming out.

almost forgot.

Ring Orientation

If are drawing a ellipsoid everything is stored counter clock wise.


Sql Server Joins – The Basics Code and Diagrams

April 14, 2009 08:07 by gemery

 

Download SQL Script used throughout in this article to practice along. Now, take a quick look at the following two tables I have created.

INNER JOIN

This join returns rows when there is at least one match in both the tables.

OUTER JOIN

There are three different Outer Join methods.

image

LEFT OUTER JOIN
This join returns all the rows from the left table in conjunction with the matching rows from the right table. If there are no columns matching in the right table, it returns NULL values. 
image

RIGHT OUTER JOIN
This join returns all the rows from the right table in conjunction with the matching rows from the left table. If there are no columns matching in the left table, it returns NULL values.
image

FULL OUTER JOIN
This join combines left outer join and right after join. It returns row from either table when the conditions are met and returns null value when there is no match.
image

CROSS JOIN

This join is a Cartesian join that does not necessitate any condition to join. The resultset contains records that are multiplication of record number from both the tables.

image

Additional Notes related to JOIN:

The following are three classic examples to display where Outer Join is useful. You will notice several instances where developers write query as given below.

SELECT t1.*
FROM Table1 t1
WHERE t1.ID NOT IN (SELECT t2.ID FROM Table2 t2)
GO

The query demonstrated above can be easily replaced by Outer Join. Indeed, replacing it by Outer Join is the best practice. The query that gives same result as above is displayed here using Outer Join and WHERE clause in join.

/* LEFT JOIN - WHERE NULL */
SELECT t1.*,t2.*
FROM Table1 t1
LEFT JOIN Table2 t2 ON t1.ID = t2.ID
WHERE t2.ID IS NULL

image

The above example can also be created using Right Outer Join.

image

NOT INNER JOIN
Remember, the term Not Inner Join does not exist in database terminology. However, when full Outer Join is used along with WHERE condition, as explained in the above two examples, it will give you exclusive result to Inner Join. This join will give all the results that were not present in Inner Join.

image

You can download the complete SQL Script here, but for the sake of complicity I am including the same script here.

USE AdventureWorks
GO
CREATE TABLE table1
(ID INT, Value VARCHAR(10))
INSERT INTO Table1 (ID, Value)
SELECT 1,‘First’
UNION ALL
SELECT 2,‘Second’
UNION ALL
SELECT 3,‘Third’
UNION ALL
SELECT 4,‘Fourth’
UNION ALL
SELECT 5,‘Fifth’
GO
CREATE TABLE table2
(ID INT, Value VARCHAR(10))
INSERT INTO Table2 (ID, Value)
SELECT 1,‘First’
UNION ALL
SELECT 2,‘Second’
UNION ALL
SELECT 3,‘Third’
UNION ALL
SELECT 6,‘Sixth’
UNION ALL
SELECT 7,‘Seventh’
UNION ALL
SELECT 8,‘Eighth’
GO
SELECT *
FROM Table1
SELECT *
FROM Table2
GO
USE AdventureWorks
GO
/* INNER JOIN */
SELECT t1.*,t2.*
FROM Table1 t1
INNER JOIN Table2 t2 ON t1.ID = t2.ID
GO
/* LEFT JOIN */
SELECT t1.*,t2.*
FROM Table1 t1
LEFT JOIN Table2 t2 ON t1.ID = t2.ID
GO
/* RIGHT JOIN */
SELECT t1.*,t2.*
FROM Table1 t1
RIGHT JOIN Table2 t2 ON t1.ID = t2.ID
GO
/* OUTER JOIN */
SELECT t1.*,t2.*
FROM Table1 t1
FULL OUTER JOIN Table2 t2 ON t1.ID = t2.ID
GO
/* LEFT JOIN - WHERE NULL */
SELECT t1.*,t2.*
FROM Table1 t1
LEFT JOIN Table2 t2 ON t1.ID = t2.ID
WHERE t2.ID IS NULL
GO
/* RIGHT JOIN - WHERE NULL */
SELECT t1.*,t2.*
FROM Table1 t1
RIGHT JOIN Table2 t2 ON t1.ID = t2.ID
WHERE t1.ID IS NULL
GO
/* OUTER JOIN - WHERE NULL */
SELECT t1.*,t2.*
FROM Table1 t1
FULL OUTER JOIN Table2 t2 ON t1.ID = t2.ID
WHERE t1.ID IS NULL OR t2.ID IS NULL
GO
/* CROSS JOIN */
SELECT t1.*,t2.*
FROM Table1 t1
CROSS JOIN Table2 t2
GO
DROP TABLE table1
DROP TABLE table2
GO

I hope this article fulfills its purpose. I would like to have feedback from my blog readers.  Please suggest me where do you all want me to take this article next.

Reference : Pinal Dave (http://blog.SQLAuthority.com)

Original Post here

Adding this here for my own refrence


Tags: ,
Categories: SQL Server | T-SQL
Actions: E-mail | Permalink | Comments (4) | Comment RSSRSS comment feed

SQL Server 2005 sp3 Released

December 24, 2008 13:38 by gemery

Microsoft just released SQL server sp3 for 2005. Just when you thought it was time to move to 2008 it still is, but if you are still running 2005 look into this pack enhancements.

The purpose of a service pack is to provide a tested intermediate-level upgrade that contains fixes to bugs encountered since the last version release. Service packs don’t typically add new features to the product, although they might provide enhanced behavior to features that were new in the most recent version but weren’t completely ready by the release to manufacturing date. However, Microsoft doesn’t always abide by this definition of service pack, and there have been SQL Server service packs that have added new features, new columns to existing metadata objects, or even entirely new metadata views or functions

Also if you’ve previously applied hotfixes or recent Cumulative Updates (CUs) for Sql Server 2005 SP2 (CU12 or CU11). The most succinct explanation of the relationship between SQL Server 2005 SP3 and the various CUs, including SQL Server 2005 SP3 CU1, which will be released in a week, can be found on Aaron Bertrand’s blog. You can find a list of bugs that have been fixed in SQL Server 2005 SP3 at http://support.microsoft.com/?kbid=955706.

Technorati Tags: ,

Comparison of Execution Speed of EC2 with SQL Express or SimpleDB and Azure Table Services by Oak Leaf

December 23, 2008 23:09 by gemery

I have been getting into cloud computing in a really big way/ I just read a great post from Oakleaf System that put a test harness on all the different cloud computing systems out there, With the exception of       s(s)ds (soon to come) and Google. It is a great through down and worth a read.  Here is a link to the article

http://oakleafblog.blogspot.com/2008/12/test-harnesses-compare-amazon-ec2-with.html

Here is a spoiler if you don’t have time to read the whole thing

Following is a comparison of EC2 execution times with those of the original OakLeaf Systems Azure Table Services Sample Project that’s described at Azure Storage Services Test Harness: Table Services 1 – Introduction and Overview, et seq.

Action: Page Count Insert Delete Create Update
EC2 with SQL Express 0.005 0.002 0.019 0.380 0.112 0.374
EC2 with SimpleDB 0.048 0.094 0.048 10.094 22.142 10.855
Azure Table Services 0.215 0.188 0.155 5.820 5.310 6.561

I was surprised to find Azure Table Services’ execution to be substantially slower than EC2 with SimpleDB for single-page SELECTS, iterative counts, and single INSERT operations.

With the exception of the Insert operation, you can verify the Azure Table Services timing data because the harness is available whenever Azure Data Services is up. EC2 services will be made available on request for brief periods (contact roger_jennings[at]compuserve[dot]com).

Make sure you read the comments there worth a gander.

https://www.blogger.com/comment.g?blogID=11646261&postID=1093778038105568110&page=1


My Interview With David Robinson On Putting SQL Server in the Cloud and More

December 10, 2008 08:44 by gemery

What happens when you all your slides fail your mike doesn’t work and then the projector turns off right before you do your presentation? This is just the start of a great conversation that Geoffrey Emery has with David Robinson at the PDC Underground. Dave just lets it all out and more when he talks about cloud computing and what a exciting time it is to be in the windows family. He is currently working on a new technology at Microsoft called SDS SQL Data Services a program at Microsoft that will eventually put SQL server in the cloud. David also brings up how to do bring the cloud computing to your boss in a way that would be easy for everyone to understand.

Putting the pieces together Microsoft is coming out with some really interesting technologies for cloud computing that is not just a database in the cloud but also hosting of your web site either by spinning up a new server instance and launching it in the cloud or by actually deploying your code into the cloud automatically by using Visual Studio development platform and eliminating the need for the developer to know the ins and outs of IIS for those who don't need it.

Links in the video

David's Blog - http://blogs.msdn.com/drobinson/

Windows Azure – http://azure.com

SQL Server Data Services (SDS) - http://msdn.microsoft.com/en-us/sqlserver/dataservices/default.aspx

Visual Studio - http://msdn.microsoft.com/en-us/vstudio/default.aspx

Microsoft Could Computing – http://azure.com

IIS - http://www.iis.net/

 


SQL Server Express 2008 and SQL Server Express 2008 Management Studio

October 24, 2008 11:22 by gemery

I am getting ready to do bunch of presentations this weekend and I realized half my computers were running the rc of Sql 2008

So I decided to got to the site and downloaded and selected to install SQL Exrpress 2008.

Went to look for SQL Server Express Management Studio Express 2008 annnnnd nothing!

Few search engine searches later and no clear direction found this on SQL Express home page:

You can manually download and install any edition of SQL Server 2008 directly from the Microsoft Download Center:

Which edition of SQL Server 2008 Express is right for you?

SQL Server 2008 Express is available in the following 3 editions (each is available from the Install Wizard):

  • SQL Server 2008 Express
    • SQL Server database engine - create, store, update and retrieve your data
  • SQL Server 2008 Express with Tools
    • SQL Server database engine - create, store, update and retrieve your data
    • SQL Server Management Studio Basic - visual database management tool for creating, editing and managing databases
  • SQL Server 2008 Express with Advanced Services
    • SQL Server database engine - create, store, update and retrieve your data
    • SQL Server Management Studio Basic - visual database management tool for creating, editing and managing databases
    • Full-text Search - powerful, high-speed engine for searching text-intensive data
    • Reporting Services - integrated report creation and design environment to create reports

So make sure you download the SQL Server 2008 Express with ToolsSql

Though I save some people some time.

One last thing:

Step 1: Download and install Microsoft .Net Framework 3.5 SP1.
Step 2 Download and install Windows Installer 4.5.
Step 3 Download and install Windows PowerShell 1.0.


Amazon EC2 for Windows is Here

October 24, 2008 08:23 by gemery

I jut received this email this morning

Dear AWS Developers,

We are excited to release the public beta of Amazon Elastic Compute Cloud (Amazon EC2) running Microsoft Windows Server and Microsoft SQL Server. AWS is also announcing that Amazon EC2 is now Generally Available and includes a Service Level Agreement (SLA). In addition, we're giving you a sneak peek at some upcoming features that will make Amazon EC2 even easier to operate. Please see details below on these announcements.

You requested to be notified when Windows was available on EC2, and starting now you can employ Amazon EC2 running Windows Server or SQL Server with all of the performance, reliability, and scalability benefits of Amazon EC2. AWS customers have commonly requested Amazon EC2 running Windows Server since the service launched, and this announcement means that Amazon EC2 will provide an ideal environment for deploying ASP.NET web sites, high performance computing clusters, media transcoding solutions, and many other Windows-based applications. Like all services offered by AWS, Amazon EC2 running Windows Server or SQL Server offers a low-cost, pay-as-you-go model with no long-term commitments and no minimum fees. Pricing for Amazon EC2 running Windows Server begins at $0.125 per compute hour. Please go to aws.amazon.com/windows for more information.

Also, Amazon EC2 has entered General Availability (GA), after just over two years of operation in beta and the addition of many highly-requested features. We are also providing an SLA for Amazon EC2, with a service level commitment of 99.95% availability within a Region. If availability falls below this level, customers are eligible to receive service credits. The new Amazon EC2 SLA is designed to give customers additional confidence that even the most demanding applications will run dependably in the AWS cloud. For further details on the SLA for EC2, see aws.amazon.com/ec2-sla.

Lastly, to help its customers better plan their future hardware and software investments, AWS is providing visibility into plans to release several new features in 2009 that will make managing cloud-based applications even easier. These features will help provide even more cost-efficient consumption of Amazon EC2 and greater visibility into the operational health of applications running in the AWS cloud. These features include:

  • Load balancing - Enables AWS customers to balance incoming requests and distribute traffic across multiple Amazon EC2 instances.
  • Auto-scaling - Automatically grows and shrinks usage of Amazon EC2 compute capacity based on application requirements.
  • Cloud monitoring - Enables AWS customers to monitor operational metrics of Amazon EC2, providing visibility into usage of the AWS cloud.
  • Management Console - Provides a simple, point-and-click web interface that lets customers manage and access their AWS cloud resources.

To learn more about these new services or to sign-up for notification when they are released, please visit: aws.amazon.com/contact-us/new-features-for-amazon-ec2.

We are excited to share these exciting new announcements with you, and invite you to visit aws.amazon.com/ec2 for full details.

I can't tell how exciting this is. More to come on this!


Amazon makes update to their windows server launch for cloud computing

October 20, 2008 22:20 by gemery

I was just talking about windows/SQL server in the cloud with my buddy James and after reading my blog he was still a little confused about what was going on. So I found a much more interesting link that I think will be more relevant to the average .net hoster here is the relevant information that I think that you will need to get started.

Starting later this Fall, Amazon Elastic Compute Cloud (Amazon EC2) will offer you the ability to run Microsoft Windows Server or Microsoft SQL Server. Today, you can choose from a variety of Unix-based operating systems, and soon you will be able to configure your instances to run the Windows Server operating system. In addition, you will be able to use SQL Server as another option within Amazon EC2 for running relational databases.

Amazon EC2 running Windows Server or SQL Server provides an ideal environment for deploying ASP.NET web sites, high performance computing clusters, media transcoding solutions, and many other Windows-based applications. By choosing Amazon EC2 as the deployment environment for your Windows-based applications, you will be able to take advantage of Amazon’s proven scalability and reliability, as well as the cost-effective, pay-as-you-go pricing model offered by Amazon Web Services. Customers will only pay for as much or little as they actually use; of course the actual price will be higher than Linux-based instances, due to the cost of Windows licenses. We’ll announce specific pricing when we make the service broadly available later this Fall.

Our goal is to support any and all of the programming models, operating systems and database servers that you need for building applications on our cloud computing platform. The ability to run a Windows environment within Amazon EC2 has been one of our most requested features, and we are excited to be able to provide this capability. We are currently operating a private beta of Amazon EC2 running Windows Server and SQL Server

 

You can sign up for more information about this from here

After doing some basic analysis about what it cost to relocate some common domains that were more brochure site we figured we could incur a common savings of over 50%. The question still is how is the SQL server instance going to work and replicate across the data centers.

I think the biggest question here is what is microsoft going to do with its cloud and what announcements are going to come out at PDC?


Where are you in Data mining and Business Intelligence

September 3, 2008 06:45 by gemery

I love data...It holds so many interesting secrets just waiting to be mined out and taken advantage of. If you haven't looked into space before the time is now and its never been easier.

Start to read Lynn Langit's Blog She is the BI Queen, and posts solid information that you will need like this great post on  BI.

http://blogs.msdn.com/socaldevgal/archive/2008/08/27/sql-server-2008-data-mining-in-the-cloud.aspx

Her book a great place to start as well

http://www.amazon.com/Foundations-Server-2005-Business-Intelligence/dp/1590598342

Enjoy!


T-Sql Seperate Date and Time

April 23, 2008 21:36 by gemery

I just used this for the 1000th time so I thought i would blog about it. Just replace getdate() and with your date...

-- just the date
SELECT CONVERT(char(10), getdate(), 101) AS [Date]
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
-- just the time
SELECT (getdate() - 
    CAST(ROUND(CAST(getdate() AS float), 0, 1) AS datetime))
SELECT CONVERT (datetime, (1 - (CONVERT (float, getdate() ) - 
     CONVERT (int, CONVERT (float, getdate())))) * - 1 - 1)

Tags:
Categories: SQL Server | T-SQL
Actions: E-mail | Permalink | Comments (8) | Comment RSSRSS comment feed

Restoring Backup Databases and viewing logical files In SQL Server

April 11, 2008 11:41 by gemery

Ok so I was running into some errors restoring a database and I ended up writing this little script that did the job.

Thought I would share.

Here’s how you look into a backup set to find out what logical files make up the backup set.

When you get the logical file names you can then write a restore script to restore the database to any name you would like as well as renaming the datafiles to match your new database name.  Here are the steps:

From Management Studio, run this command from the master database: restore filelistonly from

disk=’path\dbname.bak’ where path is the location of the backup set: 
restore filelistonly from disk='\\YourServer\c$\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\Email.bak' 

In this case it returned the following information:

LogicalName   PhysicalName                  Type       FileGroupName        Size                MaxSize              FileId

Email1        E:\Data\Email_Backup.mdf   D         PRIMARY              10770972672           35184372080640       1

Email1_log   E:\Log\Email_Backup.ldf      L         NULL                 4312465408          2199023255552         2

Then we build the restore database statement and change the PhysicalName and location of the file to a new name we prefer.  In this case it looked like this:

 

restore database Email from disk='\\YourServer\c$\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\Email.bak' 
with move 'Email1' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\Email_data.mdf', 
move 'Email1_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\Email_log.ldf' 
go
Bata Bing Bata Boom rocking the new database..