Sample 1:
~~~~~~
Declare @temp table
(
row_id int identity (1,1),
product varchar(50)
)
Declare @i int, @max int
Insert into #temp (product) Select product From products
set @max = @@rowcount
set @i = 1
While @i <= @max Begin Select product From #temp Where row_id = @i // Do your Processing here set @i = @i + 1 End Sample 2:
~~~~~~
DECLARE @Product VARCHAR(50)
DECLARE @ProductID INT -- I assume Product ID as primary Key
SELECT * INTO #Products FROM Products
WHILE EXISTS (SELECT * FROM #Products)
BEGIN
SET ROWCOUNT 1
SELECT @ProductID = ProductID, @Product = Product FROM #Products
SET ROWCOUNT 0
// Do your Processing here
DELETE #Products WHERE ProductID = @ProductID
END
Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts
Technical Aspects
Exceptions add significant overhead to your application. Do not use exceptions to control logic flow, and design your code to avoid exceptions where possible. For example, validate user input, and check for known conditions that can cause exceptions. Also, design your code to fail early to avoid unnecessary processing.
Exceptions are expensive considering the performance. So it is better to use conditional checks rather using exceptions.
The @@scope_identity() is used to get the identity value of the last update. As the trigger is not in the scope of a stored procedure, hence the last update identity value for trigger can be achieved by using @@identity()
N'123' - Here "N" denotes a unicode string or nvarchar string. This is used when the argument required is of unicode format.
Resource files ".resx" are compiled to ".resources" using "resgen" utility.
DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.
The ASP.NET State Server is a Windows service that runs on any machine where Framework is installed.
An assembly with culture information is automatically assumed to be a satellite assembly.
Struct is similar to Class, but Struct imposes less overhead. Hence Class is intended to represent complex datatypes.
Value types impose less overhead than reference types because they’re allocated on the stack, not the heap.
CLR uses heap that's called managed heap.
Hashtables implements Idictionary and hence cannot be XMLSerialized, but they can be BinarySerialized.
Joins are faster than Sub-queries.
Clustured index is automatically applied when primary key is assigned to a table.
Clustured index information is stored in the table itself, whereas non-Clustured information is stored outside the table.
Insert can be slower on clustured indexes. When a row is to be inserted between two rows, then first the rows are to be adjusted such that the new row can be accomodated between the two rows. Whereas in clustured index, the index information is stored apart from table and hence the row can be added at the end of table and index information is stored in place other than table.
Clustured index is used when large amount or rows are returned especially using comparison operators.
Non-clustured index is used when minimum rows (1 row) is to be returned.
Clustured index can be applied on composite key.
If clustured index is increased from 3 or 4 index on a table, then it will degrade the performance.
Clustured index on table increases the performance.
There can be only one clustured index on one table whereas there can be multiple non-clustured index on one table.
Overloading means having two methods with same name but different signature.
Overriding means having two methods with same name and signature but one in base class and other in derived class.
Boxing is conversion of value type (integer, string, …) to reference type (object). And Unboxing is vise-versa.
Overloading and Overriding are types of Polymorphism.
Application_BeginRequest is called on arrival of each request whereas Application_Start is called when the first request is arrived for the application.
One assembly can have one or more namespaces. Also, one namespace can span across multiple assemblies. You can create nested namespaces. If you are using VS.NET then the project name acts as the default namespace name.
The main difference between inheritance based programming and interfaces based programming is that - interfaces just specify signatures of properties and methods for a class. Your class "implements" the interface by providing implementation for various properties and methods. Unlike inheritance there is no "code" inherited from interfaces. Your class can implement one or more interfaces.
Exceptions are unpredictable errors during runtime whereas Errors are predictable.
Metadata is the complete way of describing what is in a .NET assembly. Digging into the metadata yields the types available in that assembly, viz. classes, interfaces, enums, structs, etc., and their containing namespaces, the name of each type, its visibility/scope, its base class, the interfaces it implemented, its methods and their scope, and each method’s parameters, type’s properties, and so on.
InstallUtil.exe is a .NET utility to install Windows Service.
Exceptions are expensive considering the performance. So it is better to use conditional checks rather using exceptions.
The @@scope_identity() is used to get the identity value of the last update. As the trigger is not in the scope of a stored procedure, hence the last update identity value for trigger can be achieved by using @@identity()
N'123' - Here "N" denotes a unicode string or nvarchar string. This is used when the argument required is of unicode format.
Resource files ".resx" are compiled to ".resources" using "resgen" utility.
DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.
The ASP.NET State Server is a Windows service that runs on any machine where Framework is installed.
An assembly with culture information is automatically assumed to be a satellite assembly.
Struct is similar to Class, but Struct imposes less overhead. Hence Class is intended to represent complex datatypes.
Value types impose less overhead than reference types because they’re allocated on the stack, not the heap.
CLR uses heap that's called managed heap.
Hashtables implements Idictionary and hence cannot be XMLSerialized, but they can be BinarySerialized.
Joins are faster than Sub-queries.
Clustured index is automatically applied when primary key is assigned to a table.
Clustured index information is stored in the table itself, whereas non-Clustured information is stored outside the table.
Insert can be slower on clustured indexes. When a row is to be inserted between two rows, then first the rows are to be adjusted such that the new row can be accomodated between the two rows. Whereas in clustured index, the index information is stored apart from table and hence the row can be added at the end of table and index information is stored in place other than table.
Clustured index is used when large amount or rows are returned especially using comparison operators.
Non-clustured index is used when minimum rows (1 row) is to be returned.
Clustured index can be applied on composite key.
If clustured index is increased from 3 or 4 index on a table, then it will degrade the performance.
Clustured index on table increases the performance.
There can be only one clustured index on one table whereas there can be multiple non-clustured index on one table.
Overloading means having two methods with same name but different signature.
Overriding means having two methods with same name and signature but one in base class and other in derived class.
Boxing is conversion of value type (integer, string, …) to reference type (object). And Unboxing is vise-versa.
Overloading and Overriding are types of Polymorphism.
Application_BeginRequest is called on arrival of each request whereas Application_Start is called when the first request is arrived for the application.
One assembly can have one or more namespaces. Also, one namespace can span across multiple assemblies. You can create nested namespaces. If you are using VS.NET then the project name acts as the default namespace name.
The main difference between inheritance based programming and interfaces based programming is that - interfaces just specify signatures of properties and methods for a class. Your class "implements" the interface by providing implementation for various properties and methods. Unlike inheritance there is no "code" inherited from interfaces. Your class can implement one or more interfaces.
Exceptions are unpredictable errors during runtime whereas Errors are predictable.
Metadata is the complete way of describing what is in a .NET assembly. Digging into the metadata yields the types available in that assembly, viz. classes, interfaces, enums, structs, etc., and their containing namespaces, the name of each type, its visibility/scope, its base class, the interfaces it implemented, its methods and their scope, and each method’s parameters, type’s properties, and so on.
Subscribe to:
Posts (Atom)