Skip to main content

Posts

Showing posts from February, 2010

string.IsNullOrWhiteSpace()

.NET 4 adds new method called string.IsNullOrWhiteSpace() which checks for spaces, empty or null. This is a nice time-saver for developers.. This static method returns true if a string is full of whitespace characters. Let us consider the below example . static void Main() { string strTest = "Simple Talk"; string strNull = null; string strEmpty = string.Empty; string strWhiteSpace = "\t\r\n\n "; Console.WriteLine("Is null or whitespace Exmaple!!"); Console.WriteLine("TestSting: " + string.IsNullOrWhiteSpace(strTest));//false Console.WriteLine("NullString: " + string.IsNullOrWhiteSpace(strNull)); //true Console.WriteLine("EmptyString: " + string.IsNullOrWhiteSpace(strEmpty)); //true Console.WriteLine("WhiteSpaceString: " + string.IsNullOrWhiteSpace(strWhiteSpace)); //true Console.ReadLine(); }

Stored Procedures vs. User Defined Functions in Microsoft SQL Server

                 SQL Server user-defined functions and stored procedures offer similar functionality. Both allow you to create bundles of SQL statements that are stored on the server for future use. This offers you a tremendous efficiency benefit, as you can save programming time by: Reusing code from one program to another, cutting down on program development time. Hiding the SQL details, allowing database developers to worry about SQL and application developers to deal only in higher-level languages Centralize maintenance, allowing you to make business logic changes in a single place that automatically affect all dependent applications           At first glance, functions and stored procedures seem identical. However, there are several subtle, yet important differences between the two: Stored procedures are called independently, using the EXEC command, while functions are called from within another SQL sta...

Benefits of SQL Server Stored Procedures

Microsoft SQL Server provides the stored procedure mechanism to simplify the database development process by grouping Transact-SQL statements into manageable blocks. Benefits of Stored Procedures Why should we use stored procedures? Let's take a look at the key benefits of this technology: Precompiled execution . SQL Server compiles each stored procedure once and then reutilizes the execution plan. This results in tremendous performance boosts when stored procedures are called repeatedly. Reduced client/server traffic . If network bandwidth is a concern in your environment, you'll be happy to learn that stored procedures can reduce long SQL queries to a single line that is transmitted over the wire. Efficient reuse of code and programming abstraction . Stored procedures can be used by multiple users and client programs. If you utilize them in a planned manner, you'll find the development cycle takes less time. Enhanced security controls . You can grant users permissi...

List all Constraints in Sql Server

Hi All,           Yesterday, I was facing a problem. Actually I was to rename all the constraints as our Standards. When I create tables in query analyzer, Sql Server create Constraints name itself. Now, I have to change all constraints according to naming conventions. This is the below script by which I get all the constraints in my database. SELECT OBJECT_NAME(OBJECT_ID) AS ConstraintName, SCHEMA_NAME(schema_id) AS SchemaName,  OBJECT_NAME(parent_object_id) AS TableName, type_desc AS ConstraintType FROM sys.objects WHERE type_desc LIKE '%CONSTRAINT' Above script list all constraints. But If I want to see only Primary keys or Foreign Keys or default constraints the I will use the where clause like this: SELECT OBJECT_NAME(OBJECT_ID) AS ConstraintName, SCHEMA_NAME(schema_id) AS SchemaName, OBJECT_NAME(parent_object_id) AS TableName, type_desc AS ConstraintType FROM sys.objects WHERE type_desc = 'PRIMARY_KEY_CONSTRAINT'; SELECT OBJECT...