Sunday 8 December 2013

Singularity University plots hi-tech future for humans

Rob Nail walks into the room looking like a Silicon Valley Doctor Who as played by David Tennant - tailored suit, 3D-printed trainers and the Californian twist on the sonic screwdriver, Google Glass.

More: http://www.bbc.co.uk/news/technology-25000753

Saturday 30 November 2013

SQL Performance Tuning tips

Is SQL Server slow, are queries causing your applications to be performing less than they should? There are things that you can do to improve things and make your servers fly.

SQL Version - Consider upgrading to the latest version of SQL Server – The newer the version, the better the performance, later versions have better diagnostics, improved SQL Server query optimizer. If you are running the 32 bit version consider changing to the 64 bit version as this will allow your SQL Server to use more memory.

Check the size of TempDB – if this database is heavily used and it is too small to start with the Autogrow default setting of 10% until the disk is full may be too small, consider increasing this setting to cope with busy servers. Moving the TempDB to another fast drive can help improve performance, make sure it is not the default C: drive.

Memory - Physical Server Memory is another point to consider – SQL 2008 R2 Standard can use a maximum of 64Gb of RAM, so if you have less than this in your server, upgrade to 64Gb and see your SQL Server fly.

Windows Task Manager – Sort by CPU and then memory. If you see any processes that you don’t recognise, kill them off. Avoid developers using RDP to the Server Desktop; restrict this function to only users that need to access the server. Strip out any software from the Windows Server that is not required. Configure Anti-Virus software so that it does not interfere with SQL folders.

On Windows Server 2008 or above, make sure that the windows file system cache is not chewing up all your memory. Try and avoid file copies form the server as this may affect performance of the SQL Server due to caching of the file operation. Check the Task Manager | Performance tab and check the Cached number under ‘Physical Memory’

Event Logs – Use both the Windows Event log and the SQL Server log and check for any errors or warnings, fixing these may have a major impact on the server performance. The Windows logs will show any alerts regarding potential hardware failure, take note of these and replace hardware before it’s too late. Drivers for hardware are another area that can cause problems or slowness; make sure that these are up to date. Configure SQL Server alerts so you know when storage is tight of there are errors occurring on your SQL Server.

Run Brent Ozar’s SP_Blitz script A Health check of your SQL Server

Power Plans – Check that the Windows Server Power Plan is set to Performance setting and not power saving. Use ‘powercfg /list’ at the CMD Prompt to see what power plan your server is using.

SQL Server Simple or Forced Parameterisation. Which should you be using? It will depend on what type of queries you are using but the following article will show how to decide on which route to take.

Performance Tuning Tips from mssqltips

Glen Berry’s SQL Server Performance
Depending on your anticipated workload and which SQL Server components you have installed, there are a number of instance level settings that you should consider changing from their default values. These include Max Server Memory, optimize for ad-hoc workloads,  default backup compression, max degree of parallelism, and the number of TempDB data files for the SQL Server instance.


Useful links

SQL Clustered and Non Clustered indexes

Indexes are associated with tables or views to speed up the retrieval of rows. It contains keys built from one or more columns. The structure that these keys are stored is called a ‘B-tree which allows the server to find each row quickly and effectively.

There are two types of index:-

Clustered

1.       Clustered indexes sort and store data rows based on key values.
2.       These are the columns included in the index definition.
3.       There can be only one clustered index per table, because the data rows themselves can be sorted in only one order.
4.       The only time data rows in a table are stored in a sorted order is when the table contains a clustered index.
5.       When a table has a clustered index, the table is called a clustered table.
6.       If a table has no clustered index, its data rows are stored unordered and is called a heap.
7.       When you create a PRIMARY KEY constraint, a unique index on the column or columns is automatically created. By default, this index is clustered; however, you can specify a non clustered index when you create the unique constraint.
a.       The primary key column will not allow NULL values.
8.       If a clustered index is not created with the unique property, the Database Engine automatically adds a 4 byte uniqueifier column to the table.
a.       When it is required, the database Engine automatically adds a uniqueifier value to a row to make each key unique.
b.      This column and it’s values are used internally and cannot be seen or accessed by users.
9.       Generally, you should define the clustered index key with as few columns as possible.
10.   Consider columns that have one or more of the following attributes:-
a.       Are unique or contain many distinct values.
b.      Are accessed sequentially.
c.       Defined as IDENTITY because the column is guaranteed to be unique within the table.
d.      Used frequently to sort data retrieved from the table.
11.   Clustered indexes can become typically quite large and so you should consider the following options:-
a.       SORT_IN_TEMPDB
                                                               i.      If ON, the sort results are stored in the tempdb else they are stored in the filegroup.
b.      DROP_EXISTING
                                                               i.      Indicates if the existing index should be dropped and recreated. Consider using this if you are recreating the CI as this will also update the Non Clustered indexes which use the clustered index at the same time.
c.       FILLFACTOR
                                                               i.      Sets the percentage of free space in the leaf level of each index page during index creation.
d.      ONLINE
                                                               i.      Determines whether concurrent user access to the underlying table or clustered index data and any associated non clustered indexes is allowed during index operations. When you create indexes on existing tables long term table locks are not held which allows queries and updates to continue.
12.   If a clustered index is created on a heap table that already contains several non clustered indexes then on creation of the clustered index all the non clustered indexes will need to be rebuilt so that they contain the clustered key value instead of the row identifier (RID).
13.   If a clustered index is dropped on a table that has several non clustered indexes, the non clustered indexes are all rebuilt as part of the DROP operation. This may take significant time on large tables.
a.       The preferred way to build indexes on large tables is to start with the clustered index and then build any non clustered indexes.

Non Clustered

1.       Non clustered indexes have a separate structure from the data rows.
2.       Contains the non clustered index key values and each key value entry has a pointer to the data row that contains the key value.
3.       The pointer from an index row of a non clustered index to a data row is called a row locator.
4.       The structure of the row locator depends on whether the data pages are stored in a heap or a clustered table.
5.       For a heap, a row locator is a pointer to the row.
6.       For a clustered table, the row locator is the clustered index.
7.       You can add nonkey columns to the leaf level of the non clustered index to by-pass existing index key limits, 900 bytes and 16 key columns.

Both clustered and non clustered indexes can be unique. This means that no two rows can have the same value for the index key. Otherwise, the index is not unique and multiple rows can share the same key value.

Indexes are automatically maintained for a table or view whenever the data is modified.


Friday 29 November 2013

SSRS create linked report

What if more than one dept wants access to the same report?

SSRS can become quite crowded as reports are added.  Creating folders for departments can help organise and group reports for business use.  Then setting get up security for each folder to restrict users if that's how the business operates.

Creating a linked report from the source report is straight forward and allows groups of users to utilise the report from different folders. When on the web site for your reports,  Manage the report and go to Properties the click Create Linked Report. Follow the simple instructions to place the linked report into a target folder.

Thursday 28 November 2013

SQL 2008 R2 Agent Job properties.

The Description window in job properties is not overly text rich,  like notepad you can't format text which is fine because this purely for brief information on what the job does etc. 

The one thing I found really useful is using the keyboard shortcut CTRL - ENTER. This adds a carriage return and creates a new line for text,  nice.

Wednesday 27 November 2013

SQL Unions with If Statements

I discovered today that you cannot do a UNION in conjunction with If Statements in a SELECT.

If you know different please post it HERE!

Sunday 24 November 2013

Best Practices for Virtualising and Managing SQL Server 2012

To give you a flavour of what this document is about and who should read this, I have copied the beginning of the pdf document. If you are going to virtualise your server environment, I would recommend you read this document Best_Practices_for_Virtualizing_and_Managing_SQL_Server_2012.pdf

Introduction 

This guide provides high-level best practices and considerations for deploying and managing Microsoft
SQL Server 2012 on a Microsoft virtualization infrastructure. The recommendations and guidance in this
document aim to:
Complement the architectural design of an organization’s specific environment.
Help organizations take advantage of the key platform features in SQL Server 2012 to deliver the
highest levels of performance and availability.

Executive Summary 

