Learning Mandarin: The circle of fear (a simple Chinese joke)

In a Chinese learning Facebook group, a friend posted this simple Chinese joke. I thought I'd share it.

The core word you need to know is:

(Pà) which means "fears" or "is afraid of" (in this context).

And from there, I think you can work out the rest of the joke. (Never spoil a joke by explaining it too far).

Learning Mandarin

I'll write more soon on the best methods for learning Mandarin. If you want to get a taste for it in the meantime though, my current favorite site is iTalki, and my favorite teacher by far is Amy He. If you decide to try it, click here and it's cheaper for both you and me.

 

 

Opinion: What's wrong with Yes and No ?

IT people get accused all the time, of being out of touch with other people, and for using language that is overly complex.

So many times lately, I've come across dialog boxes like the one above.

It's clearly asking a Yes/No question. Why on Earth doesn't it give the user Yes and No as answer choices?

Why do we do this to users?

If you're building apps, please don't do this. If you ask a question that in normal language would lead to a Yes or No response, please give the users Yes and No as answer choices.

SQL Interview: #5: System defined primary key names

This is a post in the SQL Interview series. These aren't trick or gotcha questions, they're just questions designed to scope out a candidate's knowledge around SQL Server and Azure SQL Database.

Section: Development
Level: Intro

Question:

If you create a table using the following code, what would the name of the primary key constraint look like?

How could you specify the name?

Can you suggest any advantages of providing a name?

Answer:

If you don't specify the name of a primary key, the system will allocate a name similar to this:

PK__Customer__9AA3001A15FDE023

It's basically PK some underscores, part of the table name, some more underscores, and part of a GUID string, chosen to be unique.

To specify the name, put CONSTRAINT and the name before PRIMARY KEY like this:

Some advantages of providing specific names are:

  • A specific name is more meaningful. It's not obvious from the system-generated name above, even which table it's associated with.
  • If you ever need to modify the constraint, you'll need to know its name. It makes it much easier to write scripts when you know the name, instead of having to write code to look it up each time.
  • If the table is recreated, it will usually end up with a different name for the constraint. If you use database comparison tools, the name might be flagged as a difference between databases created with the same script. (Note that some database comparison tools have options to ignore system-generated names).

 

Book Review: The Other Animals

I love short stories, so I was really excited when one of the Audible Originals a while back was a set of eight short stories. The Other Animals is a compilation of short stories by a variety of authors (Daniel Mallory Ortberg, Ken Liu, R. Eric Thomas, Lulu Miller, Shruti Swamy, Max McClure, Kaeli Swift, and Kelly Weinersmith).

I really didn't know what to expect with this book. The ratings from other listeners are high. Audible describe it as being "written by a crew of scientists, literary writers, and comics, and informed by animal behavioral science – explores what animal perspectives can show humans about the world we all share."

All the stories are tales told from the perspective of animals.

I have to admit that I did find some of it cute, but I really struggled to persevere with it. There's a story where a vulture contemplates his role in killing; a story where a worm breaks up with a snail; another story where a whale falls in love with a song.

Some listeners really, really liked it. For the life of me, I couldn't find it "gripping" as others did.

Even though I like a lot of "off the wall" things, I'm clearly not the target audience for this book. I just couldn't bring myself to finish it. Life is too short.

The Verdict

There are obviously people that love this book but clearly I'm not the target audience. 3 out of 10 for me.

 

 

SQL Interview: #4: INSERT statements and column lists

This is a post in the SQL Interview series. These aren't trick or gotcha questions, they're just questions designed to scope out a candidate's knowledge around SQL Server and Azure SQL Database.

Section: Development
Level: Medium

Question:

When you are writing an INSERT statement in T-SQL, the column list is usually optional.

Why would including it be a good idea? When would it ever be required (i.e. not optional)?

Answer:

If you don't include a column list, SQL Server will try to match up the values you are inserting, with the list of columns in the table. It will do that in column_id order (based on what you see in sys.columns) and it will ignore any columns that are auto-generated like IDENTITY columns, computed columns, and rowversion columns.

Sometimes you aren't wanting  to insert all the other columns. Using a column list allows you to specify just the columns that you are inserting.

This is also a good idea as it produces less fragile code. If the table gets redefined with a different order for the columns, your INSERT statement would still work if you have listed the columns you are inserting, in the order that you are providing them.

Column lists are usually optional but recommended, but they are required when you are inserting into a table with SET IDENTITY_INSERT set to ON.

 

T-SQL 101: #92 Categorizing output rows by using NTILE

I've been talking about the basic window functions in T-SQL and one that's not well known but is surprisingly useful is NTILE.

I'm not sure on the name but it's probably short for percentile. I don't know why they didn't call it a slightly more meaningful name, but what it says is take the output and break it up into bands or chunks of data.

So if I say NTILE(10), that'll give me a tenth of the rows with a value of 1, another tenth of the rows with a value of 2, and so on.

This is actually really, really useful if you're trying to do things like populate a graph with the bottom 10%, the next 10% and so on. This function would return you the required tiling for that graph i.e. which band each value needs to go into. In the example, I've called it customer band, but I've just gone through CinemaID order and so they start all being number one. Then there would have been a tenth of them with number 2. A tenth of them with number 3 and so on, and the end of the list is shown on the right. There the the last ones will have the value 10.

This can be very useful.

Learning T-SQL

It's worth your while becoming proficient in SQL. If you'd like to learn a lot about T-SQL in a hurry, our Writing T-SQL Queries for SQL Server course is online, on-demand, and low cost.

Learning Mandarin: Measure words for animals

In an earlier post, I started discussing measure words, and talked about the common measure words for people. In this post, I'll look at measure words for animals.

In English, we have many of these and they are confusing e.g. a flock of geese, but a murder of crows, etc.

While you could use the standard measure word (Gè) for animals in Chinese, you'll sound a lot better if you use the appropriate specific measure words.

(Tiáo) is one of my favourite measure words. It's not just use for animals. It's used for most long skinny things. Here are some examples for animals:

一条蛇 (yì tiáo shé) is "a snake". Now that makes sense as they're pretty long and skinny. But others use this, even though they are less long and skinny.

一条鱼 (yì tiáo yú) is "a fish".

一条龙 (yì tiáo lóng) is a surprising one. It's "a dragon". Not sure they're all that long and skinny.

I've also seen this measure word applied to things like dogs, although they have better measure words.

一只狗 (yì zhī gǒu) is "a dog"

一只鸟 (yì zhī niǎo) is "a bird"

一只老鼠 (yì zhī lǎo shǔ) is "a mouse"

一只熊猫 (yī zhǐ xióngmāo) is "a panda"

(tóu) literally means "head" on its own, but as a measure word, it's used for some larger animals:

一头牛 (yì tóu niú) is "a cow"

一头猪 (yì tóu zhū) is "a pig"

But even though horses seem pretty similar, they have a different measure word:

一匹马 (yì pǐ mǎ) is "a horse"

Learning Mandarin

I'll write more soon on the best methods for learning Mandarin. If you want to get a taste for it in the meantime though, my current favorite site is iTalki, and my favorite teacher by far is Amy He. If you decide to try it, click here and it's cheaper for both you and me.

 

 

SQL Interview: #3: Are bit columns useful in indexes?

This is a post in the SQL Interview series. These aren't trick or gotcha questions, they're just questions designed to scope out a candidate's knowledge around SQL Server and Azure SQL Database.

Section: Query Performance
Level: Medium

Question:

In SQL Server a column that is defined with a bit data type can only have the values 0, or 1, or it can be NULL if the column allows it.

Given such a small number of possible values, are bit columns ever useful in indexes? Can you give an example of when they might or might not be useful?

Answer:

The range of potential values for a data type is not the issue. The selectivity of the values is critical.

So while an index that includes a value that's evenly distributed (i.e. it's zero in half the rows and one in the other half), is unlikely to be useful, a highly skewed distribution of values can make them very useful.

For example, a query that's finding a hundred incomplete tasks amongst millions of completed tasks, will most certainly find the column useful in an index. It's also an example of what would potentially be useful in a filtered index.

For a more complete discussion, see this previous blog post.

 

SQL Interview: #2: NULL and NOT NULL when defining Columns in Tables

This is a post in the SQL Interview series. These aren't trick or gotcha questions, they're just questions designed to scope out a candidate's knowledge around SQL Server and Azure SQL Database.

Section: Development
Level: Medium

Question:

When you are writing a CREATE TABLE statement to define a new table, after each column, you can write NULL or NOT NULL, but doing that is optional.

Why is it a good practice to include it, and what happens if you leave it out? Are the columns defined as NULL or as NOT NULL? Are there any exceptions to this?

Answer:

If you leave it out NULL and NOT NULL in a column definition, many factors determine how the column will be defined. For system-defined data types, SQL Server uses a combination of ANSI_NULL_DFLT_ON SET option and the ANSI_NULL_DEFAULT_ON database option to determine which value to use.

There are several exceptions. For a few examples, a column declared as part of a PRIMARY KEY will bet set to NOT NULL regardless of settings. SPARSE columns will always be set to NULL. For CLR types and alias data types, the NULLability is determined by the data type.

It's always a good practice to write NULL or NOT NULL in the table definition.

Book Review: Living Forward by Seth Godin

I have a lot of people who recommend books to me. I order many of them. If the book has impressed one of my friends, I'm keen to see what they liked about it. That's how I came to read Living Forward: A Proven Plan to Stop Drifting and Get the Life you Want by Seth Godin.

The title is making a pretty big claim, but the content? It's ok.

There are a great number of books that suggest you need to do some basic things:

  • Decide where you are
  • Decide where you want to be
  • Fill in the gaps

So from that point, there's nothing Earth-shattering there. I did like the way though that Godin provided a pretty specific methodology for achieving the outcomes you want. It's based around being both deliberate and proactive.

The friends that liked this book, particularly mentioned that it helped them break out of a cycle of procrastination. We all can suffer from that, but some suffer more than most, and this could be the prompt they need.

Godin also, of course, keeps concepts of a balanced life in mind, but he talks about just how easy it can be to simply drift through life.

The Verdict?

I'd give this one 6 out of 10. I didn't find anything very new, but I did like the structure it provided. I know I have a number of friends who could benefit from the thinking.