Friday, January 28, 2011

Difference Between Truncate and Delete

Truncate and Delete both are used for deletion of data.But there are so many difference in between both.

1)TRUNCATE is a DDL command and cannot be rolled back. All of the memory space is released back to the server. While DELETE is a DML command and can be rolled back. Memory not released to server. After delete memory used by table will be same as before. But in Sql Server 2005 you can roll back Truncate also by using Transaction and even Delete command can not be roll back without Transaction.

2)Where clause can not be used in truncate while in delete you can.

3)A DDL it actually sets the high water mark level of the table back to zero (depends on MINEXTENTS too) hence no one can read the table records.The commend get itself issues a commit as it is DDL command hence can not be rolled back

4) In case of TRUNCATE ,Trigger doesn't get fired.But in DML commands like DELETE .Trigger get fired. But in Sql Server 2005 you can write Trigger for DDL also.

5) Do not Check Constraints.While Delete check.

When there is foreign key constraint even though there
is no data in child table Truncate cannot be done. only
when the constraint is dropped truncate can be executed.

Whereas though we have foreign key constraints if the child
table is deleted, then parent table can be deleted.

6) TRUNCATE resets the Identity counter if there is any identity column present in the table where delete not resets the identity counter.

7) Delete and Truncate both are logged operation.But DELETE is a logged operation on a per row basis and TRUNCATE logs the deallocation of the data pages in which the data exists. That’s Truncate is faster than delete.

Drop is similar to truncate only one difference is in case of drop table structure deleted too.


Ex.Below Example is true only for Oracle in SQL Server delete reduces the number of rows also.

Delete
SQL> SELECT COUNT(*) FROM emp;

COUNT(*)
----------
14

SQL> DELETE FROM emp WHERE job = 'CLERK';

4 rows deleted.

SQL> COMMIT;

Commit complete.

SQL> SELECT COUNT(*) FROM emp;

COUNT(*)
----------
10

Truncate

SQL> TRUNCATE TABLE emp;

Table truncated.

SQL> SELECT COUNT(*) FROM emp;

COUNT(*)
----------
0

Drop
SQL> DROP TABLE emp;

Table dropped.

SQL> SELECT * FROM emp;
SELECT * FROM emp
*
ERROR at line 1:
ORA-00942: table or view does not exist

Friday, January 21, 2011

Difference Between Get and Post

get and post are HTTP methods that are used to send request to the server.Difference of them are listed below.

Get() transfer only 256 char. While there is no limit for post.

Get is not Secure information appear in browser, Post is secure.And information does not appear in the browser

As the data transfers through address bar (URL) there are some restrictions in using space, some characters like ampersand (&) etc in the GET method of posting data. We have to take special care for encoding data if such special characters are present. While in post there is no restriction.

If get method is used and if the page is refreshed it would not prompt before the request is submitted again. while in case of post it will prompt to user.

One can store the name value pairs as bookmark and directly be used while sharing with others - example search results.While in Post method bookmark can not be save.

It is a single call system While Post is a two call system.

Data transmission is faster in get while in post data transmission is slow.

In get data is always submitted in the form of text in get method. In Post data is submitted in the form as specified in encrypt attribute of form tag and thus files can be used in FileUpload input box.

If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.

In ASP .Net Response.Redirect use get method while using Server.Transfer use post method.

Friday, January 14, 2011

Http Methods

HTTP offers a number of methods that can be used to perform actions on the web server. These HTTP methods can be used for various purposes.
Http Methods are.

* HEAD
* GET
* POST
* PUT
* DELETE
* TRACE
* OPTIONS
* CONNECT

* GET :- The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.

* HEAD :- The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. This method is often used for testing hypertext links for validity, accessibility, and recent modification.

* POST :- The POST method is used to request that the origin server accepts the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:

* DELETE :- This method allows a client to delete a file on the web server.

* PUT :- This method allows a client to upload new files on the web server.

* CONNECT :- This method could allow a client to use the web server as a proxy.

* TRACE :- This method simply echoes back to the client whatever string has been sent to the server, and is used mainly for debugging purposes. This method, originally assumed harmless, can be used to mount an attack known as Cross Site Tracing, which has been discovered by Jeremiah Grossman.

* OPTIONS :- The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.

Responses to this method are not cacheable.

Some methods are really harmful for a web application, as they allow an attacker to modify the files stored on the web server and, in some scenarios, steal the credentials of legitimate users. More specifically, the methods that should be disabled are the following:

put,delete,connect


Friday, January 7, 2011

WebMethod Properties

WebMethod is an attribute that is used in Web Service to inform the CLR that particular method will expose as a part of Xml Webservice. WebMethod attribute has some properties which can be sued to control the behavior of the WebMethod.

BufferResponse :- By default it’s value is true. If it true, Response of webmethod serialized and stored in a buffer. When buffer is full or response completed than it sends the data to the client. Thus minimize communication between the worker process and IIS (Internet Information Services) process. If it is false, ASP.NET buffers the responses in chunks of 16 KB while communicating to the client.In case of large file make it false.
Ex:- Suppose we have requested 64 KB file from web service. If BufferResponse is true and Method generating 8 KB data in one go. Than Webserive will not send this 8 KB data to host but Buffer this 8 KB data until unless buffer is full or whole file is completed. And if BufferResponse is false than Webservice buffer this 8 KB data and wait for second call after the second call when data is 16 KB than it sends it to the host.

Cache Duration :- When we call a web method. Web Service cache the response of each unique set of parameter for a time span. This time span is set by Cache Duration property.By default value is zero which means no caching.

Description :- You specify what a web method will do. This will appear on the service help page.Default value is empty string.

Enable Session :- If you want to use Session in Web Service you have to set this property as true. By default value is false. You can use session in web service through HttpContext.Current.Session or with the WebService.Session property if it inherits from the WebService base class.

MessageName :- If you want to overload a WebMethod than you can use this property to uniquely identified a WebMethod. By default value is method name.

Followers

Link