Wednesday, July 18, 2018

With(NOLOCK) Advantages and Disadvantages

http://vinoth1989.blogspot.com/2012/07/withnolock-advantages-and-disadvantages.html

Usage of with(NOLOCK)

When data in a database is read or modified, the database engine uses special types of controls, called locks, to maintain integrity in the database. Locks basically work by making sure database records involved in a transaction cannot be modified by other transactions until the first transaction has committed, ensuring database consistency.
When designing database applications, you should keep in mind the different types of locks that will be issued, and the different levels of isolation your transactions will occur. Typically, the SQL Server defaults work fine for what you are trying to accomplish. However, there will be times when it is advantageous to manually make hints to how locks are issued on your tables in your SQL statements.
This article focuses on table : NOLOCK. I'll set up a table to use for our example queries. Execute the script in  to create the Orders table and populate the table with data.



IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'Orders')
DROP TABLE Orders
GO

CREATE TABLE Orders ( OrderId INT, ProductName VARCHAR (30), OrderDare DATE, PriceMONEY, )
GO
--Insert values to the table
INSERT INTO Orders VALUES (1,'Bag',GETDATE(),1500.00)
INSERT INTO Orders VALUES (1,'Book',GETDATE(),200.00)

GO

NOLOCK
This table hint, also known as READUNCOMMITTED, is applicable to SELECT statements only. NOLOCK indicates that no shared locks are issued against the table that would prohibit other transactions from modifying the data in the table.
The benefit of the statement is that it allows you to keep the database engine from issuing locks against the tables in your queries; this increases concurrency and performance. The downside is that, because the statement does not issue any locks against the tables being read, some "dirty," uncommitted data could potentially be read. A "dirty" read is one in which the data being read is involved in a transaction from another connection. If that transaction rolls back its work, the data read from the connection using NOLOCK will have read uncommitted data. This type of read makes processing inconsistent and can lead to problems. The trick is being able to know when you should use NOLOCK.
The following example shows how NOLOCK works and how dirty reads can occur. In the script below, I begin a transaction and insert a record in the SalesHistory table.
BEGIN TRANSACTION

INSERT INTO Orders
    (OrderId, ProductName (30), OrderDare, Price)
     VALUES
     (3,'Shoes',GETDATE(),2000.00)

         
   
               The transaction is still open, which means that the record that was inserted into the table still has locks issued against it. In a new query window, run the following script,
SELECT * FROM Orders
The above query is in Executiong stage only and resultwon’t display.
Since the table Orders is locked by the insert statement.
With  using  the NOLOCK table hint in returning the  records in the Orders table.
SELECT * FROM Orders WITH(NOLOCK)
The number of records returned is 3. Since the transaction that entered the record into theOrders table has not been committed, I can undo it. I'll roll back the transaction by issuing the following statement:
ROLLBACK TRANSACTION
This statement removes the record from the SalesHistory table that I previously inserted. Now I run the same SELECT statement that I ran earlier:
SELECT COUNT(*) FROM Orders WITH(NOLOCK)
This time the record count returned is 2. My first query read a record that was not yet committed -- this is a dirty read.

When to use  WITH (NOLOCK)

WITH (NOLOCK) is the equivalent of using READ UNCOMMITED as a transaction isolation level. So, you stand the risk of reading an uncommitted row that is subsequently rolled back, i.e. data never made it into the database. So, while it can prevent reads being deadlocked by other operations, it comes with a risk. In a banking application with high transaction rates, it's probably not going to be the right solution to whatever problem you're trying to solve with it IMHO.

Most banking applications can safely use nolock because they are transactional in the business sense. You only write new rows, you never update them
Most of the Real time scenario’s when we used to read the date we need to use theWITH(NOLOCK)

Wednesday, July 11, 2018

Useful tools

Geany

https://fr.wikipedia.org/wiki/Geany
 Geany est un éditeur de texte2 léger utilisant GTK+ et Scintilla et incluant les fonctions élémentaires d'un environnement de développement intégré. Pensé pour avoir peu de dépendances et démarrer rapidement, il est disponible pour plusieurs systèmes d'exploitation tel que Windows, Linux, Mac OS X3, BSD et Solaris. Il supporte, entre autres, les langages C/C++, Java, JavaScript, PHP, HTML, CSS, Python, Perl, Ruby, Pascal et Haskell.
Geany est plus puissant que SciTE tout en gardant la simplicité de celui-ci. Il n'atteint ni ne vise pour autant la sophistication d'Eclipse. Il peut remplacer sous Windows des éditeurs tels que NoteTab ou ConTEXT.
C'est un logiciel libre sous licence GNU GPL1.



---------------------------------------------------------------------------------------


Typora

https://zh.wikipedia.org/wiki/Typora

Typora是一款由Abner Lee开发的轻量级Markdown编辑器,适用于OS XWindowsLinux三种操作系统,是一款免费软件。与其他Markdown编辑器不同的是,Typora没有采用源代码和预览双栏显示的方式,而是采用所见即所得的编辑方式,实现了即时预览的功能,但也可切换至源代码编辑模式[1]在编辑时,除了通过传统的Markdown代码的方式来实现富文本之外,Typora支持通过菜单栏或者鼠标右键选取命令的方式来实现富文本,也支持通过快捷键的方式插入。Typora也支持通过以TeX的格式来插入行间公式和行内公式。在完成编辑后导出文件时,Typora支持以PDFHtml的形式导出,如果安装了Pandoc,也能够以WordRTFMediaWikiLaTeX等形式导出。[2]在定制方面,Typora提供有几种主题,并支持通过自定义CSS的方式进行个性化定制[3]