A blog about SQL Server, Books, Movies and life in general
Sunday, December 16, 2007
GNET: Even Google Screws Up By Showing A Bunch Of MySQL Messages
Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/gnet/public_html.v2/libs/adodb/drivers/adodb-mysql.inc.php on line 359
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/gnet/public_html.v2/libs/adodb/drivers/adodb-mysql.inc.php on line 359
Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/gnet/public_html.v2/libs/adodb/drivers/adodb-mysql.inc.php on line 359
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/gnet/public_html.v2/libs/adodb/drivers/adodb-mysql.inc.php on line 359
Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/gnet/public_html.v2/libs/adodb/drivers/adodb-mysql.inc.php on line 359
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/gnet/public_html.v2/libs/adodb/drivers/adodb-mysql.inc.php on line 359
Warning: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/gnet/public_html.v2/libs/adodb/drivers/adodb-mysql.inc.php on line 359
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/gnet/public_html.v2/libs/adodb/drivers/adodb-mysql.inc.php on line 359
Friday, December 14, 2007
Would You Put Your Database In The Cloud?
Amazon launched a database in the cloud.
Amazon SimpleDB is a web service for running queries on structured data in real time. This service works in close conjunction with Amazon Simple Storage Service (Amazon S3) and Amazon Elastic Compute Cloud (Amazon EC2), collectively providing the ability to store, process and query data sets in the cloud. These services are designed to make web-scale computing easier and more cost-effective for developers.
Traditionally, this type of functionality has been accomplished with a clustered relational database that requires a sizable upfront investment, brings more complexity than is typically needed, and often requires a DBA to maintain and administer. In contrast, Amazon SimpleDB is easy to use and provides the core functionality of a database - real-time lookup and simple querying of structured data - without the operational complexity. Amazon SimpleDB requires no schema, automatically indexes your data and provides a simple API for storage and access. This eliminates the administrative burden of data modeling, index maintenance, and performance tuning. Developers gain access to this functionality within Amazon's proven computing environment, are able to scale instantly, and pay only for what they use.
Amazon Simple Storage Service is a pretty nice service they provide. But would you move your database to Amazon?
You can read more about Amazon SimpleDB here: http://www.amazon.com/b/ref=sc_fe_c_1_3435361_1?ie=UTF8&node=342335011&no=3435361&me=A36L942TSJ2AJA
They also have a developer guide, getting started guide, FAQs and pricing.
What do you think?
Thursday, December 13, 2007
SQL Server Business Intelligence Screencasts
Business Intelligence #01a: Introduction to Microsoft BI
This screencast provides an overview of Business Intelligence including basic database design concepts, ETL, reporting and analytics.
Business Intelligence #01b: Introduction to SQL Server 2005 Tools and Sample Databases
This screencast introduces the tools within the Microsoft Business Intelligence platform as well as a look at the Adventure Works OLTP and OLAP databases.
Business Intelligence #03a: Loading and Integrating Data from Multiple Sources
This screencast introduces the concept of Data Flow within SQL Server Integration Services (SSIS) including the use of Merge Join and Derived columns.
Business Intelligence #04a: Identifying and Importing New Customers by Using Fuzzy Lookup
This screencast introduces the concept of fuzzy lookup and highlights SQL Server Integration Services (SSIS) support within a Data Flow for performing these tasks.
Business Intelligence #04b: Implementing Slowly Changing Dimensions in the Data Flow
This screencast covers one of the most common scenarios when building a data warehouse. It introduces the concept of Slowly Changing Dimensions (SCD) and how to solve that challenge with SQL Server Integration Services (SSIS).
Business Intelligence #04c: Advanced Package Design
This screencast quickly covers some of the more advanced concepts such as Event Handlers, Logging and Package Configurations using SQL Server Integration Services (SSIS).
Business Intelligence #05a: Designing a Basic Report
This screencast covers the basics of using SQL Server Reporting Services (SSRS) including configuration of data sources and building basic reports. A few small tip, tricks and best practices are also covered.
Business Intelligence #05b: Adding Interactivity to a Report
This screencast shows the viewer how to add parameters and drill through to reports developed using SQL Server Reporting Services (SSRS).
Business Intelligence #06a: Developing a Report Model and Designing a Report Builder Report
This screencast cover building a Report Model in Business Intelligence Development Studio and show how to connect a report using SQL Server Reporting Services (SSRS).
Business Intelligence #07a: Deploying and Accessing Reports
This screencast shows how to embed and deploy SQL Server Reporting Services (SSRS) reports into your applications.
Business Intelligence #09a: Designing Dimensions
This screencast covers building dimensions on a cube built using SQL Server Analysis Services (SSAS).
Business Intelligence #09b: Advanced Dimension Design
This screencast covers optimization of the dimensions built in the previous screencast using SQL Server Analysis Services (SSAS).
Business Intelligence #09c: Using the Cube Wizard
This screencast covers the use of the Cube Wizard including some tips and tricks in SQL Server Analysis Services (SSAS).
Business Intelligence #09d: Introducing Cube Calculations
His screencast adds to the three previous screencasts by adding calculations to an SQL Server Analysis Services (SSAS) cube.
Business Intelligence #10a: Designing Reports on the UDM
This screencast covers optimization of the dimensions built in the previous screencast using SQL Server Analysis Services (SSAS).
Business Intelligence #10b: Exploring Analysis Features of Microsoft Excel 2007
This screencast covers the use of Excel as a tool for viewing data within a cube built with SQL Server Analysis Services (SSAS).
Business Intelligence #11a: More Analysis with Microsoft Excel 2007
This screencast covers using Excel as a powerful tool drill deeper into your information.
Business Intelligence #12a: Introducing Data Mining
This screencast covers general Data Mining techniques using SQL Server Analysis Services (SSAS).
Business Intelligence #12b: Introducing the Table Analysis Tool for Excel 2007
This screencast cover the use of Data Mining Add-Ins for Office using SQL Server Analysis Services (SSAS) as the data mining engine on table data within Excel.
Business Intelligence #14a: Building a PerformancePoint Scorecard
This screencast covers building and publishing scorecards with PerformancePoint.
The Strange Case OF Nulls And Case
http://groups.google.com/group/microsoft.public.sqlserver.programming/browse_thread/thread/126735827b7ae667#
This person had a case statement like this
SELECT
CASE
WHEN COL1 IS NULL THEN 'UNK'
WHEN COL1 = 'SUGAR' THEN 'SGR'
WHEN COL1 = 'SALT' THEN 'SAL'
WHEN COL1 = 'PEPPER' THEN 'PEP'
END AS items
FROM #INV_ITEMS
This still returned NULLS. Can you spot the flaw? there is no else statement, if there is a value which is not sugar, salt or pepper then a NULL will be returned. let's take a look.
Create this table
CREATE TABLE #INV_ITEMS (COL1 varchar(23))
INSERT #INV_ITEMS VALUES('SUGAR')
INSERT #INV_ITEMS VALUES('SALT')
INSERT #INV_ITEMS VALUES('PEPPER')
INSERT #INV_ITEMS VALUES('WASABI')
Now run this
SELECT
CASE
WHEN COL1 IS NULL THEN 'UNK'
WHEN COL1 = 'SUGAR' THEN 'SGR'
WHEN COL1 = 'SALT' THEN 'SAL'
WHEN COL1 = 'PEPPER' THEN 'PEP'
END AS items
FROM #INV_ITEMS
Output
--------
SGR
SAL
PEP
NULL
So we get a NULL, but which row is that? We just add the column to find out
SELECT Col1,
CASE
WHEN COL1 IS NULL THEN 'UNK'
WHEN COL1 = 'SUGAR' THEN 'SGR'
WHEN COL1 = 'SALT' THEN 'SAL'
WHEN COL1 = 'PEPPER' THEN 'PEP'
END AS items
FROM #INV_ITEMS
Output
--------
SUGAR SGR
SALT SAL
PEPPER PEP
WASABI NULL
Aha, it is the wasabi.
Let's try again by including an ELSE
SELECT Col1,
CASE
WHEN COL1 IS NULL THEN 'UNK'
WHEN COL1 = 'SUGAR' THEN 'SGR'
WHEN COL1 = 'SALT' THEN 'SAL'
WHEN COL1 = 'PEPPER' THEN 'PEP'
ELSE 'UNK'
END AS items
FROM #INV_ITEMS
Output
--------
SUGAR SGR
SALT SAL
PEPPER PEP
WASABI UNK
There we go, it is correct now.
Now let's make it more interesting by inserting a blank, a space and a NULL
INSERT #INV_ITEMS VALUES('')
INSERT #INV_ITEMS VALUES(' ')
INSERT #INV_ITEMS VALUES(NULL)
We can use a combination of NULLIF and RTRIM to filter out blanks, spaces and NULLS
SELECT Col1,
CASE
WHEN NULLIF(RTRIM(COL1),'') IS NULL THEN 'NullOrBlank'
WHEN COL1 = 'SUGAR' THEN 'SGR'
WHEN COL1 = 'SALT' THEN 'SAL'
WHEN COL1 = 'PEPPER' THEN 'PEP'
ELSE 'UNK'
END AS items
FROM #INV_ITEMS
Output
--------
SUGAR SGR
SALT SAL
PEPPER PEP
WASABI UNK
NullOrBlank
NullOrBlank
NULL NullOrBlank
And there it is
DROP TABLE #INV_ITEMS
Wednesday, December 12, 2007
Retrace : A SQL Profiler Trace Swiss Army Knife
Check it out here: http://blogs.msdn.com/khen1234/archive/2007/12/12/a-sql-profiler-trace-swiss-army-knife.aspx
SQL Teaser: LEN vs DATALENGTH
Without running this code what do you think will LEN and DATALENGTH return?
DECLARE @i int
SELECT @i =' 123456789 '
SELECT @i,LEN(@i),DATALENGTH(@i)
Tuesday, December 11, 2007
Office 2007 Service Pack 1 Available For Download
Access 2007
For third-party applications that use Data Access Object code to synchronize replicated information in a Microsoft Office Access™ 2007 database, Office Access 2007 no longer returns a run-time error that causes the application to close or time out.
Communicator 2007
Microsoft Office Communicator 2007 now presents more accurate presence information and does so with consistent visual cues.
- The icons used to display presence are modified so that users who are red-green colorblind can determine people’s presence status.
- Office Communicator 2007 no longer causes presence icons to flicker when multiple people appear simultaneously.
- Presence information in Office Communicator 2007 and other Microsoft Office applications is consistent in all scenarios.
- Microsoft Office Outlook® 2007 no longer starts in the background along with Office Communicator 2007.
Excel 2007
Several stability, general usability, and compatibility improvements have been incorporated into Microsoft Office Excel® 2007.
- Office Excel 2007 no longer stops responding in some instances when opening a workbook containing calculations.
- Office Excel 2007 workbooks that are saved in Page Break Preview mode and opened in Microsoft Office Excel 2003 no longer produce an error when switched to Normal view.
- When inputting calculations that should result in numbers 65,534 through 65,536, Office Excel 2007 no longer returns the display error of 100,001.
- Office Excel 2007 now retains custom colors on shapes in Excel 2003 worksheets.
- Office Excel 2007 no longer misplaces or wraps labels in charts when the workbook is reopened.
Groove 2007
For Microsoft Office Groove® 2007, issues surrounding the activation of new and previously retired accounts have been resolved.
- Office Groove 2007 no longer places a 60-day limit on retired accounts that are stored in backup files.
- When the auto-activation feature is turned on and invited users open an invitation file (.grv), they are no longer prompted for an activation key or notified of an unconfigured account.
InfoPath 2007 and InfoPath Forms Server
Microsoft Office InfoPath® 2007 benefits from a more consistent user experience, especially with online forms. - When users input data into an Office InfoPath 2007 form using a Web browser, the saved changes are now retained after closing and reopening the form.
- Font size no longer increases when pasting from one rich text box in Office InfoPath 2007 to another.
Outlook 2007
Microsoft Office Outlook 2007 benefits from a number of fixes and enhancements that make the popular messaging client more stable and easier to use.
- Office Outlook 2007 no longer closes unexpectedly when the junk e-mail rule is set to null.
- Body content in HTML-formatted e-mail messages now appears properly in the preview pane or when the message is opened.
- Items moved from an offline folder file (.ost) to a personal folder file (.pst) now display properly in the preview pane.
- In search folders, Office Outlook 2007 now shows the accurate count for unread items that are hidden.
- When scheduling a resource such as a meeting room in meeting requests, the public free/busy information for the resource is now complete and visible in Office Outlook 2007.
- When users forward plain-text e-mail messages with attachments, the body text is now retained.
- If the Mailbox Cleanup wizard starts while the user is dragging a message into a folder, Office Outlook 2007 no longer closes unexpectedly.
PowerPoint 2007
Fixes in Microsoft Office PowerPoint® 2007 make the presentation application even more reliable, especially when used in conjunction with Microsoft Office Outlook Web Access, Web sites that use forms authentication, or event macros.
- Users who have started an event macro in Office PowerPoint 2007 can now advance slides by right-clicking and then choosing Next or Previous.
- When users try to open a presentation in Office PowerPoint 2007 from a Web site using forms authentication, the presentation will now appear properly.
- Users can now open presentations in Office PowerPoint 2007 from e-mail attachments in Office Outlook Web Access.
- Office PowerPoint 2007 no longer crashes when the user programmatically accesses the parent property of the Hyperlinks Collection Object in the Office PowerPoint 2007 object model.
- Text formatting now behaves similarly to previous versions of PowerPoint, where new text retains the formatting of the deleted text instead of using the formatting of the character to the left.
Project 2007 and Project Server 2007
The 2007 Office system SP1 eliminates instances when either Microsoft Office Project 2007 or the accompanying Microsoft Office Project Server 2007 crashes due to a software error.
- Office Project 2007 no longer crashes when users click to view Windows account or Details in the Resources Information dialog box and then perform any other action.
- Office Project 2007 does not produce an error message when a link from one task accesses a task in a different project stored on Office Project Server 2007. This error only occurred when the linked project was renamed.
- Microsoft Office Project Web Access now makes task IDs available and allows users to enter a work estimate when creating a new task.
SharePoint Server 2007
Microsoft Office SharePoint® Server 2007 has improved manageability and compatibility.
- Office SharePoint Server 2007 now has the ability to be installed on Windows Server 2008 providing compatibility and support.
- ASP.NET AJAX has compatibility and support with Office SharePoint Server 2007 including examples for customer web parts build the AJAX 1.0 Control Toolkit and the AJAX 1.0 Extensions for ASP.NET (KB 941955)
- New manageability with STSADM commands for consolidating or repartitioning your content databases, renaming host named site collections, and the ability to scope the people picker to a specific active directory organizational unit.
- Advanced search results now include results with spaces in file names.
- The View by Modified Date function now works correctly in search results.
- Office SharePoint Server 2007 is now able to crawl case-sensitive Web content on computers not running the Windows® operating system.
- Office SharePoint Server 2007 can now index a public folder on a Microsoft Exchange Server with a backslash in the subject.
Visio 2007
Microsoft Office Visio® 2007 now properly redraws shapes when users apply a dynamic connector that is part of a group of shapes in Office Visio 2007.
Word 2007
By taking care of several small stability and usability details, Microsoft Office Word 2007 is a more useful and reliable tool for everyday document creation tasks.
- With Office Word 2007, users can now open and edit embedded objects that contain other embedded objects.
- When using smart documents in Office Word 2007, the Document Actions task pane no longer disappears when moving the pointer into the Reviewing pane. Additionally, task panes opened earlier no longer appear unexpectedly.
- Office Word 2007 properly creates and updates a table of contents in unprotected sections of documents that also contain sections protected for forms.
- Office Word 2007 no longer prints an extra page when users choose a printer with the duplex option enabled.
Download it here: http://www.microsoft.com/downloads/details.aspx?FamilyId=9EC51594-992C-4165-A997-25DA01F388F5&displaylang=en
Monday, December 10, 2007
The Sad State Of Programmers Part 2 : The In Person Interview
The point of the in person interview is to see if the person will fit in with the rest of the people in the organization. This is where you get asked such wonderful questions like:
How many gas stations are there in the state of New Jersey?
How would you move Mount Fuji?
These questions are usually asked by managers to see how you handle pressure. There is usually no real answer to these questions, you have to logically come up with an answer and solve this puzzle. For example there are 8 million people in New Jersey, these people have 6 million cars. A gas station gets between 3 and 4 cars per minute; this adds up to 4320 cars per day. You would need about 2000 gas stations to serve all these people. All these numbers could be completely wrong; the point is can you logically figure out the steps to ‘solve’ this problem. It doesn’t matter how brilliant you are, if the people that interview you feel that you are a mismatch personality wise you won’t get hired.
Some observations about the process
Dress in business attire
One person dressed very inappropriate, in fact when picking him up at the security desk we thought he was a delivery person. This is not a way to start the face to face interview. I will get into more detail in part 3 of what to wear and not to wear.
You are your own worst enemy
A person was given source code after the phone interview to study. When asked about the code during the face to face interview she mentioned that she just glanced over the code and did not really look at it. Why would you say something like that if you want to get hired? Now, would you consider hiring this person?
Be proper
Do not grimace like you have a squirrel chewing on your big toe while thinking about an answer. Do not chew on your glasses either while thinking about the answer. When you answer the question wrong, the interviewer gives the correct answer don’t say that is what I meant. If that is what you meant then you should have said so, there are of course exceptions but I am talking about real black and white scenarios.
Bring good code
When you bring source code make sure it is the best code you could possible bring. One person was asked about best practices and error handling; he seemed to know this pretty good. Then he offered to show his code, we noticed that he didn’t have any of these best practices in his code. His proc was called sp_ProcName, error handling was wrong and a bunch of other things. In this case it would have been better if the person did not volunteer to show the code.
And now the questions.
I decided to ask every person these exact questions in the face to face interview; depending on how these were answered I would ask a bunch more questions. There are a couple of questions which you couldn’t answer wrong and I did not count them as toward the total score. Here is a list of some of the questions (Alex don’t get mad), I will comment on these questions and give the answers.
How many bytes can you fit in a row, do you know why
How do you enforce that only values between 1 and 10 are allowed in a column
How to check for a valid date if it is passed in as a string
Can you name the 4 isolation levels in SQL Server 2000
How would you select all rows where the date is 20061127
Name some differences between isnull and coalesce
If you create a local temp table and then call a proc is the temp table available inside the proc
What is a SQL injection
Update trigger to capture changed information
Which naming conventions did you use?
Name some best practices which you implemented
Select 3/2
Decimal(6,5)
Create table with PK symbol 10 characters, price 8 digit precision
Add clustered index to that table
What does set xact_abort on
Select * from table where ID <> 1
Favorite SQL Server book
How do you keep your SQL skills up to date?
How many bytes can you fit in a row, do you know why?
I am looking for one of these answers
8K
8060 bytes
Same as a page
8K + overflow column/text columns
If a person does not know the answer to this question then that is ok.
How do you enforce that only values between 1 and 10 are allowed in a column?
I am looking for check constraint as the answer. A bunch of people didn’t answer anything, some answered trigger and one said you should never check in the DB but in the application itself.
How to check for a valid date if it is passed in as a string?
The answer I am looking for is ISDATE() Some people knew this answer, some people answered “convert to datetime and then check for the error” one person said “parse the string”. A bunch of people didn’t answer anything at all
Can you name the 4 isolation levels in SQL Server 2000?
Another nice to have question, if you don’t know it then is not the end of the world. I will also ask the default transaction level
How would you select all rows where the date is 20061127?
I will draw a table on the board with values like these
2007-12-06 15:36:10.293
2007-12-07 00:00:00.000
2007-12-07 15:36:10.293
2007-12-07 15:36:10.293
2007-12-08 00:00:00.000
I am looking for the 3 rows which start with 2007-12-07
The answer I want is this
WHERE date >= ‘20061127’
AND date < ‘20061128’ I don’t want between because it will grab the 2007-12-08 value also, I don’t want convert because that causes an index scan. Less than half the people get the correct answer. Some stuff to read: Do You Know How Between Works With Dates? http://sqlservercode.blogspot.com/2006/10/do-you-know-how-between-works-with.html
How Are Dates Stored In SQL Server?
http://sqlservercode.blogspot.com/2006/11/how-are-dates-stored-in-sql-server.html
The ultimate guide to the datetime datatypes
http://www.karaszi.com/SQLServer/info_datetime.asp
Name some differences between ISNULL and COALESCE
The main answer I am looking for is that ISNULL can only use 2 values while COALESCE can use a lot more. If the person knows other differences then that is also good. I was surprised at the number of people who never heard of COALESCE. Below is some code which shows the differences
There are three major differences besides being ANSI or not between COALESCE and ISNULL
1) COALESCE correctly promotes its arguments to the highest data type in the expression list, ISNULL does not
2) ISNULL can only work with 2 values while COALESCE can take a lot more
3) The alternate value takes the length of the first vale with ISNULL, with COALESCE this doesn't happen
Let's get started, run the following blocks of code
The result is 7, integer math
SELECT 15 / ISNULL(CONVERT(INT,NULL), 2.00)
The result is 7.5, which is correct
SELECT 15 / COALESCE(CONVERT(INT,NULL), 2.00)
You will see that the result is not the same ISNULL does integer math while COALESCE does not
COALESCE correctly promotes its arguments to the highest data type in the expression list.
ISNULL just looks at the first datatype, which is an integer (15) and makes everything an int
COALESCE looks at 2.00 and 15 and then promotes the integer to decimal
Another example is returning the first non null value, ISNULL can only take 2 values while COALESCE can take a whole lot more
Here we have 4 variables and all except for one are null
DECLARE @Var1 VARCHAR(20)
DECLARE @Var2 VARCHAR(20)
DECLARE @Var3 VARCHAR(20)
DECLARE @Var4 VARCHAR(20)
SELECT @Var4 = 'ABC'
--This will return ABC
SELECT COALESCE(@Var1,@Var2,@Var3,@Var4)
Last example.
ISNULL returns NOT while COALESCE returns Not There.
DECLARE @v VARCHAR(3)
SELECT COALESCE(@v,'Not There')
SELECT ISNULL(@v,'Not There')
The alternate value takes the length of the first value with ISNULL, with COALESCE this doesn't happen
If you create a local temp table and then call a proc is the temp table available inside the proc?
The answer is yes and the code is below
--create proc
CREATE PROC TestProc
AS
SET NOCOUNT ON
SELECT * FROM #temp
GO
--create our temp table
CREATE TABLE #temp (id int)
INSERT #temp VALUES(1)
INSERT #temp VALUES(2)
INSERT #temp VALUES(3)
--exec proc
EXEC TestProc
What is SQL injection?
People either knew or did not know about SQL injection, the ones who knew also knew what to do to prevent it. A little less than half the people interviewed knew what it was.
Some stuff to read:
SQL injection cheat sheet.
http://ferruh.mavituna.com/makale/sql-injection-cheatsheet/
The Curse and Blessings of Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html
Update trigger to capture changed information
In drew two tables on the whiteboard and explained to the people that I wanted to move data into a history table only when the value in a certain column changed. I was looking for several things
If the person knew about inserted and deleted tables
If the person would code the trigger for multi row statements and not assign the value to a variable
If the person knew about IF UPDATE(Column) and that this was true even if the table was updated with the same value
If the person would join inserted and deleted to make sure no row would be inserted if the value didn’t change
Some stuff to read:
Fun With SQL server Update Triggers
http://sqlservercode.blogspot.com/2005/12/fun-with-sql-server-update-triggers.html
What naming conventions did you use?
Here I wanted to hear if the person had any standards, I would also ask for an example of a proc name hoping sp_ProcName wouldn’t be answered
Some stuff to read:
The ISO organization has a document on their site. The one that deals with naming conventions is 11179-5 The link will point to a zip file which has a pdf file in it. The TOC of this pdf file is below Contents Foreword 1 Scope 2 Normative references 3 Terms and definitions 4 Data Identifiers within a registry 5 Identification 6 Names 6.1 Names in a registry 6.2 Naming conventions 7 Development of naming conventions 7.1 Introduction 7.2 Scope principle 7.3 Authority principle 7.4 Semantic principle 7.5 Syntactic principle 7.6 Lexical principle 7.7 Uniqueness principle Annex A (informative) Example naming conventions for names within an MDR registry Annex B (informative) Example naming conventions for Asian languages
What best practices did you implement?
There is a whole range of possible answers here and I won’t get into detail.
Select 3/2
When I wrote Select 3/2 on the board and ask what this would return several people looked at me if I was crazy. The answer is of course 1 because of integer math. I ask this question because we run reports which deal with calculation with integers. Take a look at this code to see what you can do to ‘fix’ the issue
Run this
--Integer math
DECLARE @Val1 INT,@val2 INT
SELECT @Val1 =3, @val2 =2
SELECT @Val1/@Val2
GO
It returns 1
Now run this
DECLARE @Val1 INT,@val2 INT
SELECT @Val1 =3, @val2 =2
--Implicit
SELECT @Val1/(@Val2*1.0)
--Explicit
SELECT CONVERT(DECIMAL(18,4),@Val1)/@Val2
GO
Both of those return 1.50000000000000
So what does @val2*1.0 do? well run this
DECLARE @Val1 INT,@val2 INT
SELECT @Val1 =3, @val2 =2
SELECT CAST(SQL_VARIANT_PROPERTY(@val2*1.0,'BaseType') AS VARCHAR(20)) + '(' +
CAST(SQL_VARIANT_PROPERTY(@val2*1.0,'Precision') AS VARCHAR(10)) + ',' +
CAST(SQL_VARIANT_PROPERTY(@val2*1.0,'Scale') AS VARCHAR(10)) + ')'
As you can see it is numeric(13,1)
Decimal(6,5)
What is the greatest value that Decimal(6,5) can hold? A lot of people answered 999999.99999 which is wrong of course. The total number of numbers is 6 and 5 of those are after the comma. So the answer is 9.99999. Run this to try it out for yourself.
Create table with PK symbol 10 characters, price 8 digit precision
I would tell people to create a table with 2 columns
1 with a column named symbol variable character 10 in length, it would also be a primary key
Price which was decimal and can hold a number as big as 999999.99999999
They had to do this on the whiteboard in T-SQL (create table…..)
Most people got the PK syntax wrong; some people got the decimal wrong. The reason I am asking this question is because we can’t go on a production machine with Enterprise Manager and start clicking. You might not have permissions to make changes, you need to supply a script which other people might run.
Add clustered index to that table
My next question would be to add a clustered index to that table. The correct answer would be you can’t since the table has a primary key which is a clustered index by default
What does set xact_abort on do
Only one person answered this question correctly, this was another nice to know question. I did explain to people why you would use this, sometimes you cannot trap the error and this statement will enable you to rollback everything up until that point.
Some stuff to read:
Implementing Error Handling with Stored Procedures
http://www.sommarskog.se/error-handling-II.html
Error Handling in SQL Server – a Background.
http://www.sommarskog.se/error-handling-I.html
Select * from table where ID <> 1
I would draw a table with three rows, the values being 1, 2 and null. Then I would ask what would be returned after running this query
SELECT * FROM #temp WHERE id <> 1
A lot of people chocked on this one, the answer is 2 of course, null will not be returned. Test it out for yourself
CREATE TABLE #temp (id int)
INSERT #temp VALUES(1)
INSERT #temp VALUES(2)
INSERT #temp VALUES(null)
SELECT * FROM #temp WHERE id <> 1
Some stuff to read:
NULL trouble In SQL Server Land
http://sqlservercode.blogspot.com/2006/01/null-trouble-in-sql-server-land.html
NULL - The database's black hole
http://sqlblog.com/blogs/hugo_kornelis/archive/2007/07/06/null-ndash-the-database-rsquo-s-black-hole.aspx
The logic of three-valued logic
http://sqlblog.com/blogs/hugo_kornelis/archive/2007/07/17/the-logic-of-three-valued-logic.aspx
Dr. Unknown, or how I learned to stop worrying and love the NULL
http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/22/dr-unknown-or-how-i-learned-to-stop-worrying-and-love-the-null.aspx
What if null if null is null null null is null?
http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/30/what-if-null-if-null-is-null-null-null-is-null.aspx
Favorite SQL Server book
Here something bizarre happened; there were several people who did not have a SQL Server book at all. I did not understand this; how do you not have a SQL server books as a developer? A bunch of people listed Ken Henderson’s Guru book, some of them listed Inside SQL Server and one person answered SQL Server 2005 unleashed (I have the 2000 version, I should check this one out). In part three I will give you a list of my favorite books.
How do you keep your SQL skills up to date?
I am looking for websites, books, blogs, conferences, webinars, podcasts etc. Some people answered Books On Line. One person answered certification (I will address certification and my dislike of them in part 3). I was surprised by the difficulty that people had in answering this question. SQL Server Central was a popular website as well as DevX and MSDN. Nobody answered podcast at all. I would ask people if they played around with the latest CTP of SQL Server 2008, most of them were not aware that this was available to the general public. I did interview a bunch of SQL Server authors and I asked them what they did or would do to master SQL. You can read those interviews by clicking on the links below
Louis Davidson
Itzik Ben-Gan
Ken Henderson
Adam Machanic
Kalen Delaney
That was it fort part two, I originally wanted to put more content here but I was afraid it would become too long, I moved some of that stuff to part three.
Saturday, December 08, 2007
Video: Microsoft SQL Server 2008 Nov CTP - Spatial (Part 1/3)
Watch it here: http://channel9.msdn.com/ShowPost.aspx?PostID=363495#363495
Wednesday, December 05, 2007
The Most Natural Set Option
this is what this means, in English....
Set the setting ANSI NULL Default Off to ON
Why not just SET ANSI_NULL_DFLT [ON|OFF]?
This is even worse than SET NOCOUNT ON
Sunday, December 02, 2007
The Sad State Of Programmers Part 1 : The Phone Interview.
Part 1 The phone interview.
Part 2 The face to face interview.
Part 3 Some tips and observations
A while back I posted that we are looking for a SQL/.NET/FoxPro developer. I did this because we had a real hard time finding this person. I am happy to inform you that we did find this person and he will start in two weeks. Interestingly enough we hired the person with the least years of experience (on paper). This person knew more that people with three times his experience in years.
These days when looking for a programmer you have to do phone interviews if you don’t want to waste an incredible amount of time. A phone interview enables you to assess the skill set of a potential employee without wasting time by picking him up, getting a security badge, booking a conference room etc. A phone interview is also good for the candidate since he/she doesn’t have to travel or dress up to do the interview.
Some things are difficult to ask over the phone but if the candidate looks (or should that be sounds) good then you can ask those questions when you bring the person in. Some people will prepare for a phone interview by having all their books and notes in front of them. They will ask you to repeat the question and while you do so you can hear them flipping pages frantically. So you might be able to cheat on the phone interview but be assured that if you do not know your stuff that you will fall flat on your face on a face to face interview (no pun intended).
One thing I never understood is the fact that it takes a person one minute to answer a question. You either know or don’t know the question. Keep your answers concise, do not spend 3 minutes explaining to me what the difference is between a clustered and non clustered index.
I had to reword my questions slightly because when I asked a question like “Do you know what the difference is between a clustered index and a non clustered index?” some people would reply “yes”. Because of that I changed the question to “Describe what the difference is between a clustered index and a non clustered index?”
Do not shoot yourself in the foot by giving me additional information which is wrong. I asked for the fastest way to empty a table. Almost every single person who knew about truncate added that you cannot rollback a truncate statement. I wrote about that myth a couple of months ago: SQL Myth: Truncate Cannot Be Rolled Back Because It Is Not Logged
I tend to ask between 20 and 40 questions, if I see the candidate’s skill is not good enough I don’t ask everything. Some of the questions are esoteric but I simply ask these questions to get a feel of the overall skill level; it doesn’t matter if they answer these wrong. You can find a list of question here: How Well Do You Interview And Do You Use Wizard Driven Programming?
Here are some interesting answers from the interviews.
Almost every single person answered that an index scan is better than an index seek.
There were several people with SQL Server 2005 experience, these people couldn’t name one single new thing introduced in SQL Server 2005. I asked about windowing functions, DMVs, pivot, apply and more, this was all Greek to them. One person had on her resume that she developed an app in SQL Server 2005. When I asked about her experience she told me she just started to read about SQL Server 2005. This is a big show stopper, sometimes headhunters/recruiters will tell you to just add it to your resume, I wouldn’t do it because it makes you look bad. If the SQL Server 2005 experience is not true what else could be made up? One person had on his resume that he optimized complex stored procedures, when I asked how he did it, he replied that he only selected the rows he needed instead of the whole table. This obviously didn’t answer my question.
That is it for the phone interview, part 2 will be up in a day or two.
EURO 2008 draw
Group A: Switzerland, Turkey, Portugal, Czech Republic
1. Portugal, Czech Republic.
Group B: Austria, Poland, Germany, Croatia
1.Croatia, 2. Germany.
Group C: Holland, France, Romania, Italy
1. France, 2. Holland.
Group D: Greece, Russia, Spain, Sweden
1. Spain, 2. Greece.
Saturday, December 01, 2007
Screencast: SQL Server 2008 - Table valued parameters
Table-valued parameters are a new parameter type in SQL Server 2008 and are declared by using user-defined table types.
Watch the screencast(SWF)
Watch the screencast(WMV)
Tuesday, November 27, 2007
Integer Math In SQL Server
SELECT 3/2
If you said 1.5 then you are wrong! The correct answer is 1, this is because when doing division with 2 integers the result will also be an integer.
There are two things you can do
1 multiply one of the integers by 1.0
2 convert one of the integers to a decimal
Integer math is integer result
DECLARE @Val1 INT,@val2 INT
SELECT @Val1 =3, @val2 =2
SELECT @Val1/@Val2Result 1
Convert explicit or implicit to get the correct answer
DECLARE @Val1 INT,@val2 INT
SELECT @Val1 =3, @val2 =2
--Implicit
SELECT @Val1/(@Val2*1.0)
--Explicit
SELECT CONVERT(DECIMAL(18,4),@Val1)/@Val2
Result 1.50000000000000
Visual Studio 2008 Training on Channel 9
This session was presented by Jaime Rodriguez
Come and learn how to build Windows Presentation Foundation (WPF) applications with the help of the new WPF designer in Visual Studio 2008 This session focuses on the construction of a real-world application demonstrating how to get the best out of the designer's capabilities. Learn the basics of building WPF applications in the Visual Studio 2008 WPF designer; have a clear view on when you'll want to work in XAML Code and on the Visual Studio design surface to get your WPF application built; and see how you can use Microsoft Expression Blend in conjunction with Visual Studio 2008 WPF designer.
Watch the screencast here: http://channel9.msdn.com/ShowPost.aspx?PostID=359715#359715
VS2008 Training Kit: What's New in Windows Presentation Foundation 3.5
This session was presented by Kevin Moore
Learn about the work being done in the Orcas release of WPF, including improved 3D with UIElement3D, increased animation smoothness, better cookie and FireFox plug-in support for XBAPs, as well as support for AddInControl, LINQ, ADO.NET and much more!
Download it here: http://channel9.msdn.com/ShowPost.aspx?PostID=359713#359713
VS2008 Training Kit: Introduction to Silverlight
This session was presented by Adam Kinney
Silverlight is a cross platform UI framework for creating compelling Web experiences. Come learn the high-level architecture of Silverlight and the tools that are available to build Silverlight applications.
Download it here: http://channel9.msdn.com/ShowPost.aspx?PostID=359712#359712
VS2008 Training Kit: Building Web Applications with Visual Studio 2008
This session was presented by Ryan Dunn
This session covers the new design and development features in Visual Studio 2008 for creating rich web applications. Topics include the new CSS and HTML design tools, much improved Javascript Intellisense and debugging support, and the new ASP.NET 3.5 controls supporting LINQ and AJAX.
Download it here: http://channel9.msdn.com/ShowPost.aspx?PostID=359711#359711
VS2008 Training Kit: Introduction to ASP.NET AJAX
This session was presented by Steve Marx
In this session, you'll learn how to use ASP.NET AJAX to build a richer, more responsive user experience. Topics include partial rendering, web services, structured scripting, and integration with Silverlight.
Download it here: http://channel9.msdn.com/ShowPost.aspx?PostID=359706#359706
Monday, November 26, 2007
.NET Framework 3.5 Common Namespaces and Types Poster Available For Download
Get it here: http://www.microsoft.com/downloads/details.aspx?FamilyID=7b645f3a-6d22-4548-a0d8-c2a27e1917f8&DisplayLang=en
Sunday, November 25, 2007
World Cup Soccer 2010 Qualification - UEFA draw, England And Croatia In The Same Group Again!
Portugal, Sweden, Denmark, Hungary, Albania, Malta
Group 2:
Greece, Israel, Switzerland, Moldova, Latvia, Luxembourg
Group 3:
Czech Rep., Poland, Northern Ireland, Slovakia, Slovenia, San
Marino
Group 4:
Germany, Russia, Finland, Wales, Azerbaijan, Liechtenstein
Group 5:
Spain, Turkey, Belgium, Bosnia-Herzegovina, Armenia, Estonia
Group 6:
Croatia, England, Ukraine, Belarus, Kazakhstan, Andorra
Group 7:
France, Romania, Serbia, Lithuania, Austria, Faroe Islands
Group 8:
Italy, Bulgaria, Ireland, Cyprus, Georgia, Montenegro
Group 9:
Netherlands, Scotland, Norway, Macedonia FYR, Iceland
Croatia and England again in the same group :-)
Group 7 doesn't look easy either
Friday, November 23, 2007
Whitepaper on Malware to Attack Databases
Brian Kelly on his blog mentiones a whitepaper by Cesar Cerrudo: Data0: Next generation malware for stealing databases. This whitepaper describes how malware could be crafted to steal information out of databases.
The attack will use the following techniques:
- Discovery
- Exploitation
- Escalate Privileges (if necessary)
- Cover Tracks
Print it out and read it while you wait in line on Black Friday
Thursday, November 22, 2007
Just For My English Friends
England and Croatia in the same group again for World Cup 2010 qualifications:
Group 6: Croatia, England, Ukraine, Belarus, Kazakhstan, Andorra
Wednesday, November 21, 2007
Thanksgiving SQL Teaser COUNT
USE tempdb
GO
CREATE TABLE Customer (CustomerID INT PRIMARY KEY)
INSERT Customer VALUES (1)
INSERT Customer VALUES (2)
INSERT Customer VALUES (3)
INSERT Customer VALUES (4)
SELECT COUNT(*) Customer