Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - Wednesday, July 15, 2009
Blog
 
# Wednesday, July 15, 2009

• The sp_recompile system stored procedure forces a recompile of a stored procedure the next time it is run.

• Creating a stored procedure that specifies the WITH RECOMPILE option in its definition indicates that SQL Server does not cache a plan for this stored procedure; the stored procedure is recompiled each time it is executed. Use the WITH RECOMPILE option when stored procedures take parameters whose values differ widely between executions of the stored procedure, resulting in different execution plans to be created each time. Use of this option is uncommon, and causes the stored procedure to execute more slowly because the stored procedure must be recompiled each time it is executed.

• You can force the stored procedure to be recompiled by specifying the WITH RECOMPILE option when you execute the stored procedure. Use this option only if the parameter you are supplying is atypical or if the data has significantly changed since the stored procedure was created.

Wednesday, July 15, 2009 2:04:06 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question SQL  | 

You can use the sp_procoption system stored procedure in master database to mark the stored procedure to automatic execution when the SQL Server will start.

Wednesday, July 15, 2009 2:03:04 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question SQL  | 

There are four different type of stored procedure given below:

1. Temporary Stored Procedures - SQL Server supports two types of temporary procedures: local and global. A local temporary procedure is visible only to the connection that created it. A global temporary procedure is available to all connections. Local temporary procedures are automatically dropped at the end of the current session. Global temporary procedures are dropped at the end of the last session using the procedure. Usually, this is when the session that created the procedure ends. Temporary procedures named with # and ## can be created by any user.

2. System stored procedures are created and stored in the master database and have the sp_ prefix.(or xp_) System stored procedures can be executed from any database without having to qualify the stored procedure name fully using the database name master. (If any user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed.)

3. Automatically Executing Stored Procedures - One or more stored procedures can execute automatically when SQL Server starts. The stored procedures must be created by the system administrator and executed under the sysadmin fixed server role as a background process. The procedure(s) cannot have any input parameters.

4. User defined stored procedure - These stored procedure is created by user.

Wednesday, July 15, 2009 2:02:16 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question SQL  | 
# Monday, July 13, 2009

Microsoft® SQL Server™ 2000 uses locking to ensure transactional integrity and database consistency. Locking prevents users from reading data being changed by other users, and prevents multiple users from changing the same data at the same time. If locking is not used, data within the database may become logically incorrect, and queries executed against that data may produce unexpected results.
Lock mode Description. There are six different type of locks given below:

Shared (S) Used for operations that do not change or update data (read-only operations), such as a SELECT statement.
Update (U) Used on resources that can be updated. Prevents a common form of deadlock that occurs when multiple sessions are reading, locking, and potentially updating resources later.
Exclusive (X) Used for data-modification operations, such as INSERT, UPDATE, or DELETE. Ensures that multiple updates cannot be made to the same resource at the same time.
Intent Used to establish a lock hierarchy. The types of intent locks are: intent shared (IS), intent exclusive (IX), and shared with intent exclusive (SIX).
Schema Used when an operation dependent on the schema of a table is executing. The types of schema locks are: schema modification (Sch-M) and schema stability (Sch-S).
Bulk Update (BU) Used when bulk-copying data into a table and the TABLOCK hint is specified.

Monday, July 13, 2009 2:06:07 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question SQL  | 

Views can have only select statements (create, update, truncate, delete statements are not allowed) Views cannot have "select into", "Group by" "Having", "Order by"

Monday, July 13, 2009 2:04:56 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question SQL  | 
# Thursday, July 09, 2009
SELECT MIN(Salary) AS Expr1 FROM tblEmployee 
WHERE (empid IN (SELECT DISTINCT TOP 5 empid FROM tblSalary ORDER BY Salary))  
Thursday, July 09, 2009 7:27:51 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question SQL  | 

ASP.NET provides the following additional benefits:

Simplified development: ASP.NET offers a very rich object model that developers can use to reduce the amount of code they need to write.

Language independence: ASP pages must be written with scripting. In other words, ASP pages must be written in a language that is interpreted rather than compiled. ASP.NET allows compiled languages to be used, providing better performance and cross-language compatibility.

Simplified deployment: With .NET components, deployment is as easy as copying a component assembly to its desired location.

Cross-client capability: One of the foremost problems facing developers today is writing code that can be rendered correctly on multiple client types. For example, writing one script that will render correctly in Internet Explorer 5.5 and Netscape Navigator 4.7, and on a PDA and a mobile phone is very difficult, if not impossible, and time consuming. ASP.NET provides rich server-side components that can automatically produce output specifically targeted at each type of client.

Web services: ASP.NET provides features that allow ASP.NET developers to effortlessly create Web services that can be consumed by any client that understands HTTP and XML, the de facto language for inter-device communication.

