<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'T-SQL', 'development', and 'SQL'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=T-SQL,development,SQL&amp;orTags=0</link><description>Search results matching tags 'T-SQL', 'development', and 'SQL'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Please Vote: Windowing Enhancements in SQL Server</title><link>http://sqlblog.com/blogs/michael_coles/archive/2009/11/19/please-vote-windowing-enhancements-in-sql-server.aspx</link><pubDate>Fri, 20 Nov 2009 03:45:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:19010</guid><dc:creator>Mike C</dc:creator><description>&lt;P&gt;Back in January 2007, SQL guru &lt;A title="Itzik's Site" href="http://www.solidq.com/insidetsql/"&gt;Itzik Ben-Gan&lt;/A&gt; posted a series of &lt;A title="Itzik's Connect Requests" href="https://connect.microsoft.com/SQLServer/SearchResults.aspx?UserHandle=Itzik+Ben-Gan"&gt;MS Connect enhancement requests&lt;/A&gt; concerning windowing function enhancements.&amp;nbsp; Those who have used the &lt;A title="ROW_NUMBER() in BOL" href="http://msdn.microsoft.com/en-us/library/ms186734.aspx"&gt;ROW_NUMBER()&lt;/A&gt;, &lt;A title="RANK() in BOL" href="http://msdn.microsoft.com/en-us/library/ms176102.aspx"&gt;RANK()&lt;/A&gt;, &lt;A title="DENSE_RANK() in BOL" href="http://msdn.microsoft.com/en-us/library/ms173825.aspx"&gt;DENSE_RANK()&lt;/A&gt;, and &lt;A title="NTILE() at BOL" href="http://msdn.microsoft.com/en-us/library/ms175126.aspx"&gt;NTILE()&lt;/A&gt; functions on SQL 2005 and 2008, you already know how useful they are.&amp;nbsp; They simplify code and can improve performance considerably over the alternatives, which usually include self-joins, temp tables and/or cursors in various combinations.&lt;/P&gt;
&lt;P&gt;Well, the windowing functionality that you've seen in SQL 2005 and 2008 is just the tip of the iceberg.&amp;nbsp; The ISO SQL standard actually defines several additional options for these functions that SQL Server doesn't yet support. These additional options allow you to do some pretty amazing calculations. The ROWS and RANGE window subclauses that the standard defines allows you to perform "sliding window" calculations; the ORDER BY clause for aggregate functions which simplifies complex running sum (and other) calculations.&lt;/P&gt;
&lt;P&gt;As a SQL developer or DBA, these enhancements will simplify your life.&amp;nbsp; But don't take my word for it - read Itzik's white paper at &lt;A href="http://www.insidetsql.com/OVER_Clause_and_Ordered_Calculations.doc"&gt;http://www.insidetsql.com/OVER_Clause_and_Ordered_Calculations.doc&lt;/A&gt;.&amp;nbsp; Then let Microsoft know you want these enhancements in SQL Server by&amp;nbsp;voting on Itzik's enhancement requests at the following links:&lt;/P&gt;
&lt;DIV&gt;Progressive Ordered Calculations: &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254397"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254397&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;FIRST_VALUE, LAST_VALUE functions: &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254395"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254395&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;DISTINCT clause for aggregates: &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254393"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254393&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;ROWS and RANGE window subclauses: &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254392"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254392&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Vector expressions: &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254391"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254391&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;TOP OVER: &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254390"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254390&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;LAG and LEAD functions: &lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254388"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254388&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;ORDER BY for aggregates:&amp;nbsp;&lt;A href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254387"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=254387&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Read Itzik's article, vote on the Connect items, and spread the word!&lt;/DIV&gt;</description></item><item><title>&amp;quot;Cloning&amp;quot; Symmetric Keys</title><link>http://sqlblog.com/blogs/michael_coles/archive/2009/06/17/cloning-symmetric-keys.aspx</link><pubDate>Thu, 18 Jun 2009 01:40:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14741</guid><dc:creator>Mike C</dc:creator><description>&lt;P&gt;It's well-known by now that SQL Server 2005 and 2008 include new encryption-related statements that allow you to create and administer encryption keys. You can use &lt;FONT face=courier&gt;CREATE CERTIFICATE&lt;/FONT&gt; to create or&amp;nbsp;import a certificate or &lt;FONT face=courier&gt;DROP ASYMMETRIC KEY&lt;/FONT&gt; to remove an asymmetric key from the database, for instance.&amp;nbsp; One of the interesting ommissions from the T-SQL encryption statements is the statements necessary to backup and restore a symmetric key.&amp;nbsp; Why would you want to do this?&amp;nbsp; I can think of a couple of reasons off the top of my head:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You need to backup symmetric keys (and all other encryption keys, in fact) as part of an overall disaster recovery (DR) program.&amp;nbsp; If a server needs to be rebuilt you obviously need a way to restore all encryption keys.&lt;/LI&gt;
&lt;LI&gt;You need to implement the same symmetric keys on multiple servers.&amp;nbsp; There could be a couple of reasons for this -- you might encrypt data on one server and decrypt it on another, or you might be load-balancing across a server farm and need identical encryption keys on multiple servers simultaneously.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;It seems like a bit of an oversight to not include &lt;FONT face=courier&gt;BACKUP&lt;/FONT&gt; and &lt;FONT face=courier&gt;RESTORE SYMMETRIC KEY&lt;/FONT&gt; options in T-SQL, but in practice you can effectively achieve the same end results with the standard &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement.&amp;nbsp; Basically the &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement gives you an option to "clone" the exact same symmetric key on any SQL Server 2005 or 2008 instance, anywhere, at any time.&amp;nbsp; To create a cloneable symmetric key you need to specify two special &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; options:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; option, which SQL Server uses to generate a GUID (uniqueidentifier) for the key&lt;/LI&gt;
&lt;LI&gt;The &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; option, which SQL Server uses as key material to generate the actual key&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;As long as you specify the same values for the &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; options (and the same &lt;FONT face=courier&gt;ALGORITHM&lt;/FONT&gt;), your symmetric key will be exactly the same no matter where, when, or how many times&amp;nbsp;you create it.&amp;nbsp; To be honest, if I were creating a list, always use &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; would be listed in the top 10 list of SQL Server encryption best practices.&lt;/P&gt;
&lt;P&gt;Here's a quick sample demonstrating the &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement with &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; specified:&lt;/P&gt;
&lt;P&gt;&lt;FONT face=courier&gt;CREATE SYMMETRIC KEY test_aes128_key&lt;BR&gt;WITH KEY_SOURCE = 'I am the very model of a modern major general',&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDENTITY_VALUE = 'E pluribus unum',&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ALGORITHM = AES_128&lt;BR&gt;ENCRYPTION BY PASSWORD = &lt;A href="mailto:'p@$$w0rd'"&gt;'p@$$w0rd'&lt;/A&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement will create the same symmetric encryption key on any SQL Server 2005 or 2008 instance on which you run it.&amp;nbsp; This brings up another point, about security.&amp;nbsp; If the same &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; and &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; options can create the exact same encryption key on any of your servers, they will create the exact same encryption key on any of my servers, or any server owned by any hacker anywhere in the world.&amp;nbsp; So once you've run your &lt;FONT face=courier&gt;CREATE SYMMETRIC KEY&lt;/FONT&gt; statement, the &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; need to be handled like any other secure information.&amp;nbsp; Don't leave them lying around where just anyone can access them.&amp;nbsp; Store them with your certificates, key backups, and other confidential materials in a secure off-site location.&lt;/P&gt;
&lt;P&gt;So what happens when you don't specify the &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; options?&amp;nbsp; Well, basically SQL Server generates an unpredictable GUID to identify the symmetric key and the encryption key source material is randomly generated.&amp;nbsp; Basically you'll never regenerate the exact same key again.&amp;nbsp; Ever.&amp;nbsp; There could be situations where this would be handy.&amp;nbsp; The concept of "session keys" comes to mind.&amp;nbsp; A session key is basically a "temporary" key that's only required to encrypt data for a user during a single session.&amp;nbsp; Since it only exists for the life of the session, a totally randomly-generated key is just fine.&lt;/P&gt;
&lt;P&gt;For my tastes, it would make more sense to require &lt;FONT face=courier&gt;IDENTITY_VALUE&lt;/FONT&gt; and &lt;FONT face=courier&gt;KEY_SOURCE&lt;/FONT&gt; options by default. If you didn't want to specify both of these options there should be another option/indicator specifically to say that you want these options generated randomly.&amp;nbsp; At any rate, it's a good idea to get into the habit of treating these options as if they are mandatory unless they have a very specific special-purpose requirement (e.g., "session keys").&lt;/P&gt;</description></item></channel></rss>