With the proliferation of applications in everyday use, enterprises have an increasing need for more
instances of databases such as SQL Server. Most applications have their own set of database
requirements, leading to the use of multiple versions of databases and to significant costs related to the
databases and related hardware resources. More importantly, the hardware deployed for databases is not
fully utilized or there is a demand to scale up hardware resources to meet peak utilization on certain
databases. Therefore, it has become important to control the cost of databases and related hardware
resources, and to optimize and scale the use of hardware resources in different scenarios to provide better
flexibility and maintain service level agreements (SLAs). An ideal solution to this problem is virtualization.
Virtualization is fairly common now. Many organizations worldwide have moved beyond the nascent
stage into being more advanced users of server virtualization, specifically. These organizations have
gained benefits in the areas of costs, efficiency, operations, availability, agility, and resiliency.

Microsoft SQL Server 2012 and Windows Server 2012 provide a host of new features that can be used to
effectively virtualize demanding database workloads that previously were not considered for virtualization.
This guide explains these new features in the context of how organizations should consider virtualizing
SQL Server 2012 on Windows Server 2012 and the benefits of managing this virtualized environment with
Microsoft System Center 2012. Working together, these industry-leading products deliver an integrated
platform with a low total cost of ownership (TCO) as well as mission-critical scale, performance, and
availability. The platform also provides enhanced end-to-end security, management, and monitoring
capabilities.

Further, many organizations now want to go a step beyond and adopt an IT infrastructure that is
optimized for and ready to work in the cloud. They need an IT infrastructure that can seamlessly span
from a private to a public cloud. To achieve this goal, organizations require a common virtualization
platform that can increase performance and efficiency across the infrastructure. In this regard, Windows
Server 2012 Hyper-V offers an ideal virtualization platform for SQL Server 2012.

SQL Server Database documentation

ApexSQL Doc

I use this product and it's pretty good. It struggles sometimes with dealing with multiple servers but you can break those down to more manageable jobs so that it does not error during processing. On the whole, its a great piece of software which describes and documents your databases using the extended properties as the descriptors. 
Tip: It's a very good idea when using SQL Server Extended Properties to decide what you are going to use use as a label i.e. 'MS_Description' and then use this label all the way through your descriptions for Tables, Fields etc. The reason for this is that Apex SQL Doc can only use one label so if you have different labels sprinkled throughout your database you won't see them all when you carry out your database documentation.

Your database Visualised. Database to documentation in a variety of formats.

Generate database and SSIS documentation in CHM, HTML and Word
Automate and schedule the documenting process
Include relationship diagrams in your database documentation
Leverage extended properties and edit them directly

More information: http://www.apexsql.com/sql_tools_doc.aspx

SQL Prompt - Write, refactor, and explore SQL effortlessly

Real world positive feedback from the T-SQL coal face

I have been using this tool for a few years now and can tell you it saves me a lot of time from re-writing T-SQL. I also love the new History tab so all those SSMS Queries you closed down thinking you didn't need them and then discover in fact you did? Well the history tab remebers what you typed and allows you to reteive your work, no more lost work!
The SQL Format function is brilliant, no more messy code! 
Enjoy!!

5 ways coding becomes effortless with SQL Prompt:

NEW! Tab history - save, search, and recover tabs in SSMS
IntelliSense-style code completion
Customizable code formatting
Save code snippets
Refactor SQL code
SQL Prompt is an add-in for SQL Server Management Studio and Visual Studio, and has been designed to strip away the repetition of coding.

More information: http://www.red-gate.com/products/sql-development/sql-prompt/

SQL Assistant - for SQL Server, SQL Azure, Oracle, DB2, Sybase, MS Access, PostgreSQL, and MySQL

The ultimate tool for database development

SQL Assistant equips database developers and DBAs with the productivity tools they need to speed up the database development process, improve code quality and accuracy. SQL Assistant can boost your SQL coding productivity by 300%.  SQL Assistant supports all major databases. It is shipped pre-configured with support for Oracle, Microsoft SQL Server, IBM DB2, MySQL, PostgreSQL, Sybase ASE and SQL Anywhere. The product also offers a full-featured source control interface that supports the Subversion and Microsoft Team Foundation Server code repositories. Many users have stated they don't know how they can code and manage their databases without SQL Assistant. To get a better idea of what it can do for you, download the trial and check it for yourself.

More information: http://www.softtreetech.com/isql.htm

A family of viruses pose for a photo.


Most Terrifying Hikes In The World

Mount Huashan Is One Of The Most Dangerous, Terrifying Hikes In The World http://www.huffingtonpost.com/2013/11/13/mount-huashan-hike_n_4262641.html


250 Hard Drives Used To Make One Awesome F1 Car

250 Hard Drives Used To Make One Awesome F1 Car http://wonderfulengineering.com/250-hard-drives-used-to-make-one-awesome-f1-car/

Saturday 23 November 2013

Open data

Wikipedia list of countries that offer open data.

http://en.wikipedia.org/wiki/Open_data


What is Open Data?

Open data is the idea that certain data should be freely available to everyone to use and republish as they wish, without restrictions from copyright, patents or other mechanisms of control. The goals of the open data movement are similar to those of other "Open" movements such as open source, open hardware, open content, and open access. The philosophy behind open data has been long established (for example in the Mertonian tradition of science), but the term "open data" itself is recent, gaining popularity with the rise of the Internet and World Wide Web and, especially, with the launch of open-data government initiatives such as Data.gov and Data.gov.uk.

Raspberry Pi hack creates a smart TV

Raspberry Pi hack creates a smart TV from a not-so-bright set http://www.engadget.com/2013/11/23/raspberry-pi-hack-creates-smart-tv-from-a-not-so-bright-set/?ncid=rss_semi

China's 'Sharp Sword' stealth drone makes maiden flight

China's 'Sharp Sword' stealth drone makes maiden flight http://www.wired.co.uk/news/archive/2013-11/23/sharp-sword

Friday 22 November 2013

Kano: a Raspberry Pi computer that snaps together like Lego in 107 seconds

http://www.independent.co.uk/life-style/gadgets-and-tech/news/kano-a-raspberry-pi-computer-that-snaps-together-like-lego-in-107-seconds-8953923.html

Men robbed and knocked unconscious for Xbox One consoles

http://www.bbc.co.uk/news/uk-england-somerset-25052592


Two men have been robbed of their brand new games consoles in Gloucester, just minutes after buying them.

The pair, aged 25 and 27, were among the first to have bought the new Microsoft Xbox One after it went on sale in the UK on Thursday at midnight.

What core skills should someone have with T-SQL?

I'll start the list, but feel free to add to it or give me your thoughts. I think someone ought to be able to understand these items and write code to solve problems that involve:

finding duplicate rows (grouping, joins)
returning aggregates of single or multiple columns (MAX, MIN, SUM, COUNT)
return aggregates in groups, or islands. (grouping and aggregates, windowing)
join multiple tables together on matching, multiple columns (joins)
find data in one table that doesn't have matches in another (outer joins)
filtering data (WHERE) subqueries and complex CTE joins of data
create row numbers and join back to a table without numbers (APPLY)
pivoting data from rows to columns

Wednesday 20 November 2013

Wolfram|Alpha - Computational knowledge engine

http://www.wolframalpha.com/
Wolfram|Alpha introduces a fundamentally new way to get knowledge and answers - not by searching the web, but by doing dynamic computations based on a vast collection of built-in data, algorithms, and methods.


Google Public Data Explorer

http://www.google.co.uk/publicdata/directory
The Google Public Data Explorer makes large, public-interest datasets easy to explore, visualize and communicate. As the charts and maps animate over time, the changes in the world become easier to understand. You don't have to be a data expert to navigate between different views, make your own comparisons, and share your findings.

World's largest cancer database launched - health - 14 November 2013 - New Scientist

https://cansar.icr.ac.uk/


SQL Injection can destroy your database

http://www.w3schools.com/sql/sql_injection.asp
An SQL Injection can destroy your database. Read this chapter from http://www.w3schools.com/ which explains the 'how', having this knowledge will enable you to prevent SQL Injection.

SQL Monitor

Red Gates SQL Monitor version 3.5 has just been released
http://www.red-gate.com/products/dba/sql-monitor/