Performance: ASP.NET pages are compiled whereas ASP pages are interpreted. When an ASP.NET page is first requested, it is compiled and cached, or saved in memory, by the .NET Common Language Runtime (CLR). This cached copy can then be re-used for each subsequent request for the page. Performance is thereby improved because after the first request, the code can run from a much faster compiled version.

Thursday, July 09, 2009 7:19:56 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question ASP.NET  | 


1. Use views and stored procedures instead of heavy-duty queries.
This can reduce network traffic, because your client will send to server only stored procedure or view name (perhaps with some parameters) instead of large heavy-duty queries text. This can be used to facilitate permission management also, because you can restrict user access to table columns they should not see.

2. Try to use constraints instead of triggers, whenever possible.
Constraints are much more efficient than triggers and can boost performance. So, you should use constraints instead of triggers, whenever possible.

3. Use table variables instead of temporary tables.
Table variables require less locking and logging resources than temporary tables, so table variables should be used whenever possible. The table variables are available in SQL Server 2000 only.

4. Try to use UNION ALL statement instead of UNION, whenever possible.
The UNION ALL statement is much faster than UNION, because UNION ALL statement does not look for duplicate rows, and UNION statement does look for duplicate rows, whether or not they exist.

5. Try to avoid using the DISTINCT clause, whenever possible.
Because using the DISTINCT clause will result in some performance degradation, you should use this clause only when it is necessary.

6. Try to avoid using SQL Server cursors, whenever possible.
SQL Server cursors can result in some performance degradation in comparison with select statements. Try to use correlated sub-query or derived tables, if you need to perform row-by-row operations.

7. Try to avoid the HAVING clause, whenever possible.
The HAVING clause is used to restrict the result set returned by the GROUP BY clause. When you use GROUP BY with the HAVING clause, the GROUP BY clause divides the rows into sets of grouped rows and aggregates their values, and then the HAVING clause eliminates undesired aggregated groups. In many cases, you can write your select statement so, that it will contain only WHERE and GROUP BY clauses without HAVING clause. This can improve the performance of your query.

8. If you need to return the total table's row count, you can use alternative way instead of SELECT COUNT(*) statement.
Because SELECT COUNT(*) statement make a full table scan to return the total table's row count, it can take very many time for the large table. There is another way to determine the total row count in a table. You can use sysindexes system table, in this case. There is ROWS column in the sysindexes table. This column contains the total row count for each table in your database. So, you can use the following select statement instead of SELECT COUNT(*): SELECT rows FROM sysindexes WHERE id = OBJECT_ID('table_name') AND indid < 2 So, you can improve the speed of such queries in several times.

9. Include SET NOCOUNT ON statement into your stored procedures to stop the message indicating the number of rows affected by a T-SQL statement.
This can reduce network traffic, because your client will not receive the message indicating the number of rows affected by a T-SQL statement.

10. Try to restrict the queries result set by using the WHERE clause.
This can results in good performance benefits, because SQL Server will return to client only particular rows, not all rows from the table(s). This can reduce network traffic and boost the overall performance of the query.

11. Use the select statements with TOP keyword or the SET ROWCOUNT statement, if you need to return only the first n rows.
This can improve performance of your queries, because the smaller result set will be returned. This can also reduce the traffic between the server and the clients.

12. Try to restrict the queries result set by returning only the particular columns from the table, not all table's columns.
This can results in good performance benefits, because SQL Server will return to client only particular columns, not all table's columns. This can reduce network traffic and boost the overall performance of the query. 
  
Index Optimization Tips.

• Every index increases the time in takes to perform INSERTS, UPDATES and DELETES, so the number of indexes should not be very much. Try to use maximum 4-5 indexes on one table, not more. If you have read-only table, then the number of indexes may be increased.

• Keep your indexes as narrow as possible. This reduces the size of the index and reduces the number of reads required to read the index.

• Try to create indexes on columns that have integer values rather than character values.

• If you create a composite (multi-column) index, the order of the columns in the key are very important. Try to order the columns in the key as to enhance selectivity, with the most selective columns to the leftmost of the key.

• If you want to join several tables, try to create surrogate integer keys for this purpose and create indexes on their columns.

• Create surrogate integer primary key (identity for example) if your table will not have many insert operations.

• Clustered indexes are more preferable than nonclustered, if you need to select by a range of values or you need to sort results set with GROUP BY or ORDER BY.
 

Thursday, July 09, 2009 7:17:55 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   SQL Server  | 
# Wednesday, July 08, 2009

A stored procedure is a set of Structured Query Language (SQL) statements that you assign a name to and store in a database in compiled form so that you can share it between a number of programs.
• They allow modular programming.
• They allow faster execution.
• They can reduce network traffic.
• They can be used as a security mechanism.

Wednesday, July 08, 2009 7:53:35 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question SQL  | 

Yes, Let us consider there is employ Table ( empid, empName, empManagerid). In this table manager is also be an employ.

Wednesday, July 08, 2009 7:52:09 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]   Interview Question SQL  | 
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: