At third, if you want to learn more about how that script works keep reading.

1. Script Parameters and variables:

- @CenterX & @CenterY - Starting point of the initial triangle. It is set to (0,0), but really does not matter unless you have special requirements.

- @Radius - That is a Radius of Circumscribed circle of the Initial Triangle. It can be any, but do not make it too small because you can loose precision.

- @Angle - An Angle you want your Initial Triangle to be turned. It really does not matter, you just have ability to rotate Fractal on the screen. Try to use value "15" for better effect visibility.

- @MaxLevel - Specifies how many levels deep you want to draw your Fractal. That value can't be big. With Max Level value "9" I've got almost 2 millions of objects. So, you can try more if you want to wait. However SSMS will not be able to show you so many objects. The maximum Number I've got was little bit lower than 250K.

- @CurrLevel - Just a variable to track current Level of Fractal's Triangles

- @Rate - Rate with which triangles will be decreasing in size. With Rate = "1" child triangle's Radius of Circumscribed circle will be twice as less Radius of the Parent's triangle. You can play with that value, but pictures might be not so nice.

2. Temporary Table

It contains all parameters of created triangles such as
- Center point;
- Coordinates of all Corners of a triangle;
- Radius of Circumscribed circle;
- Triangle Inclination Angle;
- Level of the triangle (1 is the highest);
- Processing Bit Indicator. Set to 1 if triangle already has children;
- ID Identity field;
- Calculated Spatial field. It allows you to see graphical results by just simple selecting that field from the table.

3. Triangle construction.

There is no sacred magic in the original triangle construction, so, will start from the child generation level in Step 2.1.
3.1. Lines 59-64. Here we direct how many child triangles will have each side of a parent. To demonstrate that change value of variable "@MaxLevel = 2" and replace that section with the following and run the whole script:

First side has only one child in the center, second have two children near corners and third one has all places filled. You can specify only one side by replacing what section by just "SELECT 0 as Side, 1 as Position" and changing variable "@Rate = 1.5097. Then you can get something like this:

4. Triangle presentation

That is most difficult operation. At first, SSMS can't show more than 5000 separate objects at the same time. In order to show more we have to construct "MULTIPOLYGON" or "GEOMETRYCOLLECTION". That only the way to fit more objects into SSMS screen. However it is still limited.
In order to combine triangles in a single object we divide them in buckets (Line 106).
In this example I just making number of buckets approximately equal to a number of objects within each bucket. Making lower number of buckets will increase processing speed, but produce less colors. All objects in one collection will have the same color.
Also, I wrapped the last query in extra CTE to have more flexibility on results formation.

5. Playing with results

As I mentioned in #4, you can change Line 124 to produce slightly different results.
For instance you can replace it with that:
"SELECT Polygon.STBoundary() FROM Collections"
That will show ONLY the boundaries of all triangles and you might see something like this:

You also can play with number of buckets in Line 106, replacing it by following:
"Bucket = TriangleID % 5000"

6. Playing with configuration.

Besides of changing an inclination angle the biggest change is number of children triangles.
Do the following:
- Replace Lines 59-64 by following:

Tuesday, November 17, 2015

In this post I will not describe how to download SQL Express, or where to buy SQL Developer edition.
Will not pinpoint on how to install them and what hardware/software you need to have.

Assume you already dedicated several Gigabytes of your hard drive, installed and successfully tested your local SQL Server.
So, what is next.

The very next you'll face a problem of not having enough memory, unless you only run "SELECT@@VERSION;"

Here I will discuss about how to reclaim your memory back from local SQL Server and do it very easily without spending much time on it.

Will do it in Three very easy steps:

Step 1: Make sure that SQL Server does not start automatically.

When you just start your computer or VM you usually want to do other stuff, such as browsing the Internet, Manage your Finances or even playing games, rather just than accessing your SQL Server instance. That time you do not want SQL Server to eat 200 Mb of your valuable memory.
In order to prevent that you have to set your SQL Server do not start automatically during the system startup. If you did not specified that option during the SQL Server installation I'll show you how to do it.
At first you have to start Windows Services Console. In order to do so you do following:
- Run "Control Panel" (That will be a problem in Windows 10);

- In "Control Panel" go to "Administrative Tools";

- In "Administrative Tools" start "Services";

Actually, I've promised you the "Easy Way". So, you can just press "Win+R" on your keyboard. Copy paste the command "%windir%\system32\services.msc" and press "Enter".

When List of services opened, scroll down to SQL related services.

"Startup Type" for all of them has to be "Manual" or for some services it can be even "Disabled".
In order to get that just double click on the service, choose "Startup Type" as "Manual". Stop the service if necessary and hit "OK" button.

Please make a note of the name of your SQL Server Service. In my case it is "MSSQLSERVER".

Step 2: Easily start SQL Server Service.

Now, when you need to play with your personal SQL Server you can just go to Services again and start it.
Not easy enough?
Here is an easy way:
- Do a right click on your desktop; Choose "New" and then click on "Shortcut"

- In the Location Bar type "NET START MSSQLSERVER", where "MSSQLSERVER" is the name of your SQL Server Service you captured in the first step.

- After hitting next, name your new shortcut like "Start SQL Server" and hit "Finish".

- That is not the End. You have to finish the configuration to have it Really Easy: Right click on your new shortcut icon and choose "Properties".

- In the Shortcut Properties in "Shortcut" tab click on "Advanced..." button.

If you will click on your new shortcut it will ask you for administrator's permissions to run you "SQL Server Service". When you hit "Yes" it will open a windows shell window indicating an attempt to start your "SQL Server Service".

Now you can go to "Control Panel Services" and verify that your SQL Server Service successfully Started.
From this point you can connect your SQL Server in Management Studio.

If, by any chance, Service did not start see "Step Zero" below on how to troubleshoot the issue.

Step 3: Easily Stop SQL Server Service.

That is very possible you performed some very heavy and memory intense operation by your local SQL Server instance and it ate all your free memory. You do not need it anymore, but SQL Server won't easily give memory back.
The easiest way to claim all your memory is to stop your SQL Server.
There are some easy ways doing it:
- First way us using SQL Server Management Studio. You just have to do a right click on your local SQL Server instance and choose "Stop".

It will ask you for the confirmation. Just say "Yes" for it.

That is very smart way to stop SQL Server from SSMS, but would say you've forgot to do it. Do you want to re-start SSMS again just to stop SQL Server Service?
The second your option will be quick and dirty:
- Use "Task Manager". Just Press three buttons at once on your keyboard: "Ctrl-Shift-Esc".
Just scroll through the list of tasks and kill SQL Server Service by pressing "End Task" button.

That "quick and dirty" and now will be "quick and clean".

You probably already guessed it because it is the same way as in our "Step 2", but instead of starting the Service we want to stop it:
- First, Copy and Paste your new shortcut you created for starting the service and rename it to "Stop SQL Server"

- Open the shortcut properties and change "Target" to "C:\Windows\System32\net.exe STOP MSSQLSERVER" and hit "OK" button to save the changes:

Now you have two very nice shortcuts to Start and Stop SQL Server Service, which you can "Pin to Start" and have them available any time when you press "Win" button.

Step Zero: You are unlucky guy and your SQL Service does not start.

Lets go through a troubleshooting.
To troubleshoot your case you have to run "Windows PowerShell" in administrator's mode. In order to do this press "Win+S" and type "PowerShell". When it will be found make a right click on the "Windows PowerShell" and choose an option "Run as administrator".

Case 1. Wrong Service name. In that case you have following error:The service name is invalid.
In this case you just have to figure out the correct Service name.

In Order to figure out correct SQL Server Service name you can run following command:Get-Service | Where-Object {$_.displayName.StartsWith("SQL")} | Select name
In my case it returned following:

Case 2. Service is disabled. In that case you have following error:System error 1058 has occurred.The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.

That probably means that by some reason your SQL Service is disabled. To check it out run the following command in PowerShell:

get-wmiobject win32_service -filter "name = 'MSSQLSERVER'"

Here is my result when service was disabled:

For easy fix you can go to "Control Panel Services" and change the Start mode there or simply run following command:set-service MSSQLSERVER -startuptype manual

Case 3. Service can't start because your Shortcut is not configured to run as administrator.
Here is nothing to troubleshoot. If Shortcut does not ask you for Administrator's permission just re-do the Step 2.

Case 4. Service doesn't start at all.
Nothing to troubleshoot again. If you can't start your service even from "Control Panel Services" that means something is scudded off completely. I don't want to cover possible SQL Service Service problems in that post. You have to search solution somewhere else or simply repair SQL Server Installation on your workstation. It might be much faster than search for the solution.

2. Uninstalled my previous installation of CTP2. That means I had no issues on the very initial setup of new installation.

3. After choosing the evaluation version of the product I selected ALL available services and features within an installation.

4. After hitting "Next" button, I got following error:

Somehow SQL Server installation required Oracle JRE!
After I got back and unchecked "Polybase Query Service for External Data" feature everything went well.

5. I've tried to set all services on my virtual machine to start manually, to save some memory, but new feature "SQL Server Launchpad" can't be changed.

6. Collation setup looks just little different, but no surprises.

7. Very nice new feature is setting multiple TempDB files during Install.
It is not very obvious how to place different TempDB data files on different drives, only Log file has it's special folder.
I've found it wonderful that Setup program recognized virtual environment and allowed me to place TempDB files in folder on my Host machine.

8. Unfortunately, I do not have a domain setup in my virtual environment, so, I couldn't use UNC path.
When I tried to get back I couldn't move forward anymore and replace UNCs by local folders.
As a result I had to restart setup program.

9. After I restarted Setup and choose all default options everything else was as in previous version of SQL.

10. After the full install it required me to restart my virtual machine. After restart I've got newest shiny version: