navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

SQL Server 2012 New Features

SQL Server 2012 New Features

with Martin Guidry

 


SQL Server 2012 is the first cloud-ready information platform for Microsoft. In this course, author Martin Guidry explores its new possibilities, showing you how to protect, unlock, and scale the power of your data, and work with a variety of devices and data sources. The course also provides an overview on obtaining, installing, and running SQL Server 2012 and will be of immense interest to anyone considering upgrading or installing this latest edition.
Topics include:
  • Choosing an edition
  • Finding and downloading SQL Server 2012
  • Using FileTables to enhance FileStream
  • Searching unstructured data semantically
  • Searching text
  • Exploring the Watch, Quick Watch, and Quick Info windows
  • Creating user-defined server roles
  • Understanding the changes to replication
  • Exploring new types of indexes and new options on indexes
  • Accommodating changes to database structure

show more

author
Martin Guidry
subject
Developer, Servers, Databases
software
SQL Server 2012
level
Intermediate
duration
1h 50m
released
Nov 16, 2012

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:04Hi! I am Martin Guidry! And welcome to SQL Server 2012 New Features.
00:10In this course, we'll look at numerous innovative features Microsoft added to its latest release of SQL Server.
00:16I'll start by showing you how to search and manipulate files using the new file tables.
00:21We'll write efficient code that pages through data, and handles errors elegantly.
00:26Then, I'll show you how to use SQL Server Management Studio to debug your queries more
00:32effectively by setting breakpoints, using the Watch windows, and understanding the improvements to IntelliSense.
00:40We'll see how to store user passwords at the database level instead of the server level.
00:45We'll cover all these features along with some other tools and techniques and we'll
00:49try to have a little fun along the way too.
00:51Now let's get started with SQL Server 2012 New Features.
Collapse this transcript
What you should know
00:00This course is designed for database developers with experience in a previous version of Microsoft
00:05SQL Server, such as SQL Server 2008, or SQL Server 2005.
00:11You should have a working knowledge of the T- SQL language, queries, indexes, full-text
00:17search, and some experience debugging T-SQL.
00:21If you'd like to review some of these topics before going through this course, you can
00:25do so here in the lynda.com online training library.
00:29Look for the course SQL Server 2008 Essential Training with Simon Allardice.
Collapse this transcript
Using the exercise files
00:00The exercise files for this course are arranged by chapter in the folder here on my desktop.
00:05Each chapter folder contains text files that I use for copy and pasting snippets of code
00:11into SQL Server Management Studio.
00:14These code examples are largely used to demonstrate concepts, and I'll describe what they do as I use them.
00:20The exercise files for this course are available freely to all members, and with that in mind,
00:26let's get started with SQL Server 2012 New Features.
Collapse this transcript
1. Getting Started
Finding and downloading SQL Server 2012 Express edition
00:00To complete the exercises for this course, you'll need access to a Microsoft SQL Server 2012 machine.
00:07Because we're focusing on the new features of 2012, these things would not be available
00:12in Microsoft SQL Server 2008 or 2005.
00:16So you will certainly need a 2012 edition.
00:19You can use just about any version.
00:21So if you have access to Enterprise or Developer edition, go ahead and use those.
00:26But if you don't, I'm going to show you how to download a free version called Express.
00:30Microsoft has released a few of their tools recently in Express versions.
00:35The Express versions are free for anyone to use for testing, development, learning, and training.
00:40You can not put it in production, but you're welcome to test and learn on it as much as you like.
00:46To find Microsoft SQL Server 2012 Express you can visit your favorite search engine,
00:52and search for something to the effect of SQL Server 2012 Express.
00:59We'll see several options there.
01:01I'm going to go head and click on the first one.
01:03We do get more than one option.
01:05I'll scroll down a little, and we'll see we get about a dozen options.
01:08Some of our choices are 32 bit or 64 bit.
01:12Obviously, you'll need to download whatever is compatible with your operating system.
01:16There are also a few different choices on what features are included.
01:21If we scroll down a little more, it shows us that detail.
01:26The one I'm interested in here is the last bullet point, Express with Advanced Services.
01:32The key point of Advanced Services is it gives us Full Text Search, and in some of the exercises,
01:38I do want to use the Full Text Search.
01:41So I'm going to go ahead, and download Express with Advanced Services.
01:45And on my machine, I am 64 bit, so I will get that one.
Collapse this transcript
Setting up the SQL Server 2012 Express edition environment
00:00So now let's look at installing SQL Server 2012 Express.
00:10So I have two choices here, one is a New Installation and one is an Upgrade.
00:14I'm going to choose New Installation.
00:20I will need to accept the terms of the license.
00:30So now the machine is asking me which features I would like to install and it already has
00:35several of them checked off.
00:37Most of these I agree with.
00:38The one I'm going to clear is Reporting Services.
00:41For this course we do not need Reporting Services.
00:44Reporting Services is a good tool.
00:46If you'd like to install it you're more than welcome to do so.
00:49It shouldn't cause any problems.
00:51I just choose not to at this time.
00:53At the bottom we see it's going to default to C:\Program Files\Microsoft SQL Server.
00:59I am perfectly fine with that.
01:01So I'm going to leave it with the default.
01:03You're welcome to change yours if you like. Click on Next.
01:08It's asking me for a name of the Instance and it suggested the name SQLExpress.
01:12I am going to change that slightly.
01:16Typically, my test machines end up with lots of different versions of SQL.
01:21So I will want to know that this one is 2012Adv, and I'll hit Next.
01:29It's asking me which Account I would like to use to run the different services and whether
01:33or not I would like them to store up automatically or manually.
01:36I'm going to accept all the defaults and just click Next.
01:40Here it's asking about security.
01:43Are we going to authenticate our user via Windows or via Mixed Mode? I typically go
01:48Mixed Mode, particularly in a test environment.
01:52Microsoft says that using just Windows authentication is more secure.
01:57So in production you might want to think about that, but in testing it's fairly common to have Mixed Mode.
02:03I'll need to have a password for the administrator.
02:10At the bottom it's asking me which Windows users I would like to be administrators.
02:15By default it has taken the current user and put in there.
02:18That's a good idea.
02:19You can add an additional user, if you like.
02:24No changes here and we wait.
02:32Great! Lots of green check marks there saying we have successfully installed Microsoft SQL
02:37Server 2012 Express Edition.
02:41Now that we have successfully installed SQL Server 2012 Express Edition we will need to
02:47set up a database that we will use for testing, and also import some information into that database.
02:53I am going to go ahead and open up SQL Server Management Studio and we will need to connect
03:02to the appropriate instance.
03:03I have staged some code for you already.
03:06It's in your exercise files and it's just a script to create a database called myDatabase.
03:12We'll copy that and paste it into a new query in Management Studio.
03:19I'll scroll up and point out one thing here.
03:22We created down an mdf file and an ldf file.
03:27I am putting both of those in the default folder. If you'd like to put them in a different
03:31folder, you are welcome to do so.
03:33Just be careful about the permissions on those particular folders.
03:37So let's Execute this.
03:39It says it completed successfully.
03:43We can go here now and see myDatabase. That is good.
03:47myDatabase will need at least one table for us to work with.
03:51So I am going to right-click, go to Task and go to Import Data.
04:00My Data Source is going to be a Flat File Source.
04:06It will ask me the name of the file and that is also in your exercise files.
04:15It is a CSV file called Students.
04:20That should be all I need to configure here.
04:21So I'll hit Next.
04:23It's asking me for my Row delimiter and my Column delimiter.
04:26I can accept the defaults for both of those.
04:30And we'll see in the Preview that we look like we're getting good data there.
04:34The values and fields like ID, LastName, FirstName, all of those fields make sense.
04:40So I'll hit Next.
04:42It's asking me for a Destination.
04:43The Destination will be the current instance of SQL Server, and it's asking me what database.
04:49It selected my database by default, and that is what I want.
04:52So I'll hit Next.
04:54It's asking me where I would like to put it.
04:55I would like to put in a new table.
04:57The machine figured that out for me and is suggesting it is going to call the new table
05:02(dbo).(Students).
05:04I'm perfectly okay with that.
05:05So I'll hit Next.
05:08On this last when I just hit Finish, and Finish one more time.
05:13Lots of green check marks indicates a high likelihood of success.
05:18I'll hit Close here.
05:21Expand the Tables tree.
05:23I see dbo.Students. That's good.
05:26Let me go ahead and right-click and select some rows from there, and yes, I get a whole
05:32bunch of rows and all of those look correct.
05:35So we have successfully installed SQL Server 2012 Express.
05:40We successfully set up a database we'll use for the exercises and then we imported one
05:45table of data.
05:46So I think we are ready to go.
05:48
Collapse this transcript
2. Database Engine Improvements
Using FileTables to enhance FileStream
00:00When you open up SQL Server Management Studio, one of the first changes you'll notice for
00:05SQL Server 2012 is the addition of a new type of table called a File Table.
00:11A File Table allows us to make a connection between a Windows Share and a Database Table,
00:21such that any file that appears in the Share will become a row item in the table.
00:27It allows us to run queries that tell us how many files we have in a Share, what type of
00:33files, what size the files are, et cetera.
00:37So setting this up is a multiple step process.
00:40The first thing we'll have to do at the instance level is enable file stream, and we'll do
00:46that with the Configuration Manager Tool.
00:50So under SQL Server 2012 > Configuration Tools > SQL Server Configuration Manager, I'll go
00:57to the instance I'm interested in, EXPRESS2012.
01:02Right-click on that, go to Properties, and there is a tab for FILESTREAM.
01:06In there, I'm going to click on all of the check boxes, enabling every feature.
01:12Then, back in Management Studio, there is a brief line of code we'll need to run.
01:19I have that code staged for you in your exercise files, paste that over.
01:24It is an sp_configure, changing the filestream_access_level to 2.
01:30So we'll run that.
01:32So that's all we have to do at the instance level.
01:33Now there are a few steps we need to accomplish at the database level.
01:40We'll need to provide a new file group.
01:42We'll need to enable non-transactional access, and we'll need to specify a directory for
01:47the File Tables, and then we'll need to create a File Table.
01:51We'll cut and paste this over to Management Studio.
01:55I'll scroll up to the top, and I'll walk you through this code.
01:59Lines 3, 4, and 5 here, alter the database to add a new file group, and then lines 9
02:06through 15, we'll add a file to that file group.
02:10I'm putting mine in C:\SQLData which is a directory you'll need to create. Scroll down a little more,
02:18and we see lines 22 and 23 will enable non-transactional access.
02:25So let's think about this for a minute.
02:27Typically, a database works entirely in transactions.
02:31Meaning that reading or writing of data; either 100% succeeds or 100% fails.
02:37But a file system often allows partial success.
02:42You can start reading a file, and even if the file isn't complete, the machine will
02:46still return the beginning of the file.
02:49It's more of a streaming mindset.
02:52So now that we're connecting a File Table to a Windows Share, we need to resolve those differences.
02:58The solution Microsoft came up with is to allow in some cases non-transactional access.
03:06So now we've created a database that in some cases may return a partial result set.
03:12The code to do that is right here at lines 22 and 23.
03:17Scroll down a little more, lines 31 and 32 will alter the database again, saying which
03:24directory we are interested in putting our files in.
03:28And finally, lines 40 through 45 will create a new table called DemoFileTable.
03:35We'll place the contents of that table into the directory myFileTable.
03:40So you want to make sure you're running this against the myDatabase, Database and we'll click Execute.
03:46It says completed successfully.
03:49Let's double-check that.
03:50I'll expand myDatabase.
03:51I'll expand Tables, I'll expand File Tables, and I'll have to hit Refresh.
03:59Now I see DemoFileTable which should be empty at this time.
04:07No results return that is correct.
04:10The contents of this table have been connected to a Share on my machine.
04:15So let's go ahead, and look at the Shares.
04:17I'm going to go to the Run, and type in the name of my machine.
04:24That will show me all of the Shares available.
04:26Notice one of them has the exact same name as my instance of SQL Server.
04:30Let's open that up.
04:32We have something called myFileTable which I just created, and then we see an empty folder.
04:38I'm going to right-click in here and create a new text document, and we can leave it blank for now.
04:45Come back over to Management Studio, I run this query again, and I now have one result returned.
04:52You'll see in the third column there, it says New Text Document.
04:56So I believe I have successfully connected this File Table to a Windows Share.
05:03So this new text document was a blank document.
05:05It has no contents, not really interesting.
05:08Let's look at a text file that does have some contents.
05:11I'll work with the 02_01_setup.
05:15I'm going to copy that file over into the Share, and I can come back to Management Studio,
05:21and I should see that new file there.
05:25I will now have to scroll to the right to see 02_01_setup.txt is there.
05:29So I scroll back to the left.
05:33We see for the file_stream, I get a whole bunch of numbers.
05:37That is because SQL Server is reading that data as binary data, and I would prefer for
05:44it to read it as characters.
05:47I can tell it to do that.
05:48I can write a query that does exactly that.
05:53So we'll have to do a Convert.
05:56And remember with Convert, the first thing you type in is what you would like the data to look like.
06:02I would like this to look like characters.
06:05I don't know exactly how many characters it's going to be.
06:07So I'm going to say max.
06:10The name of the field I'm interested in pulling is file_stream.
06:16I also want the name of the file.
06:19We'll run that, and now we see one column of the name of the file, that's great! And
06:23the other column has the contents of the file.
06:26The new text document is in fact blank. That is the accurate representation of the contents.
06:32And then, the second one is a lot more interesting.
06:35It actually has the code we use to create all this.
06:38That is the contents of the file that I copied over there.
06:41So you can start to think about some uses of this in your applications.
06:46If you're writing some sort of lightweight document management system, you now very quickly
06:52and easily can find the largest file, the smallest file, the most recently accessed file.
06:59Let's look at the columns we're given, and all of these were the default columns.
07:04When I created the table, I just said, I want this table to be a file table.
07:09I never specified which columns I wanted.
07:11Microsoft gave me all of these by default.
07:14A lot of them are very useful.
07:16File_type obviously could be quite useful, Creation_time, last_write_time, last_access_time
07:23all of those, it seems would very likely be in an order by clause.
07:29We could look for what is the order in which my files were created, or the order in which
07:35they were modified most recently.
07:38So certainly lots of possibilities if you are writing your own document management system.
07:43I also think about a lot of websites that I've worked on where the users are allowed
07:47to upload a file, and we keep that file in a directory.
07:52This would be a nice way to link that directory or files to a table, and have a little bit
07:58easier way to query it.
08:00I'm going to discourage you from writing a heavyweight document management system from
08:05scratch because those tools already exist.
08:07Microsoft has tools like SharePoint that will do your document management for you already.
08:13So recreating that from scratch doesn't make a whole lot of sense.
08:17This is a valuable tool in a situation where you couldn't run SharePoint.
08:21For example, maybe you wanted to embed it in a small application you're creating.
08:26This is a great tool.
08:27But it's probably not best to reinvent the wheel.
08:31Don't go back and recreate a heavyweight File Management System because those systems already exist.
08:38
Collapse this transcript
Exploring the new semantic search for unstructured data
00:00In this section, I'd like to talk about searching some unstructured data.
00:05In order to do this, we'll need to install an additional tool from Microsoft.
00:09This tool contains a semantic language database.
00:14So in order to find this, one of the easiest things to do is just search for Semantic Language
00:19Database, and here our first option will take us to the Download page. Two options on the
00:27Download page; one for the 64 bit version, and one for the 32 bit version.
00:33So choose whichever one is appropriate for your operating system.
00:39So here in my Downloads folder, I have the installer for Semantic Language Database.
00:43Just go ahead and double-click on that.
00:46I'll click on Next.
00:50Yes, I accept the terms of this license.
00:53Now it's asking me where I would like to install it? I almost always take the defaults, but
00:58this is one of the installers where I am going to change the default.
01:02It is defaulting to C:\Program Files\ Microsoft Semantic Language Database. That is a very
01:08descriptive name but unfortunately that folder does not have the proper permissions.
01:13I want to install this database into realistically any folder that has the proper permissions
01:19to run a database, and I know one of those folders exist already.
01:23It's the folder where Microsoft is storing all its other databases.
01:28So from the top, that is, C: > Program Files > Microsoft SQL Server, and then the one that
01:35has the name of the instance I am working with, and then there is only one folder in
01:40there, so the choice is obvious, and then DATA.
01:44So that's the directory Microsoft typically stores its databases in.
01:49Therefore, the permissions should already be set there.
01:52Hit Next, hit Install, and that should be it.
01:56Okay, it looks like we are complete, so I will hit Finish.
02:01By running this MSI package, we successfully copied over the files that will eventually
02:06become the database.
02:07Now we need to go into Management Studio and attach that database.
02:12So here in Management Studio, I'll right-click on Databases and go to Attach, and then I will hit Add.
02:20And now I will need to browse to the location.
02:23Actually the location came up by default as the default data location for this instance.
02:28We have the new one called semanticsDB, hit OK here, and hit OK here.
02:36And now over here in Databases, I have a new database called semanticsDB.
02:40If you don't see that right away, you might need to right-click and hit Refresh.
02:46Mine came up there, and now just more step, we need to register this as a semanticsDB.
02:54That will be two lines of code.
02:56I've staged those for you already in your Exercise folder.
03:00Copy and paste that over into Management Studio.
03:04Let's look at what it says.
03:05We are going to execute a store procedure called fulltext_semantic_register_language_statistics.
03:14That store procedure takes one parameter, that parameter is the name of the database.
03:17I am going to use the database I just created a second ago called semanticsDB.
03:23Hit Execute and it said Command(s) completed successfully.
03:27So now we will need some test data to work with.
03:30This demonstration is working with what Microsoft calls unstructured data.
03:35In other words data that is not in a typical database table.
03:38We are instead storing our data in documents which obviously happens an awful lot in the real world.
03:44I have a few text documents in your exercise files called Memo1, Memo2, and Memo3.
03:52We'll look at these real quickly.
03:54Memo1 is a fictitious memo, introducing the arrival of a new faculty member to our university.
04:03Memo2 and Memo3 are similar, using slightly different phrasing.
04:10Memo1 and Memo2 are about the same length.
04:14Memo3 is about twice as long, just has more detail basically on the same topic.
04:20Let's copy all three of those files into the File Table we created in the previous exercise
04:29which is also part of a share on our machine.
04:36We had dropped two files in there previously.
04:39We'll add Memo1, Memo2, and Memo3.
04:43We'll also need to create a Full Text Index on those files, and I've stated some code
04:50for you to do that.
04:51Copy and paste this code into Management Studio.
04:56We'll look at it briefly.
04:58Line 4 creates a full text catalog, then line 7 through 15, creates a full text index on that catalog.
05:05This is very similar to which you would have done in previous versions of SQL Server.
05:10There is a new statement on line 12, STATISTICAL_SEMANTICS.
05:15That is the new feature in SQL Server 2012 that I'm going to demonstrate here in just a second.
05:23That last line, line 14 where it says KEY INDEX (PK_DemoFile_ and a number.
05:31That number may be different on your machine.
05:34That's a primary key that was created automatically when we created our File Table.
05:40So if you want to navigate to your File Table, you can find out exactly what your key is called.
05:46Under Keys, you will see one that says PK_ DemoFile, and has some number after it.
05:54You want to make sure that is the one you are using.
05:58We'll hit Execute, and Command(s) completed successfully.
06:02So that means we have created a Full Text Index with statistics on the semantics.
06:09That means we can run some new types of queries new in SQL Server 2012.
06:15I have staged some of this code for you in your exercise files.
06:18I am going to work with just the top query first.
06:22Copy and paste that over.
06:24Lines 1 through 7 or creating a variable called Document ID, and storing the ID of Memo 01
06:33in that variable, and then so most of our exciting stuff happens in line 11, 12, and 13.
06:41We see the table SEMANTICKEYPHRASETABLE.
06:44That's actually a table valued function; a function that takes three parameters and returns a table.
06:50The first parameter is the name of the table we will be querying, the next is the column
06:55we are interested in using as the primary key, and then the last one where we are passing
07:00DocID, that is the value of the document we are interested in.
07:05We'll execute that, and I will scroll up, so that we can see the key phrases it returned.
07:12It found the most interesting key phrase as Janelle, second as Roper, third as Faculty,
07:18and Fourth as professor.
07:20So Microsoft has used the semantic database we created in earlier in this exercise, went
07:27in and analyzed that memo and found what it perceives to be the most important words.
07:31So words like 'and', 'or', 'the' are automatically considered to not be very important.
07:38Words that are unusual, words that appear often, words that are the very first word
07:42in a sentence or come up early in a paragraph, those words are considered to be more important.
07:49So Microsoft's opinion, this is a memo about Janelle, Roper, Faculty, Professor, and that's
07:55actually pretty close to correct.
07:57Those are the key points of that memo.
08:00So this is a very interesting new feature.
08:03I have one more query I want to run that's also staged.
08:08So I'll copy and paste that from the exercise files to Management Studio.
08:13The top lines 1 through 7 is pretty similar to the example we just looked at, it's just
08:18finding the DocID of Memo1.txt.
08:21The query 9 through 14 is a little more complex.
08:26The heart of it is line 11 where it's referencing SEMANTICSIMILARITYTABLE.
08:32As the name implies, this is going to find files that are semantically similar to Memo1.txt.
08:40So if we go ahead and run this, and look at the results, we see that the machine feels
08:48Memo2 is 93% similar, Memo3 is 67% similar, and the 02_01_setup file is only 1% similar.
09:02I would have to agree with these numbers.
09:03Memo2 is very similar to Memo1, Memo3 has some of the same information, but it's about
09:09twice as long, so only about half of the information is similar, and then the 02_01_setup file
09:16has basically no similarities to Memo1.
09:19So I would agree with these results.
09:22I've done these demos with text files.
09:24If you would like to use different type of files, that is possible.
09:28SQL Server utilizes what's called an IFilter, and an IFilter will extract the text from
09:34files like Word documents, Excel, PDFs, et cetera. Pretty easy to find IFilter files
09:42with a web search.
09:46If we search for something like IFilter office, we should be taken to the Microsoft Download
09:51page for the IFilters for the various office documents, and that will work not only with
09:59SQL Server, but also other Microsoft products.
10:02So a pretty useful tool!
Collapse this transcript
Exploring enhancements to full text search
00:00In this section I would like to talk about a small enhancement to searching data that
00:05is in a full text index.
00:07It's a pretty small change from 2008, but I think a very nice feature. It gives the
00:12developer a little more control.
00:15I'll be using the full text index we created in the previous movie.
00:19Now that full text index is on a file table. That is not necessary for this to work. What
00:24I'm going to demonstrate would work on any full text index whether it's connected to
00:29a file table or not.
00:31I have staged a little code for you in your exercise files. I'll copy and paste that over
00:36into management studio.
00:38And what I have on the screen right now is actually something that would work in 2008.
00:44We are going to search for information that contains the word proud and the word Janelle
00:51and they have to be near one another.
00:54So I'll execute that.
00:56And we see both Memo3 and Memo2 have the word proud near the word Janelle.
01:02In SQL 2008 this is about as far as I could take it. I didn't have any more options.
01:06In 2012 they've given me the option to say how far or how close we would like these words to be.
01:15So rather than near being some abstract concept we can actually put a hard number on it.
01:21I can say I want the proud to be within 12 words of the word Janelle.
01:29And we run that again and we get the same results.
01:34But now if you start to think about if we're looking for a situation where someone is saying
01:37that proud of Janelle and those two words are 12 words apart they could actually be
01:42saying they're proud of something else.
01:44So I want them to be much closer. Let's demonstrate that where they are only four words apart.
01:52And now we only get one file, we just get Memo2.txt where those two words are within
01:58four words of one another.
02:00So again, this is a pretty small change over 2008, but I do like it. I always like any change
02:06that gives the developer more control.
02:08So now rather than just saying the near I have the option to say exactly how many words
02:14apart these things should be.
Collapse this transcript
Implementing ad-hoc paging with offset and fetch
00:00In this section, I would like to talk about creating a query that returns data that is
00:05ordered that will likely be displayed to the user in small chunks.
00:10So we'll display the first 10 records within the next 10 records, within the next 10 records
00:15et cetera, et cetera.
00:18This is commonly done in many applications and can sometimes require writing some complex
00:23code in the application.
00:25New in SQL Server 2012 we have some additional tools where we can fairly simply modify a
00:32database query that it will handle just giving back part of the results commonly known as paging.
00:40So we now have some built-in paging tools.
00:43I'll start of with a new query. We'll get to work with the students table, so let's select a
00:49few fields from that student table, and let's return them in an ordered format. We'll order
00:56by ID and there we see it returned 25,000 rows.
01:02Obviously on an end-user application you're not going to display 25,000 rows at one time.
01:08You're going to cut that down. Let's look at an example where we want to only get back
01:13five records at a time. We'll add to the order by clause, we'll add the phrase offset and
01:19we'll say offset by five rows.
01:24So now instead of starting on the very first record, it skipped the first five records and
01:30gave me what was number six. So this would be the information for the second page of
01:36data, and then we could say offset 10 rows to give me the information that was stored
01:43on the third page of data.
01:46One problem though now is it still returning way more records that I want. I said I only
01:51want to display five at a time, and it's displaying everything beyond those first 10 rows, so
01:5824,990 rows. I really don't need that many.
02:03I can change that by telling it to only fetch a certain number of rows.
02:08So fetch is the other part of the new order by clause, so I can say fetch next 5 rows only.
02:21We'll run that and it only returns five rows.
02:24So this is starting on record number 11, because I set offset 10 rows and then it's going through
02:30the next 5, and then the next query you would say offset it by 15 and again only return
02:375. We don't need to change that and that gives me the next group of 5.
02:42So by using the new offset and fetch feature new in SQL Server 2012 we can implement paging
02:50on the database side rather than having to do all of our paging in the application.
02:57
Collapse this transcript
Using the new throw statement to enhance try-catch blocks
00:00In this section, I'd like to talk about a new way to handle errors in SQL Server 2012.
00:07First of all let's look at some of the ways it's currently handled.
00:10I have some code in your exercise files, and I intend for this to be something fairly similar
00:16to what most developers do for handling errors.
00:19Lines 2 and 3 are inside of a TRY statement, and I intentionally have created an error
00:25there. I'm going to attempt to divide by zero.
00:28Lines 7 through 15 are located inside of a CATCH block. They should handle that error
00:36and return a message to the user.
00:38We'll execute this and we see it does in fact work.
00:42This RAISEERROR technique has a few issues and therefore Microsoft has implemented a
00:47new way of doing this.
00:49It's not dramatically different.
00:51Let's talk about some of the problems here first.
00:54One is the unusual spelling of RAISEERROR.
00:57If this is actually two words then I would think you would be spelled raise with an E
01:03and then another E to start error. And if you combine those two words, in some places
01:09that does work, but in most places it doesn't.
01:12In most places you have to use just one E in the middle of that word.
01:16So there's always been some confusion amongst developers about do we say RAISEERROR with
01:22one E in the middle or with the two Es in the middle.
01:25Some places you have to use one, some places you have to use a different one.
01:29All of that is somewhat cumbersome.
01:31We also have the issue when we raise errors, sometimes it stops the control of flow, sometimes it does not.
01:39So instead of doing a divide by zero up here in the TRY block I'll change that to a RAISEERROR statement also.
01:48And the first parameter we passed is the message, and the next parameter is the severity.
01:54So I'm going to start off with severity 12 and then the state in this case doesn't matter.
02:01So we run this and it executes as we would think.
02:06At the bottom we get the red message indicating that it was an error, a level 12 error.
02:13But if we change the level down to 10 and we run this again, you notice now what comes
02:18up at the bottom is black.
02:21Because a level 10 error doesn't stop the flow. So this continued on and it wasn't recognized as an error.
02:28Being I use the phrase RAISEERROR and the machine chose to interpret that as not an error,
02:35it's been a little confusing to me.
02:37Let's talk about the new way of doing this.
02:40Microsoft has eliminated the word RAISEERROR and they've changed it to THROW.
02:50And I'll put this back like we had it a minute ago where we were doing the divide by zero problem.
02:57We'll execute that and we see that just by using the word THROW in the CATCH block it
03:04returns the message divide by zero error encountered.
03:08So that's simpler than the RAISEERROR technique, it also may be more intuitive for many developers,
03:14particularly if you've written a lot of C# or Java code.
03:18This is exactly how it works.
03:21The THROW has the advantage of always stopping the control of flow whereas the RAISEERROR
03:27would sometimes stop the control of flow, sometimes it wouldn't, depending on the severity.
03:34So some reasons to stop using RAISEERROR and start using THROW.
03:39Number one, the spelling of RAISEERROR is odd, the RAISEERROR has been deprecated, and
03:46in Microsoft terms deprecated means it will eventually be taken out.
03:51It still works perfectly fine in SQL Server 2012 but eventually they are going to remove
03:57the syntax of RAISEERROR.
04:00The THROW is more similar to other programming languages.
04:04The THROW is simpler and the THROW will always stop the control of flow and jump you to the CATCH block.
04:10It's not a big change. All-in-all your error- handling mindset and philosophy doesn't have to change
04:16dramatically. It's more of a small syntactic change, but I encourage you to start using
04:21THROW and stop using RAISEERROR.
Collapse this transcript
3. Improvements to SQL Server Management Studio Debugging
Using breakpoint condition, breakpoint hit count, breakpoint filter, and breakpoint action
00:00SQL Server 2012 introduces powerful new debugging features associated with breakpoints.
00:07Let's look at some code I have staged for you.
00:09This code contains a variety of T-SQL statements, some loops, some conditionals, and some queries.
00:15I'm not trying to demonstrate any particular feature of T-SQL.
00:18I just wanted to create some code that would provide lots of debugging opportunities.
00:23So don't get too caught up on what this code is accomplishing.
00:27So anywhere in the code out to the left I can click and create a breakpoint signified
00:32by that little red circle.
00:34Nothing new, same as SQL Server 2008.
00:37But when we right-click on the breakpoint we see some new options.
00:42The top two options there Delete and Disable have always been there and are fairly self-explanatory,
00:46but everything under that is new.
00:50So let's talk about these one at a time. Location.
00:53I'll go ahead and select Location and it saying this breakpoint starts on Line 7, Character 1.
01:00Every breakpoint defaults to starting at Character 1, but you can change that if you would like it.
01:06So I want to move this so we can see behind.
01:08Currently, it has the red highlight around the phrase SET @x = 1.
01:13So that is where it's going to break.
01:15I can change what character it starts at to make that actually break when one of the other phrases.
01:21So let's change that to 15.
01:24Now it moves over and now it's going to break on SET @y = 7.
01:29So I have successfully changed the location of that breakpoint.
01:33It's still on the same line, but it's at a different character.
01:36So I'm going to create another breakpoint down here.
01:40Right-click on that and we'll talk about Condition.
01:42A Condition allows us to write a statement that evaluates to either true or false.
01:48If the statement evaluates to true, the breakpoint will cause the break to happen.
01:52If the statement evaluates to false, the breakpoint will be skipped entirely.
01:57We commonly look at the value of different variables in these conditions.
02:00So we can do something like, if y<1.
02:05So in other words if y is 0 or a negative number, I might think this logic is going
02:11to function differently.
02:12Therefore, I only want to break under that condition. I hit OK.
02:17And you'll notice at that breakpoint the icon changed just a little.
02:20There is now a white plus mark in the middle signifying this is a conditional breakpoint.
02:26Now I'll create another breakpoint here, right-click on it, and will go to Hit Count.
02:32This is probably my personal favorite of the new options.
02:35We can set a breakpoint to only function when it has already been reached a certain number
02:39of times or set it to stop functioning after it has been reached too many times.
02:45This is very useful if we are concerned about loops that run too many times.
02:49I sometimes set one of these breakpoints in every loop and give it a very high value.
02:54So basically I'm telling the machine I only want a break if we've hit this point 1000 times.
03:01Because if we've hit this point 1000 times, something is wrong with my code and I need
03:06to know about it.
03:07So if this loop executes more than 1000 times, we will break.
03:12Set another breakpoint and our next option is Filter.
03:16Filter allows us to set up conditions.
03:18The example Microsoft uses is to only break if machine name is equal to a certain value
03:24or process name is equal to a certain value.
03:28So this would be likely we want to set up breakpoints that will break in development,
03:32but not break in production.
03:34So you would set the machine name to your development machine and allow it to break
03:39only on development.
03:43Next option is When Hit.
03:46So the default action of a breakpoint is that when it's hit, it stops the execution and
03:50allows you to look at the values.
03:53But we could have it do something else.
03:55We could have it print a message to you in the output window.
03:59We can say continue execution or don't continue execution.
04:03We can change the behavior of the breakpoint by using the Is Hit option.
04:11Next is Edit Labels.
04:13So we can give labels to our breakpoints and then we can later search for those.
04:19So I created a label called ABC.
04:21I could later search for all the breakpoints that have the label ABC and either enable
04:27those, disable those, or delete those as a group.
04:31So this doesn't change the functionality of the breakpoint at all.
04:34It is just an administrative tool.
04:37If you want to perform the same action on a large number of breakpoints, you give them
04:42all the same label, and then you can perform that action on those as a group.
04:47The last option is Export.
04:50We can export all of our breakpoints to an XML file and then later import them.
04:56The logical place you would do this is while you're in development, you might have all
05:00of your breakpoints set up.
05:02You then would remove the breakpoints before you move into production.
05:06But rather than having to re-create those breakpoints later, if you exported them first,
05:11you can then import them rather than having lost all that work.
05:16So again, lots of new options on breakpoints and I'm excited to see these new features
05:20in SQL Server 2012.
Collapse this transcript
Exploring the Watch, Quick Watch, and Quick Info windows
00:00Now I would like to talk about a few of the changes made to some of the windows while we're debugging.
00:06So again I have some sample code staged for you in your exercise files. It's actually
00:10the exact same code we used in the previous movie. Copy and paste that over to Management
00:16Studio, and I'll go ahead and set a breakpoint at a random point and I'll press Debug.
00:24Now here in my debugging interface lots of windows have popped up. Your windows may look
00:30a little different. Remember you can open and close many of these off the Debug menu
00:35here at the top, we have the option to turn on or turn off various windows.
00:41First of all at the bottom I have the locals window. Now once I've press Play and hit my
00:46breakpoint, it shows me the value of the local variables: X equal 1, Y equal 7 and Z equals 0.
00:56Reading that information has not changed, but in SQL Server 2008 this was a Read Only
01:01window. In SQL Server 2012 you can change values in this window. So what the value of Y is
01:08currently 7, I'm going to change that to a random number and that change will be reflected
01:15in the code above. We'll see we are currently paused on a line that is going to subtract
01:21one from the value of Y.
01:23So I'm going to press F11 on my keyboard to cause that to advance through that line.
01:30And we see it change the value of Y to 98, so it took my new value and continued on with the code there.
01:38We also have in SQL Server 2012 a new type of window called the Quick Info window.
01:45We get to this just by hovering the mouse over a particular variable. You don't have
01:50to click on it, just hover the mouse over and we see here that Y currently has a value of 98.
01:57I'll go ahead and click on the push pin there, and now that Quick Info window is anchored
02:03and I can press F11 a few times to continue cycling through the code, and we'll see the
02:09value of Y change there. The value of Y is changing and again this is a Read/Write window,
02:16so I can change the value of Y if I so choose to.
02:20I'll press F11 a few more times and we see it continuing to work. So that's a new feature
02:26of SQL Server 2012.
02:28Another new feature is while we're in Debug mode, while it is broken, we can add comments.
02:36So I can comment here and type some comment.
02:41And that comment will stay not only in Debug mode, but also when I get out of Debug mode
02:47that should still be there.
02:52And there we go my comment has stayed.
02:54So if you want to either make temporary notes to yourself or write permanent comments that
02:58will live on with your code forever, you can do that either in this view or in Debug mode.
03:04That's a nice new feature of SQL Server 2012.
03:08
Collapse this transcript
Reviewing Transact-SQL IntelliSense improvements
00:00SQL Server 2012 has added some new features to IntelliSense, specifically support for code
00:08snippets. So I have some code staged for you for this one. It's very similar to the code
00:13we used in the previous movie. I'll copy and paste all of that into Management Studio.
00:20So I can move my cursor anywhere in this code and right-click, and we'll see the option to
00:27insert snippet, which will give me a menu of various things I can insert, so let's do
00:34Index and then Create a Basic Index.
00:38So code gets inserted, it has the basic template for creating an index.
00:44Some of the things here I'll need to add myself such as what table I would like to use, what
00:50column I would like to use and the name of the index.
00:54But it's got me started and that is the point of these snippets, to be small sections of
00:59reusable code that we can get some mileage out of; write it once and then reuse it several times.
01:07Typically they're not going to give us complete functionality on their own they're going to
01:12be sort of a fill in the blanks mindset of there's a few more pieces of information we
01:17need to get to really finish it up and drive it home.
01:20I'm going to right-click again and look at Insert Snippet, and talk about a few of these
01:25things, things like creating logins and creating rolls I find are very useful, because those
01:31are things that I don't do real often and therefore having the prompting of a snippet helps me a lot.
01:38I am going to scroll down here and highlight the bottom of my code the last three lines, right-click.
01:45And notice right under Insert Snippet there is Surround With, and this is sort of a special
01:53type of snippet, it's going to insert some code right above where I'm highlighted and
01:59other code right below where I have highlighted.
02:02So basically it will surround the code I have highlighted.
02:04It can surround things with things like an if statement so now rather than my code always
02:11running I have surrounded it with an if statement, and I can create a conditional, and now that
02:18code will only run under certain conditions. So the Surround With snippets are also very useful.
02:28SQL Server 2012 comes with a fairly complete set of snippets, but if you would like to
02:33create your own you can.
02:36If we go to the Tools menu the very top option is Code Snippets Manager which allows us to
02:43remove existing snippets, create new snippets, or change what folders these snippets are in.
02:51Creating your own snippet is not as easy as you might want it to be. I have some source
02:57code for one in your exercise files. It's called TryCatch.snippet. I'll right-click
03:05on that and edit it in a text editor and we'll see it is a combination of XML and SQL.
03:13So the SQL here around lines 28 through 38, this is the SQL that I would like to be part
03:20of the snippets. All of the XML surrounding it describes the type of snippet, what directory
03:26it would be in, what situations it could be used in.
03:30So the syntax here is a little tricky because you're writing XML and SQL at the same time.
03:37Realistically, I've never had to write a snippet from scratch. If there's a particular snippet
03:42I'm looking for, I typically go to my favorite web browser and search for something descriptive
03:48about the snippet I'm looking for, and I've always been able to find someone who's already
03:53created this snippet and is willing to let me copy and paste it over.
03:58And so it is somewhat rare that you have to create these from scratch.
04:05As you become familiar with the new snippet functionality, hopefully it will decrease
04:11the amount of time it takes you to code, and increase the consistency with which you can
04:17write good code.
Collapse this transcript
4. Changes to the Scope of Objects
Understanding changes to user passwords and logins
00:00In SQL Server 2005 and 2008 if we want to give a user access to one of our databases,
00:09we first have to create a login at the server level and then create a user at the database level.
00:16So just for the sake of discussion I'll go ahead and do this.
00:19I'm going to open up Security, right- click on Logins, and create a New Login.
00:26I want a SQL Server Login and we will call him TestLogin.
00:35Give it whatever password you see fit and hit OK.
00:40Now that we have a login called TestLogin, I can go into any of my databases under the
00:48Security section, open up Users.
00:52I can right-click and create a New User.
00:55I have to say which login name I want this to connect to, and I've just created one called
01:02TestLogin, and I'll call this guy TestUser.
01:09So now I have TestUser contained in myDatabase and I have TestLogin contained at the Server
01:16level, and those two have a relationship.
01:19One of the problems with this setup is that if I ever move the database, myDatabase,
01:25if I ever move that to a different server, well, TestLogin isn't going to be on that
01:30new server and therefore we have a problem.
01:33TestUser would become disconnected from his login and would probably stop functioning.
01:40So this is a big problem for developers when you work on a development machine that has
01:44one set of logins and then you copy your database to a production machine that has a different
01:50set of logins, a lot of times things break.
01:53It can be difficult to troubleshoot and we usually end up having to write a bunch of
01:57code to sync up the logins.
02:00Microsoft has apparently thought of this and come up with a new feature in SQL Server 2012.
02:07We can now store all of the information in the database.
02:11So we don't have to have a login at the server level anymore.
02:17Everything happens at the database.
02:19This is a special type of Database called a Contained Database or called a Partially
02:25Contained Database.
02:26And I have some code staged that will set one up for us.
02:30So in your exercise files I'll copy it over into Management Studio and we'll walk through this.
02:39I'll scroll back up to the top.
02:41Lines 1 through 4 are going to just turn on the fact that we would like to use partially
02:47contained databases.
02:48We'll have to use the sp_configure for that.
02:51Line 7 creates a new database that I'm going to call PartContDB for partial containment,
02:59and the only parameter I'm passing to it is CONTAINMENT=PARTIAL.
03:03That's the only option I'm setting.
03:04Then line 16 and 17 will create one table in that database.
03:10Scrolling down line 25 and 26 will create a new user called user1 and give him a password.
03:18Then line 28 and 29 are going to add that user to a particular role.
03:24Go ahead and Execute all of that.
03:26It looks like that was successful.
03:28We can look for our new database by hitting refresh, and there is my PortContDB, and in
03:36there I should have a user.
03:38A User called user1 and that user is not contained to any login at the server level.
03:44We can right-click and look at his properties and see his password is stored with the database.
03:51It's not stored at the server level.
03:54So user1 should be able to login.
03:57We can Connect Object Explorer.
03:59We will have to change to SQL Server Authentication.
04:02The login will be user1, and if I try to just do it like this, login into the server should fail.
04:12So that is correct.
04:15But if I hit Options here and say I particularly want to only connect to one database.
04:20I want to connect to PortContDB, then I can in fact connect, and we see down here he is
04:30connected to one database, the PortContDB.
04:35So although user1 does not have the ability to log into the server, he does have the ability
04:41to connect to this one database, because his password is contained in that database.
04:47Meaning, if we copy this database to any other server, he should still be able to login.
04:53We don't need to create him a login on that server, all of his information is stored in the database.
04:59So this is a great feature.
05:00Very convenient for anyone who moves databases often, and just depending on your working environment
05:06you may move databases often going from development to production, or going from development to
05:12testing and then testing to production.
05:15Now do be aware of the different security like I said we're storing the password in the database.
05:21That's a new mindset.
05:22So you now have some confidential information in your database.
05:26You need to be careful to protect that and just be aware that now passwords can be stored
05:32in the database.
05:33That's information you're responsible to protect.
Collapse this transcript
Creating user-defined server roles
00:00Microsoft SQL Server has long had the concept of server roles.
00:05So under Security, we can see the available server roles hasn't changed much in a few generations.
00:13We have things like the securityadmin, serveradmin, dbcreator, et cetera, et cetera.
00:20Now in SQL Server 2012 for the first time, we can create our own custom server roles.
00:26They do not yet have a graphical interface for this.
00:29So if you right-click, you don't see any options that say Create New Server Role.
00:35We have to do all this in code.
00:37So I have staged some code for you in your exercise files.
00:41Copy and paste all of that over into Management Studio.
00:46The hypothetical I'm going through here is that I want to create a new server role called ReadOnly_Admin.
00:53This is because maybe I am troubleshooting something with an outside vendor or some other admins.
00:59And in order to troubleshoot properly, they need to be able to look at a lot of things on my server.
01:04But I don't want them changing anything on my server.
01:07So I'm giving them a series of permissions that are basically Read Only.
01:11I'm calling that sever role ReadOnly_Admin.
01:16So I will execute this, come over here to Server Roles, hit Refresh, and we now see
01:22the ReadOnly_Admin.
01:24So now, I can go to the logins, and on any of the logins, I can add them to that server role.
01:31So I look at Properties > Server Roles, and my custom one ReadOnly_Admin is now available in that list.
01:41So this is a fairly simple tool Microsoft has added that has a potential to significantly
01:46reduce administrative effort.
01:48There aren't any new permissions here.
01:50It's not like I can grant or deny access to anything that I couldn't previously.
01:56But it does mean by creating a custom server role that I could possibly reduce the administrative effort.
02:04If I have 5 or 10 people that all need the exact same access, rather than having to set
02:09them up all individually, I could create a new role, put all of them in that role, and
02:15administer them as a group which is going to be less effort in the long run.
Collapse this transcript
Understanding auditing
00:00In this section I'd like to talk about some of the changes to auditing in SQL Server 2012.
00:06I have a little sample code for you. I'll copy and paste over just the top part for
00:12now, paste that into Management Studio.
00:16We have some new options on the ON_FAILURE area here.
00:21The default is still ON_FAILURE to continue.
00:24So in other words if for some reason the machine is not able to audit the particular action,
00:30the machine will continue running, the SQL Server will continue operating as normal,
00:35just nothing will be audited.
00:37In previous versions of SQL Server, once it failed to audit once it would stop trying.
00:43That has changed in 2012.
00:46Even if it fails once, when it's time to audit again it will try again, and if it fails then
00:51it will try again, over and over.
00:53If it ever becomes successful again the auditing will pick up from there.
00:57We also have the option ON_FAILURE to shut down the server. That hasn't changed since
01:03previous versions. That's obviously a very aggressive way to go, but it is the most secure.
01:08It means that if for whatever reason we are unable to audit something, the entire SQL Server
01:14will be shutdown. We'll have no more functionality.
01:17The third option is new in 2012, it is called FAIL_OPERATION.
01:23What this does is the particular operation that user was trying to do, that should have
01:28been logged but can't be logged, that operation will fail.
01:33But any other action, any action that does not cause an ordered event to occur will continue to run normally.
01:40So for example, if you have a database set up to audit all changes but not audit any
01:46read-only access.
01:49If auditing would fail for some reason, all of the write operations would fail, but all
01:54of the read operations would continue to run normally.
01:57This is a nice new option, and I think I will be considering it for many of my production databases.
02:03The other new feature I want to talk about is a new stored procedure, and this is probably
02:08more interesting to developers.
02:10I have some code here, I'll copy and paste over into Management Studio.
02:14It's a new stored procedure, called sp_audit_write, and as the name implies it is going to write
02:21something to the audit log.
02:23So in previous versions of SQL Server we didn't have this fine level of control.
02:28We would set up an audit specification that will talk about large groups of things we
02:33wanted to audit, and if you try hard enough you can get fairly gray, you look to specific
02:37events to audit them or not audit them.
02:40But we never had the ability to just say, hey, here's a phrase, I want to write to the
02:44audit log immediately, and now we do have that.
02:47Fairly simple to operate, sp_audit_write. It takes three parameters and event_id something about success.
02:56Typically you're going to do a 1 or 0 here saying the operation was successful or not
03:01successful, and then the last parameter user_defined_ information which is text, and you can write anything you want.
03:08So let's talk about a few likely scenarios where you might use this.
03:13If you have an error handling module that writes all of your errors to an error log,
03:19you could add this stored procedure to that module and that would write all of your errors
03:23to the audit log. That could be in addition to writing them to the error log or instead
03:29of writing them to the error log.
03:30I think it would also be a good idea to write things to the error log about major changes,
03:35such as we installed a new service pack or we made a change to the schema.
03:40It would also make sense to say we implemented a new security policy at this time.
03:45So for example, if your company suddenly changes the rules about who can and cannot access
03:51certain pieces of data, and you've been auditing who is and is not accessing those pieces of
03:57data, you might also want to make a note in the audit log that hey, at this point in time
04:02the rules changed, so anything before this point you need to evaluate that against the
04:07old set of rules, and anything after this point you need to evaluate against the new set of rules.
04:14All in all sp_audit_write makes auditing more powerful, more flexible, gives the developer
04:22more control, and I always like things that give developers more control.
Collapse this transcript
5. High Availability from the Developer's Point of View
Exploring AlwaysOn
00:00SQL Server 2012 introduces a new high availability feature called AlwaysOn.
00:07This course is focused on development, not administration.
00:09So I am not going to get too deep into the nuts and bolts of setting up or maintaining
00:14AlwaysOn, instead I want to focus on you, the developer, and what you need to do to
00:20make your applications work seamlessly with databases configured with AlwaysOn.
00:25First, let's talk a little background about AlwaysOn, and get a little terminology under our belts.
00:31As with most high availability techniques, an AlwaysOn database runs most of the time
00:37on a main server, and that's going to be called the primary replica.
00:42If anything goes wrong with that server, the database is automatically copied to another
00:47server, and that's called a secondary replica.
00:51AlwaysOn actually supports up to four secondary replicas.
00:55Now with previous high availability techniques, when a database would move, it would move
01:00one at a time independent of any other database.
01:04This could be a problem because many applications use more than one database.
01:08So you had a problem if an application uses two databases, one of them fails over, and
01:14one of them doesn't.
01:15So now you would be accessing data in two locations; could be a problem.
01:20AlwaysOn solves this problem by creating what it calls Availability Groups.
01:25An Availability Group contains multiple databases all of which will fail over together.
01:31So if this is used properly, you can guarantee that all the databases you need to access
01:36from a particular application are up and running on the same replica.
01:40So you want to be prepared to work with your administrator to identify which databases
01:45should be in the same Availability Group.
01:48This could also possibly change some database design.
01:52In the past, some developers have forced a lot of data into the same database, even though
01:58that data wasn't necessarily related, they just were concerned when the failover happened,
02:04they wanted everything to move at one time.
02:06So we ended up with things in the same database that really should have been split out amongst two databases.
02:13Now that we have the Availability Groups, you can go ahead and split your large database
02:18into two, or three, or four more logically contained databases, place them all in the
02:23same Availability Group, and we can be assured that the failover will happen together.
02:29When connecting to a database configured with AlwaysOn, you may need to tweak a few things
02:34in a typical connection string.
02:36Here is an example of a valid AlwaysOn connection string.
02:40Notice that we always use a TCP/IP connection.
02:44Named Pipes are not allowed with AlwaysOn.
02:47You also notice that you have to use a DNS name.
02:50Using an IP address is not allowed because the primary replica and secondary replicas
02:56will all have different IP addresses.
02:59And this connection string may be potentially connecting to the primary, at other times
03:04it may be connecting to the secondary.
03:06So we can't put the IP address in there, we have to put the DNS name instead.
03:11Other than that, pretty much the same as any other connection string.
03:15This connection string will automatically connect first to the primary replica.
03:20If the primary fails, it will automatically redirect you to one of the secondary replicas.
03:26So as a developer, you do not need to write any code to handle the redirect. That will
03:30be handled behind-the-scenes for you.
03:32However, there could be up to a 60 second pause where neither the primary, nor the secondaries are available.
03:39So your code should have some mechanism that after a failed connection, it pauses and tries
03:45again, and pauses and tries again for up to 61 seconds.
03:50Realistically, I would recommend that you have that even if you aren't using this high
03:54availability technique. We always want to write code that's robust and can handle a short disconnect.
04:01When AlwaysOn is set up, the primary replica is a Read/Write copy of the data, fully functional,
04:07you can both read and write.
04:09All the secondary replicas are Read Only copies.
04:13So if you have an application that needs Read Only access to the data like a reporting application,
04:20you can use a special connection string.
04:21I am going to have one of these on the screen for you.
04:25It's basically a typical connection string, and at the end, we added the phrase ApplicationIntent=ReadOnly.
04:33By telling the machine you want Read Only access, you can open up the possibility to
04:38being connected to a secondary replica.
04:41This will move some of the workload off of the primary replica.
04:45So although, AlwaysOn is primarily a high availability technique, using this modified
04:51connection string, we can also make it into a load distribution technique where only your
04:57Read/Write operations need connect to the primary and any Read Only application can connect
05:04to the secondaries.
Collapse this transcript
Examining changes to replication
00:00In the previous movie, we talked briefly about the new AlwaysOn technology and how you could
00:06use a connection string to connect an application to an AlwaysOn replica.
00:12In this section, I want to talk about using AlwaysOn with replication.
00:17As I'm sure you know, replication doesn't use connection strings to connect to machines.
00:22So we'll have to use a slightly different technique to connect to an AlwaysOn group.
00:26I've outlined a four step process here for you.
00:30The first thing you want to do is configure the database publication and subscriptions
00:34on your primary replica.
00:36So not too surprising; you go to the Primary Replica, and you configure replication just
00:41like you normally would on any other machine.
00:43Then you need to go to all of the secondary replicas and make sure replication is turned on.
00:49You don't have to actually configure a publication nor a subscription, just make sure the services
00:54are running, and the permissions are set properly.
00:57Then in step three, we are going to redirect from the original publisher, and instead point
01:02it at the AlwaysOn Availability Group.
01:06This will allow replication to continue on even if the original publisher fails.
01:11Even if the primary replica fails, one of the secondaries could become the publisher,
01:16and our replication could carry on.
01:18So it's a stored procedure called sp_redirect_publisher.
01:22It takes three parameters: the original publisher, the database we're using for publishing, and
01:30the name of the AlwaysOn group we would like to redirect to.
01:34Once that's done, we have another stored procedure that we can use to verify the configuration;
01:42sp_validate_replica_hosts_as_publishers.
01:45When running the stored procedure, you should get some data as the output, some of the data
01:50that is being replicated from whatever subscription you were concerned with.
01:54As long as you get some data, that's a good sign, as long as you don't get an error, that
01:58means things are running properly.
02:00The errors we usually get with this are often permission issues.
02:04When I've seen this go wrong, it's typically a permission issue on the secondary servers.
02:09You need to make sure the secondary servers have the appropriate level of permission to
02:14access all of the publishers.
Collapse this transcript
6. Licensing
Choosing an edition
00:00SQL Server 2012 is available in several editions.
00:05The Enterprise edition remains the top shelf edition containing every possible feature,
00:10but also the highest price tag.
00:12By researching the features of different editions, you might be able to find all the functionality
00:17you need in a lower-priced version.
00:21The Microsoft website is certainly the best source of information for details on what
00:26features are included in what version.
00:29The amount of information presented here can be a bit overwhelming.
00:32I would like to walk you through some of it and point out some of the most popular features
00:37and what versions they are available in.
00:39Also should make a note that I am giving you information that is up-to-date as time of
00:45this recording, but Microsoft does tend change these things from time to time, in particular
00:50whenever they release a service pack for SQL Server.
00:53They often make minor changes to what features are available.
00:57With SQL Server 2012, Microsoft is primarily marketing three editions: Enterprise, Business
01:04Intelligence and Standard.
01:07Enterprise and Standard have been around for a while but Business Intelligence is new in 2012.
01:13We can scroll down here and see some of the capabilities, some of the features that are
01:17included, and as we scroll down we will see a bullet point in every single box or enterprise.
01:23Like I said it contains every single feature, and we see slightly less features in Business
01:28Intelligence and Standard.
01:31Notice the features of basic Business Intelligence: Reporting, Analytics, Data Mining and Basic
01:38data integration are included in all three editions because they have one version named
01:43Business Intelligence you might think that Business Intelligence features aren't included
01:47in the other versions. That's not exactly correct.
01:51The basic Business Intelligence, the basic reporting, the basic analytic server is included
01:56in all three versions.
01:57What Business Intelligence gives you, is a few advanced features that are not included
02:02in Standard such as Power View and PowerPivot.
02:06PowerPivot a very popular feature particularly among SharePoint developers.
02:12So that may be something that would push you to buy the Business Intelligence server.
02:16Also notice there's nothing in the Business Intelligence server that isn't in the Enterprise,
02:21so if you have access to Enterprise, there is no reason to downgrade to the Business
02:25Intelligence version.
02:27Looking at some more detailed information, in particular information about the hardware,
02:32we will notice that the Enterprise version always uses the maximum CPU and maximum RAM
02:39supported by the operating system.
02:42And on the other end of the spectrum, Standard has some limitations on the number of CPUs
02:48we can use and the amount of RAM we can use.
02:52Currently that set to 16 cores and 64 GB.
02:57Now you might be thinking, hey right now that's a pretty beefy machine!
03:0016 core, 16 GB of RAM is a pretty beefy machine by today's standards.
03:06But remember you may be putting SQL Server in production for 5, 10, 15 years. Is that
03:12still going to be a beefy machine 15 years from now?
03:15I can't say for sure, how much RAM will be common 15 years from now.
03:19I'm betting it's a lot higher than 64 GB.
03:21So those limitations are more of a problem in the future than they are right now.
03:28Notice Business Intelligence has some limitations when you're running the database engine, but
03:33it ramps up to operating system maximum on the analysis services and reporting services piece.
03:41The line on maximum relational database size is also interesting, 524 petabytes. That is
03:47very, very large.
03:49A petabyte is 1000TB, a terabyte is 1000 GB, so a petabyte is basically a million gigabytes.
03:58I have yet to see a database that is even 1 petabyte, so 524 petabytes would seem to
04:05be an overwhelming amount of information.
04:08Again it's hard to say that 10 or 15 years from now whether or not that'll still be a
04:12reasonable limitation, but also you notice Enterprise, BI and Standard all have the exact
04:19same limitations, so it's not something to consider one way or the other when purchasing.
04:24We also have a line here for the licensing model.
04:27Notice that the Enterprise edition is only per processor or per core, the Business Intelligence
04:33edition is only available with licensing model of server plus client access license.
04:39But Standard edition is available with either licensing model.
04:44So when choosing edition, you also have to consider the different licensing models and
04:48we will get into those in detail over the next few movies.
04:53
Collapse this transcript
Licensing SQL Server 2012 in a non-virtual environment
00:00SQL Server 2012 is available with two licensing models.
00:05We can license per processor core or we can license as the Server plus a Client Access License or CAL.
00:14First let's talk about Server+CAL because it's a little simpler and it really hasn't
00:19changed much since previous versions of SQL Server.
00:22In order to do this first you would license a physical server, so whatever machine you
00:26want to run SQL Server on, doesn't matter how powerful or how weak of a box it is, and
00:32then additionally you need a Client Access License either for each person that accesses
00:38or for each machine that accesses.
00:42Now most companies have one human being working at one computer, so you would end up paying
00:47the same amount whether you did per person or per machine.
00:51But let's say your business works 3 shifts during the day and all of those people share
00:55a machine, well then it might be cheaper to go per machine.
00:59Really this hasn't changed since previous versions of SQL Server.
01:03Just remember licenses don't roll forward, they only roll back.
01:07So in other words if you have a Client Access License for SQL Server 2008 it is not valid
01:13for SQL Server 2012.
01:16But if you buy a Client Access License for SQL Server 2012, it is valid for 2008, 2005,
01:242000; any previous version.
01:28Now let's talk about the per core and this is per processor core. The basic mindset is
01:34similar to previous versions of SQL Server, but the exact calculation has become a little
01:39more complicated.
01:41First of all, we used to license physical processors, in other words a physical device you plug
01:47into a mother board.
01:48Now instead we are licensing per core and pretty much every processor out these days
01:55contains multiple cores, usually 2, 4, 6 or 8 cores per processor.
02:01If you don't know how many cores are in your processor, the manufacturer can certainly tell you.
02:06And then additionally many machines have more than one physical processor, so you could
02:10likely end up with a scenario where you have two physical processors, each one of them
02:16has four cores, so you have a total of eight cores in that machine. You have to buy a license
02:22for all eight cores. You can't play any tricks to try to reduce the number of cores.
02:27And I'll demonstrate one of those things.
02:31In Management Studio, you can right-click on the name of your Server, go to Properties
02:37and there is an option for Processors.
02:42My machine shows me that I have four processors.
02:45In some versions of SQL Server you can turn on or turn off certain processors.
02:51This does not affect licensing, because there are four logical processors in this machine,
02:55in other words four cores. I still have to buy four licenses for the four cores.
03:02Even if I would go in here and turn off to the cores, I still have the license every
03:06core that is physically in that machine.
03:09So once we know how many cores are in our machine we're not 100% finished. We still
03:14have to multiply that by a core factor and Microsoft publishes a list of core factors.
03:22If you follow that link, it will take you to a download that shows a Core Factor table.
03:31I'll scroll down here.
03:34And we see that certainly for most processors the Core Factor is just 1, so you multiply
03:39times one. It doesn't change anything.
03:41But for certain AMD Processors with 6 or more cores, we have a factor of 0.75.
03:47So you would figure out how many cores you have and then multiply times 0.75 and that's
03:55the number of licenses you need.
03:57So let's work through a couple of examples on that.
04:01Let's say I had 6 cores and their AMD processors, so I multiple times 0.75, I come up with 4.5.
04:11Now it's impossible to buy half a license, it's also impossible to by less than two licenses.
04:17SQL Server core licenses are only sold in two packs.
04:22So in this case you would still have to buy 6 licenses. Didn't actually save me any money.
04:27But if I had an 8 core machine, I could multiply times 0.75 and come up with 6, and then I only
04:35have to buy 6 licenses even though I have 8 cores.
04:39So again, our process is to determine the number of cores in the machine, multiply time
04:44a Core Factor, come up with a total number of licenses you have to buy, but remember
04:50that you could only buy licenses in packs of two.
04:53Also we talked about the two different models, the per core and the Server+CAL.
04:59The Standard Edition is the only one that allows us to choose which of those licensing models we use.
05:05For Enterprise you have to do per core, for the Business Intelligence edition you have
05:10to do Server+CAL, but if you buy the Standard Edition you can choose to either do per core
05:16or Server+CAL.
Collapse this transcript
Licensing SQL Server 2012 in a virtual environment
00:00In SQL Server 2012, licensing on virtual machines can be slightly different than licensing on
00:06physical machines.
00:08If you are running the Server+CAL method, it doesn't change things too much.
00:13You still need one server license for each SQL Server you run, and users still need one
00:18CAL, regardless of whether they access servers that are physical, or they access servers
00:23that are virtual, but when we license per processor core, it becomes little more complex
00:28in a virtual environment.
00:30Microsoft uses the term v-core to discuss a virtual core.
00:35One v-core license is required for each hardware thread used by the virtual machine.
00:41Microsoft defines a hardware thread as either one physical core or one hyper-thread on a
00:48physical processor.
00:49Most hardware virtualization systems have a 1:1 ratio of cores to hardware threads.
00:56Meaning, you will need to buy one v-core license for each virtual core presented to the machine.
01:02Some virtualization systems allow two hardware threads per core, and that would double the
01:07number of licenses you need.
01:10You only need to license the cores presented to the virtual machine.
01:13For example, if you have 24 cores in your physical machine but the virtual SQL Server
01:19is only allocated six of these cores, then you only need to buy six v-core licenses.
01:25Now remember, some virtualization systems can dynamically add or remove CPU power at
01:31runtime, and you need to have the appropriate licenses in place before you increase the
01:36number of v-cores presented to a virtual server.
01:40Last but not least, Microsoft requires that every virtualized SQL Server require a minimum
01:46of 4 v-core licenses.
01:49Microsoft has given us one more option for licensing SQL Server, and I think it is a
01:53particularly good option especially for large companies.
01:57It is called licensing for maximum virtualization.
02:00This licensing model only applies to the Enterprise Edition of SQL Server 2012.
02:06It allows you to run unlimited number of virtual SQL servers on one physical machine as long
02:12as you buy the license for every physical core on that machine.
02:16So you would use the techniques we talked about in a previous movie to determine how
02:20many core licenses you need for the physical machine.
02:23Go ahead and buy a license for every physical core in that machine.
02:28And once you've done that, you can turn up a new virtual SQL Server anytime, and don't
02:33have to worry about purchasing new licenses.
02:35This could be a significant savings, particularly if you would like to run a very large number
02:40of virtual servers on one very powerful box.
Collapse this transcript
7. Additional Changes
Introducing new conversion, logical, and string functions
00:00SQL Server 2012 gives us 14 new functions.
00:05And I know developers are always excited to have new toys to play with.
00:09Some of these are really useful, some of these more serve a utility purpose that probably
00:13wouldn't be used real often.
00:16Let's go and go through some of these.
00:18I have some code staged for you in your exercise files.
00:22I'm going to copy these over on at a time, paste into Management Studio.
00:27So our first new function is called PARSE and this function is used for parsing dates,
00:35times and currency options in the different local culture.
00:39As I'm sure you're aware some countries use different symbols for currency. Some countries
00:45use the comma and the period different as delimiters between the whole numbers and the
00:49fractional numbers, and certainly dates can be formatted a wide variety of ways.
00:55The Parse Function allows us to convert from the common formatting of one culture to the
01:00common formatting of another culture.
01:02Or in this case, the example I have on the screen, removing the formatting, just converting
01:07to a SQL Datatype.
01:09So we'll execute this, and we see simply that it took off the currency symbol and changed
01:14the comma to a period and returned to us a common SQL Datatype.
01:20Very useful function, if you working with international applications that need to accept
01:24input from a lot of different people possibly in different countries.
01:28You may find this quite useful.
01:30However, if all of the applications you develop, run in the same country in which they're developed,
01:35and you only have customers from that country then this may not be that useful for you.
01:40The next two we have our TRY_CONVERT and TRY_PARSE.
01:44As the name implies TRY_CONVERT works very similar to the way CONVERT works.
01:50It just handles errors a little differently.
01:53So I'll copy and paste this code over.
01:55Basically, I'm trying to convert the word hello into an integer.
02:00Obviously, that is not going to be successful.
02:03When I Execute this, it returns NULL.
02:06If we had used the older CONVERT function without the word try in front of it, this
02:10would have returned an error instead.
02:12It says conversion failed.
02:14When the conversion is successful either CONVERT or TRY_CONVERT do exactly the same thing.
02:20They only handle errors differently.
02:23TRY_CONVERT really avoid sending errors, it returns NULL, instead of an error.
02:29And TRY_PARSE is the same thing.
02:32It functions exactly the same way as PARSE when it works properly.
02:35When there's an error, it will return NULL rather than error.
02:39Moving on to our logical functions; the first one is called to CHOOSE. Copy and paste that over.
02:46CHOOSE allows us to look at a list of items and select one based on an index we pass as
02:51the first parameter.
02:53So here to my CHOOSE Function the first thing I passed was the numeral 2, and then I passed
02:58a list of three items.
03:00What's going to be returned is in fact that second item in the list, because I passed that 2.
03:06This is somewhat similar to working with arrays.
03:09Except on arrays we always start counting on 0.
03:11And here with the CHOOSE, we start counting on 1, so the first element is a 1 not a 0.
03:19If you are used to working with arrays in other programming languages, you might find
03:23this a little awkward.
03:24And I agree it's not as elegant as full array support, but you know we work with what we have.
03:30T-SQL does not yet have full-on arrays.
03:33So we'll work with this CHOOSE structure.
03:35Hopefully, in the future we'll get some more powerful array functionality.
03:40The next one I'm honestly not quite sure how to pronounce, it's IIF spelled with two I's, so it's I-IF.
03:47And that does function similar to a typical If statement, but whereas an If statement typically
03:52only allows us to look at what to do if the value is true.
03:57The one with two I's allows us to say what happens if it's false.
04:02So when our statement is true, whatever is the next parameter is what will be returned,
04:08and whenever our statement is false, whatever is the third parameter will be returned.
04:14This isn't real common in other programming languages.
04:16However, it is very common in Microsoft Access.
04:20And because people convert a lot of apps from Microsoft Access to SQL Server, this is a logical thing to do.
04:26If you do in fact convert from Access to SQL Server, I think you'll use this often.
04:31If you're not doing that conversion, I'm not sure I see a whole lot of use for this.
04:36Next with our string functions, we have CONCAT which is an abbreviation for concatenate.
04:44And as the name implies, it takes a series of parameters and returns them as a concatenated string.
04:51Obviously, there are other tools and techniques for doing this inside of SQL Server, but many
04:56of those tools and techniques stumble when you pass parameters that are not strings,
05:02CONCAT handles that well.
05:03So you'll see I'll pass it a number, and it will automatically convert that to a string.
05:09And also very surprisingly it handles nulls, so I can even pass the NULL value to it, and
05:15it basically ignores the NULL value.
05:19And just continues to right on after it.
05:22So this is unique amongst our different string concatenate techniques.
05:27All other string concatenation techniques would stumble on that null.
05:31And the last one I want to demonstrate is the FORMAT.
05:34And FORMAT has some similarities to the first one we did.
05:38It again works with formatting dates, times and currencies into different cultures.
05:45The first function we did call PARSE was assuming that the input was already formatted in some
05:50culturally specific way and then we converted it to a SQL Datatype.
05:55This is the exact opposite.
05:57We start off with a SQL Datatype and we converted to some culturally specific way.
06:03So I'm going to take the date of October 16th and convert it into German, Great Britain,
06:09and simplified Chinese, showing that there are several different ways to express that date.
06:16Again for some of you very, very useful, if you work with a lot of international applications,
06:21for other people probably not so useful.
06:24We also have a big group of date and time functions, new in SQL Server 2012.
06:29I'm not going to do a demo on these.
06:32There is good utility here for some of these.
06:35They're probably not going to be used nearly as often as the previous seven, but just stored
06:40somewhere is on the back of your mind that there are some new functions.
06:43Most of these, as the names imply, allow us to create a date from the individual parts.
06:49So you would pass parameters individually for month, year, day and then possibly the time.
06:57And that could return either a DATE, a DATETIME, a DATETIME2, et cetera, et cetera.
07:03So file away in the back of your mind that these exist and you can come back and use
07:07them when it's necessary.
Collapse this transcript
Understanding changes to hardware and operating system support
00:00Many of you may remember that from 2001 to 2009 Intel sold a family of processors called
00:07Itanium processors.
00:09You may also remember that SQL Server 2005 and 2008 were sold in special editions specifically
00:17for the Itanium processor.
00:20That is no longer the case. With SQL Server 2012 we do not have a special version for
00:26Itanium processors, but you still can install SQL Server on a machine running an Itanium
00:32processor. Just use any of the 64-bit versions of SQL Server.
00:38New in SQL Server 2012 we have the option to install SQL Server on a reduced version
00:46of the operating system called Server Core.
00:49Server Core is something Microsoft came out with, with Windows server 2008. It is a scaled-down
00:54version of the operating system. It has removed pretty much all graphical elements and it
01:00just a command line interface. It runs significantly less services than a full-blown version of Windows.
01:07So if you're running Windows Server 2008 or to Service Pack 1 or Windows Server 2012 Server
01:15Core, you can install any 64-bit version of SQL Server on those.
01:20Some of the advantages of that Server Core only installs the minimum required services
01:26for a manageable server. That means there will be less time and energy to manage the server.
01:32For example, when patches come out for Windows servers, many of those patches do not apply
01:38to sever core. Server core simply isn't running the service that that patch applies to.
01:44And less patching needs fewer reboots meaning your SQL Server is online.
01:49Server Core is also more secure, because there is less things to attack. Less services running
01:55means less attack surface.
01:57Less services running also means more memory of available to applications, available to
02:02your SQL Server, and available to any custom application you may want to run.
02:08Not everything in a SQL Server is available once you install on Server Core.
02:13We'll see that the majority of the most important things are certainly there. We get the database
02:18engine, replication, full text search, analysis services and integration services will all
02:25work perfectly fine if you install on Server Core.
02:29However, reporting services will not work. It's just simply not an option at this time.
02:34Probably will work at some point in the future, but right now we cannot install reporting
02:38services on Server Core.
02:41You also don't get the SQL Server books online. Probably not a big deal because you could
02:45look at that someplace else.
02:47And the Management tools, so for example Management Studio will not run on the machine that's
02:53formatted Sever Core, but you could run Management Studio on some other machine and still connect
03:00to your Server Core machine.
03:01So you will have to do remote management which realistically on a production server you're
03:07likely doing remote management anyway.
03:10So we're really not giving up much functionality. Not having reporting services will be a deal
03:15breaker for some people, but other than that you're not really giving up any functionality
03:20and the advantages of several core are significant. It's something everyone should consider.
Collapse this transcript
Exploring new types of indexes and new options on indexes
00:00In SQL Server 2012, Microsoft has introduced a new type of index called the columnstore index.
00:07This is somewhat similar to traditional indexes, in that, the point of it is to increase the
00:13performance of queries. The mechanics behind the scenes work a little different.
00:17A columnstore index groups and stores data for each column first and then worries about
00:24the rows, whereas a traditional index grouped and stored data by the row first, and then
00:30worried about the columns.
00:32You'll see the biggest performance advantage on a columnstore index when you have a particular
00:37situation, a particular pattern of data, and this happens when a column has a small set
00:43of distinct values that are repeated over and over.
00:46So for example, think about a database table that tracks the sales of a product across
00:5150 retail locations.
00:53There might be millions of rows in that table, but the location ID column is always going
00:59to contain one of 50 pieces of data.
01:02So it's a relatively small number of distinct values that are repeated over and over.
01:08Furthermore, it's likely that you are going to run reports grouped by that column, grouped by location.
01:14In this situation you would see a big advantage from one of the new columnstore indexes.
01:21I would recommend as you're getting used of columnstore indexes with some queries to try
01:26it with a traditional index, and then remove that index and create a columnstore index,
01:32run the query again and see if you get better performance.
01:37Overtime as you do this, you hopefully start to develop some instincts on which queries
01:42would benefit most from a traditional index and which queries would benefit most from
01:47a columnstore index.
01:49In SQL Server 2012, Microsoft has given us the option for indexes to remain online while
01:55you rebuild them, also while you perform other alter statements on them, like adding a column
02:01or removing a column.
02:03The syntax for this is pretty simple. You can take any ALTER INDEX statement and just
02:08add at the end WITH (ONLINE = ON) and that index will remain online and usable throughout
02:15the alter process.
02:17This is available in the Enterprise Edition only, won't work on any other edition.
02:22What goes on in the background when this happens is a complex system of locking the index,
02:27copying parts of the index over slowly and re-creating that index, all while leaving
02:33it online for any query to continue to use it.
02:36This can be taxing on the system. It can use a lot of processor, a lot of memory, and it
02:41can hit your disk subsystem pretty hard.
02:44So if you have a traditional maintenance window, where you take indexes offline and perform
02:49your maintenance offline, I would recommend continuing to do that.
02:53But if you have a situation where you really need to be online 24/7 and you need all of
02:58your indexes to be online 24/7, you do have the option to do that, just be prepared to
03:05shell out some big dollars for Enterprise Edition SQL Server and you'll probably need
03:09some beefier hardware.
03:11So not too uncommon that wanting to be online 24/7 is possible, it's just expensive.
03:17SQL Server 2012 has made some changes to our spatial indexes.
03:22So just a quick review, spatial indexes were introduced in SQL Server 2008 and they came
03:28in two flavors: geometry and geography.
03:32Geometry assumes a flat two- dimensional plane like a black board.
03:37Geography assumes a curved two-dimensional surface such as the surface of the earth.
03:43Pretty much all of the changes in 2012 have come on the geography type. Microsoft has
03:49made that more robust.
03:51One of the limitations in SQL Server 2008 was you could only work in one hemisphere at a time.
03:58So for example you could draw a line from one point in the Northern Hemisphere to another
04:03point in the Northern Hemisphere, and you could draw a line from one point in the Southern
04:07Hemisphere to another point in the Southern Hemisphere, but you could not draw a line
04:12from a point in the Northern Hemisphere to a point in the Southern Hemisphere.
04:162012 removes that limitation and we can now work with what they call the full globe.
04:22So you can draw a line from any point. It doesn't matter what hemisphere it's in.
04:28Along with that, Microsoft has introduced three new subtypes of circular arcs. They are called
04:34circular string, compound curve and curved polygon.
04:39All of these things are structures that used to exist in geometry and now have been modified
04:45slightly to exist in the geography mindset where they do a better job of hugging the
04:51curvature of the sphere.
04:53If you work with spatial indexes, I encourage you to research these more.
04:58SQL Server 2012 looks like it's continuing more after the specialty market of GIS systems,
05:04which is something that many developers won't ever get to work with, but if you do have
05:07the chance it can be very exciting.
Collapse this transcript
Understanding new administrative options
00:00In this section, I would like to talk briefly about administering SQL Server 2012.
00:06This course is primarily for developers, but let's be perfectly honest all developers end
00:11up doing at least a little bit of administration. Some of us end up doing a lot of administration.
00:17One of the tools that's changed slightly, is the sqlcmd.exe, the SQL command.
00:22One of these changes is very exciting to me and I think a very positive thing.
00:26There was a problem with previous versions of SQL command where it would take a single
00:31quote and replace it with an ampersand APOS, in other words, they thought it was an apostrophe
00:37instead of a quote.
00:38They have removed that or as I would say they've fixed that bug and now a single quote stays
00:44as a single quote. Definitely a positive change in my opinion.
00:48The other two changes here are very minor, just changing how the system handles situations
00:54where you don't put a value after the decimal point.
00:58Does it assume zero or does it assume .000, et cetera, et cetera.
01:04How many zeros does it assume? It's a very minor change in my opinion.
01:09A few changes with PowerShell, first PowerShell is no longer installed with SQL Server, instead
01:15it is a prerequisite.
01:17So you have to have PowerShell 2.0 on a machine before you can install SQL Server 2012.
01:23Realistically most Microsoft operating systems will already have PowerShell 2.0, but if you
01:29don't have it, it's a free download from Microsoft.
01:32Also inside of Management Studio, when you launch PowerShell, you will be launching the
01:37full version of PowerShell 2.0.
01:39Let me show you what I mean.
01:41In Management Studio, there are lots of places you can right-click, and one of the options
01:46that comes up is Start PowerShell.
01:49We see that on several of the different containers we can click on, Start PowerShell.
01:56It used to be, in previous versions of SQL Server, when you would click on Start PowerShell,
02:02it would actually open what's known as a mini- shell, which is a reduced functionality PowerShell.
02:08Basically you could only run commands specific to SQL Server.
02:12Now they've changed that and when we start this, it is a full version of PowerShell, PowerShell 2.0.
02:18So not only can you run any SQL command here, you can run any other PowerShell command if
02:24you would like to administer your operating system at the same time.
02:28A few changes to Dynamic Management Views and functions; one of the more common Dynamic
02:33Management Views the execute query stats, they've added four columns.
02:38A lot of people use exec_query_stats to look for slow running queries and troubleshoot
02:44slow running queries.
02:45The four new columns will give you additional information for your troubleshooting.
02:49I think they'll all be useful.
02:51They are total rows, minimum rows, maximum rows, and last rows.
02:56We also have a handful of new functions.
02:58I am going to talk about three of the ones that I feel are the most useful.
03:01I am going to have a little demo setup on these, in your exercise files.
03:06We will run each of these one at a time, copy and paste over into Management Studio.
03:14So this first one dm_os_volume_stats, as the name implies it's telling me about the volume
03:24to which my database is running. In other words, information about the dish drive.
03:29So this tells me I'm running on the C drive, and as I scroll over, it tells me how much
03:35free space is on the C drive, whether or not the C drive supports compression, and whether
03:41or not it is read-only.
03:43Obviously all of this information was available through other sources, but this is the first
03:48time we have it available in a quick and easy table format.
03:53The next Dynamic Management View I would like to talk about is called dm_server_services.
04:00If we execute this, you can see that it tells me information about the SQL services that
04:06are running on this machine.
04:07So I'm running SQL Server, SQL Server Agent and SQL Full-text Filter.
04:13It shows me the startup_type and whether or not they are running right now, and some other information.
04:20Again all of this would have been available through other places. You could have gone to Control
04:24Panels and found out all this information, but it's nice to have it available inside of SQL Server.
04:30A lot of people write a little bit of SQL code that will document their current solution
04:34or their current environment.
04:36This is a Dynamic Management View that's going to make that documentation a little easier.
04:40You can just run this query and drop that into a text file, and you have a nice neat
04:45documentation on what services are running on your machine.
04:49Next, we will talk about dm_server_registry.
04:55This is going to show me all of the registry keys, SQL Server is reading for its configuration,
05:01which is a lot of information. It shows me the registry key and as I scroll over the
05:06value of that key, and this returned about 63 rows.
05:11I could've gotten this information directly from the registry, but obviously there is
05:15a lot more than 63 rows in the registry.
05:18Finding all this information in the registry would have involved looking through lots and
05:22lots of other stuff, so having all this information in a clear, concise location without all of
05:30the other stuff from the registry is very valuable.
05:32I personally am working on some projects right now where I'm trying to recreate a SQL Server
05:38in one data center, exactly the same as it is in another data center.
05:42Unfortunately I'm not running SQL Server 2012.
05:46If I was, I would certainly be using this Dynamic Management View. What I would do is
05:51run it on both machines and then compare the results.
05:53At any place that is different would be a cause to go and investigate, and see if these
05:59two servers actually do in fact have a different configuration.
06:03So this is a great way to first of all document your current configuration and secondly compare
06:08the configuration of two separate SQL servers.
06:12
Collapse this transcript
Accommodating changes to database structure
00:00Microsoft SQL Server 2012 gives us the ability to create multiple file groups for our file stream data.
00:08So I'm going to right-click on this database and go to Properties, and then I'll select
00:13Filegroups and at the bottom we have the File Stream section.
00:18I currently have one file group. I can add another, and I could add another, and I could another.
00:24You can have as many as you want.
00:26Previous versions of SQL Server limited you to only one.
00:30So the question is, why might you want to do this?
00:32Well, it's the same reasons that we do this with non-file stream data.
00:37We can create multiple file groups typically for one of two reasons.
00:41One would be performance. If we create files on different disk drives we can often see
00:46a performance increase.
00:48So remember creating multiple files on the same disk drive are typically not going to
00:53increase performance, but creating multiple files on different disk drives could in fact
00:58increase performance.
01:00The other thing is administration. Remember some of your administrative tasks are performed
01:04at the file group level, such as backup and restore.
01:07So if you had some file stream data that changes on a daily basis and needs to be backed up
01:12on a daily basis you could put that in one file stream group.
01:16And let's say you have other file stream data that only changes maybe once a month or once a year.
01:23Therefore it doesn't need to be backed up nearly as often, you could put that in a different
01:27file group with a different backup schedule.
01:30We also need to talk briefly about SQL Server 2012 endpoints.
01:35We still have the TSQL, SERVICE_BROKER, and DATABASE_MIRRORING endpoints.
01:40However, Microsoft has removed the native XML Web services endpoint. This feature simply
01:48no longer exists in SQL Server 2012.
01:51Kind of surprising that they removed it so quickly. Usually a feature is moved to the
01:55deprecated list and then in some future version it is removed. In this one they kind of removed
02:02this one rather quickly.
02:03To be honest this is a feature that not a whole lot of people used. It was never adopted
02:07very well by the user community.
02:09Some of the other endpoints are used very commonly, particularly Database Mirroring is very common,
02:15but the Native XML Web Service endpoint was not commonly used and therefore has been removed.
02:21There really isn't a work around, so if you have a SQL Server that utilizes this feature,
02:27you really can't upgrade to 2012. You need to stay at 2008 or 2004 now.
02:33Contact Microsoft, see if there is an upgrade path in the future, but for right now you
02:39need to not upgrade.
Collapse this transcript
Conclusion
Goodbye
00:00This concludes our course, SQL Server 2012 New Features.
00:04I certainly hope you found it informative.
00:06I'd like to leave you with a few thoughts, some resources you can utilize to further
00:11your knowledge of SQL Server 2012.
00:14The first one is the Microsoft Documentation.
00:16I find SQL Server to be the best documented product Microsoft puts out.
00:21In particular they have a publication called the SQL Server 'Books Online' that is excellent.
00:26It contains quite a wealth of information, lots of technical information, lots of walk-throughs,
00:32lots of introductory information.
00:34It's available through the Microsoft website or you may have installed it, when you install
00:39SQL Server you have the option to install Books Online locally.
00:43I typically do that in case I'm ever offline away from the Internet.
00:48For example, on an airplane or something, I'd still like to have that documentation there with me.
00:53However, when I have it installed locally and I'm off-line, I'm not sure SQL Server
00:58Books Online is the right name for it.
01:01Maybe it should be called SQL Server Books Offline.
01:03Anyway it's a very good resource and I encourage you to probably go there first for most of your questions.
01:10If you're looking for a third-party point of view I like sqlservercentral.com.
01:16It contains a wealth of information about SQL Server and other issues that affect database
01:21administrators and database developers, such as Windows issues, security issues, and common regulations.
01:29It has an active user community, so if you have questions you can post them, typically
01:34get a response fairly quickly.
01:36It does require you to sign up but the sign up is free.
01:38I'll also encourage you to look into another course here on the lynda.com online training library.
01:45SQL Server: Triggers, Stored Procedures and Functions.
01:49It contains the information on those topics on both SQL Server 2008 and the new SQL Server
01:542012 that I'm sure you're excited about.
01:57Again, thank you for your time and I hope you enjoyed the course.
Collapse this transcript


Suggested courses to watch next:

SQL Server 2008 Essential Training (6h 54m)
Simon Allardice


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,141 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked