difference between varchar(500) vs varchar(max) in sql server

[Origin]: https://stackoverflow.com/questions/3682821/difference-between-varchar500-vs-varcharmax-in-sql-server

In SQL Server 2000 and SQL Server 7, a row cannot exceed 8000 bytes in size. This means that a VARBINARY column can only store 8000 bytes (assuming it is the only column in a table), a VARCHAR column can store up to 8000 characters and an NVARCHAR column can store up to 4000 characters (2 bytes per unicode character). This limitation stems from the 8 KB internal page size SQL Server uses to save data to disk.

To store more data in a single column, you needed to use the TEXT, NTEXT, or IMAGE data types (BLOBs) which are stored in a collection of 8 KB data pages that are separate from the data pages that store the other data in the same table. These data pages are arranged in a B-tree structure. BLOBs are hard to work with and manipulate. They cannot be used as variables in a procedure or a function and they cannot be used inside string functions such as REPLACE, CHARINDEX or SUBSTRING. In most cases, you have to use READTEXT, WRITETEXT, and UPDATETEXT commands to manipulate BLOBs.

To solve this problem, Microsoft introduced the VARCHAR(MAX), NVARCHAR(MAX), and VARBINARY(MAX) data types in SQL Server 2005. These data types can hold the same amount of data BLOBs can hold (2 GB) and they are stored in the same type of data pages used for other data types. When data in a MAX data type exceeds 8 KB, an over-flow page is used. SQL Server 2005 automatically assigns an over-flow indicator to the page and knows how to manipulate data rows the same way it manipulates other data types. You can declare variables of MAX data types inside a stored procedure or function and even pass them as variables. You can also use them inside string functions.

Microsoft recommend using MAX data types instead of BLOBs in SQL Server 2005. In fact, BLOBs are being deprecated in future releases of SQL Server.

Credit: http://www.teratrax.com/articles/varchar_max.html

In SQL Server 2005 and SQL Server 2008, The maximum storage size for VARCHAR(MAX) is 2^31-1 bytes (2,147,483,647 bytes or 2GB – 1 bytes). The storage size is the actual length of data entered + 2 bytes. The data entered can be 0 characters in length. Since each character in a VARCHAR data type uses one byte, the maximum length for a VARCHAR(MAX) data type is 2,147,483,645.

Full Interesting read for you: http://www.sql-server-helper.com/faq/sql-server-2005-varchar-max-p01.aspx

Reference: http://msdn.microsoft.com/en-us/library/ms143432.aspx


Why use angular’s $log instead of console.log?

[Origin]: https://stackoverflow.com/questions/24185847/why-use-angulars-log-instead-of-console-log

I understand it is a best practice in angular to use $log instead of console.log. However, I can’t find good documentation explaining the reasons. Why should a developer use $log?

$log first checks if the browser supports console.log (IE 8, for example, doesn’t). This prevents errors being displayed on IE 8. Note: this doesn’t mean it will log anything on IE 8, it simply means it won’t throw the error.

Next to that, it also allows you to decorate and mock $log for extending and testing purposes, if you are so inclined. You could for example decorate it to log to an array for IE 8 support.

A bonus feature: if you pass it a JavaScript Error instance, it will attempt to format it nicely. This can be found out by reading the source code.

EDIT: “It is not that IE 8 doesn’t support console.log. It just doesn’t create the console object until the dev tools are opened.” See comments below for more details.

Change Schema Name Of Table In SQL

[Origin]: https://stackoverflow.com/questions/15482838/change-schema-name-of-table-in-sql

I want to change schema name of table Employees in Database. In the current table Employeesdatabase schema name is dbo I want to change it to exe. How can I do it ?






I tried with this query:


But this gives me an error:

Cannot alter the schema ‘exe’, because it does not exist or you do not have permission.

What did I miss?


Create Schema :

IF (NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'exe')) 

ALTER Schema :


Where should I put tags in HTML markup?

[Origin]: https://stackoverflow.com/questions/436411/where-should-i-put-script-tags-in-html-markup

When embedding JavaScript in an HTML document, where is the proper place to put the tags and included JavaScript? I seem to recall that you are not supposed to place these in the  section, but placing at the beginning of the  section is bad, too, since the JavaScript will have to be parsed before the page is rendered completely (or something like that). This seems to leave the end of the  section as a logical place for  tags.

So, where is the right place to put the  tags?

(This question references this question, in which it was suggested that JavaScript function calls should be moved from  tags to  tags. I’m specifically using jQuery, but more general answers are also appropriate.)


Here’s what happens when a browser loads a website with a  tag on it:

  1. Fetch the HTML page (e.g. index.html)
  2. Begin parsing the HTML
  3. The parser encounters a  tag referencing an external script file.
  4. The browser requests the script file. Meanwhile, the parser blocks and stops parsing the other HTML on your page.
  5. After some time the script is downloaded and subsequently executed.
  6. The parser continues parsing the rest of the HTML document.

Step 4 causes a bad user experience. Your website basically stops loading until you’ve downloaded all scripts. If there’s one thing that users hate it’s waiting for a website to load.

Why does this even happen?

Any script can insert its own HTML via document.write() or other DOM manipulations. This implies that the parser has to wait until the script has been downloaded & executed before it can safely parse the rest of the document. After all, the script could have inserted its own HTML in the document.

However, most javascript developers no longer manipulate the DOM while the document is loading. Instead, they wait until the document has been loaded before modifying it. For example:

<!-- index.html -->
        <title>My Page</title>
        <script type="text/javascript" src="my-script.js"></script>
        <div id="user-greeting">Welcome back, user</div>


// my-script.js
document.addEventListener("DOMContentLoaded", function() { 
    // this function runs when the DOM is ready, i.e. when the document has been parsed
    document.getElementById("user-greeting").textContent = "Welcome back, Bart";

Because your browser does not know my-script.js isn’t going to modify the document until it has been downloaded & executed, the parser stops parsing.

Antiquated recommendation

The old approach to solving this problem was to put  tags at the bottom of your , because this ensures the parser isn’t blocked until the very end.

This approach has its own problem: the browser cannot start downloading the scripts until the entire document is parsed. For larger websites with large scripts & stylesheets, being able to download the script as soon as possible is very important for performance. If your website doesn’t load within 2 seconds, people will go to another website.

In an optimal solution, the browser would start downloading your scripts as soon as possible, while at the same time parsing the rest of your document.

The modern approach

Today, browsers support the async and defer attributes on scripts. These attributes tell the browser it’s safe to continue parsing while the scripts are being downloaded.


<script type="text/javascript" src="path/to/script1.js" async>
<script type="text/javascript" src="path/to/script2.js" async>

Scripts with the async attribute are executed asynchronously. This means the script is executed as soon as it’s downloaded, without blocking the browser in the meantime.
This implies that it’s possible to script 2 is downloaded & executed before script 1.

According to http://caniuse.com/#feat=script-async, 90% of all browsers support this.


<script type="text/javascript" src="path/to/script1.js" defer>
<script type="text/javascript" src="path/to/script2.js" defer>

Scripts with the defer attribute are executed in order (i.e. first script 1, then script 2). This also does not block the browser.

Unlike async scripts, defer scripts are only executed after the entire document has been loaded.

According to http://caniuse.com/#feat=script-defer, 90% of all browsers support this. 92% support it at least partially.

An important note on browser compatibility: in some circumstances IE <= 9 may execute deferred scripts out of order. If you need to support those browsers, please read this first!


The current state-of-the-art is to put scripts in the <head> tag and use the async or deferattributes. This allows your scripts to be downloaded asap without blocking your browser.

The good thing is that your website should still load correctly on the 20% of browsers that do not support these attributes while speeding up the other 80%.

P.S. See also Google’s explanation: https://developers.google.com/speed/docs/insights/BlockingJS



how to solve error “[$location:nobase] $location in HTML5 mode requires a tag to be present!”

[Origin]: https://stackoverflow.com/questions/40121747/how-to-solve-error-locationnobase-location-in-html5-mode-requires-a-base

I have no idea how to solve this case.

Error: [$location:nobase] $location in HTML5 mode requires a tag to be present!
http://errors.angularjs.org/1.5.7/$location/nobase at angular.js:68 at $LocationProvider.$get 
(angular.js:13384) at Object.invoke (angular.js:4709) at angular.js:4508 at getService 
(angular.js:4655) at injectionArgs (angular.js:4679) at Object.invoke (angular.js:4701) at 
angular.js:4508 at getService (angular.js:4655) at injectionArgs (angular.js:4679)

This happens when you have set html5mode, like so :

 enabled: true,
 requireBase: false

Just add a tag in your HTML template like so :

 <base href="/">

It’s exactly same thing mentioned in the docs here: https://docs.angularjs.org/error/$location/nobase


Tech tip: How to do hard refresh in Chrome, Firefox and IE?

[Origin]: https://www.getfilecloud.com/blog/2015/03/tech-tip-how-to-do-hard-refresh-in-browsers/#.WguIZkqnGUl

Browser cache are useful for web browsing , but a real pain point for developers.

Modern day browsers nowadays cache every front end resource like javascript or CSS style sheets. They primarily do this to increase the website performance. But this can be really irritating while one is in development mode and constantly modifying the javascript or css style sheets. The only way to see the changes is by doing a hard refresh or clear the cache of the browser.

hard refresh is a way of clearing the browser’s cache for a specific page, to force it to load the most recent version of a page. Sometimes, when changes are made to the website, they don’t register immediately due to caching. A hard refresh will usually fix this, though occasionally completely clearing the cache is necessary.

How to do hard refresh on various browsers?


Quick hard refresh can be done by using the following short cut keys


  1. Hold down Ctrl and click the Reload button.
  2. Or, Hold down Ctrl and press F5.
  3. just open the Chrome Dev Tools by pressing F12. Once the chrome dev tools are open, just right click on the refresh button and a menu will drop down. This menu gives you the option of doing a hard refresh, or even clearing the cache and do a hard refresh automatically.



  1. Hold ⇧ Shift and click the Reload button.
  2. Or, hold down ⌘ Cmd and ⇧ Shift key and then press R.


Mozilla Firefox and Related Browsers:


  1. Hold the Ctrl key and press the F5 key.
  2. Or, hold down Ctrl and ⇧ Shift and then press R.


  1. Hold down the ⇧ Shift and click the Reload button.
  2. Or, hold down ⌘ Cmd and ⇧ Shift and then press R.


Internet Explorer:

  1. Hold the Ctrl key and press the F5 key.
  2. Or, hold the Ctrl key and click the Refresh button.

How in Chrome can you easily kill an infinite loop?

[Origin]: https://www.codeschool.com/discuss/t/how-in-chrome-can-you-easily-kill-an-infinite-loop/17580

This happens to me constantly. I’m checking out some code–sometimes stuff I’ve written frowning — and I freeze Chrome because the code has an unexpected infinite loop.

If it’s not chewing up too many resources, you can

  1. open up the devtools,
  2. click pause, which usually works,
  3. stop the code by changing it appropriately in the browser.

But that’s way too hard and time-consuming. There’s gotta be a stop-button type of way to do this.

Any ideas on how to better, more easily do this?


Since Chrome uses individual tabs as processes, I just use Process Explorer (when I’m on Windows) to force end the browser tab with an infinite loop. It doesn’t close the browser and usually won’t affect any other tabs.

If you’d rather close the tab in native Chrome, you can use Shift+Esc to bring up the task manager (for Chrome) and end the tab there instead. I haven’t done this in a while, but it should still work.