Posts

Showing posts from January, 2016

Check if stored proc exists in DB?

I am trying to execute scripts of procedures in another database. The problem is this stored procedure exist or not in database. For handling this problem, I wrote following script  which checks if stored proc exists in database and if does then provide execute for user? Try this: IF EXISTS ( SELECT * FROM dbo . sysobjects WHERE id = object_id ( N '[dbo].[your_procedure_name]' ) and OBJECTPROPERTY ( id , N 'IsProcedure' ) = 1 ) BEGIN -- Set privileges here END Try this: if exists ( select 1 from sysobjects where id = object_id ( 'YourProc' ) and type = 'P' )

Rules for Constructing Variable Names

Rules for Constructing Variable Names A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 247 characters. Still, it would be safer to stick to the rule of 31 characters. Do not create unnecessarily long variable names as it adds to your typing effort. The first character in the variable name must be an alphabet or underscore . No commas or blanks are allowed within a variable name. No special symbol other than an underscore (as in gross_sal) can be used in a variable name. Ex.:  si_int m_hra pop_e_89 These rules remain same for all the types of primary and secondary variables. Naturally, the question follows... how is C able to differentiate between these variables? This is a rather simple matter. C compiler is able to distinguish between the variable names by making it compulsory for you to declare the type of any variable name that you wish to use in a program. This type ...

Types of C Variables

Types of C Variables As we saw earlier, an entity that may vary during program execution is called a variable . Variable names are names given to locations in memory . These locations can contain integer, real or character constants .  In any language, the types of variables that it can support depend on the types of constants that it can handle . This is because a particular type of variable can hold only the same type of  constant.  For example, an integer variable can hold only an integer constant, a real variable can hold only a real constant and a character variable can hold only a character constant. The rules for constructing different types of constants are different. However, for constructing variable names of all types the same set of rules apply. These rules are given below.

Rules for Constructing Character Constants

Rules for Constructing Character Constants A character constant is a single alphabet. A single digit or a single special symbol enclosed within single inverted commas .  Both the inverted commas should point to the left. For example:                      ’A’ is a valid character constant whereas ‘A’ is not. The maximum length of a character constant can be 1 character. Ex.:  'A' 'I' '5' '='

Rules for Constructing Real Constants

Rules for Constructing Real Constants Real constants are often called Floating Point constants. The real constants could be written in two forms—Fractional form and Exponential form.   The  Fractional form Following rules must be observed while constructing real constants expressed in fractional form: A real constant must have at least one digit. It must have a decimal point. It could be either positive or negative. Default sign is positive. No commas or blanks are allowed within a real constant. Ex.:   +325.34 426.0 -32.76 -48.5792 The exponential form of representation of real constants is usually used if the value of the constant is either too small or too large. It however doesn’t restrict us in any way from using exponential  form of representation for other real constants. In exponential form of representation, the real constant is represented in two parts. The part appearing before ‘e’ is called mantissa, whereas the part follow...

Rules for Constructing Integer Constants

Rules for Constructing Integer Constants An integer constant must have at least one digit . It must not have a decimal point . It can be either positive or negative . If no sign precedes an integer constant it is assumed to be positive. No commas or blanks are allowed within an integer constant . The allowable range for integer constants is -32768 to 32767 . Truly speaking the range of an Integer constant depends upon the compiler . For a 16-bit compiler like Turbo C or Turbo C++ the range is –32768 to 32767. For a 32-bit compiler the range would  be even greater. Question like what exactly do you mean by a 16-bit or a 32-bit compiler, what range of an Integer constant has to do with the type of compiler and such questions are discussed in detail in Chapter 16. Till that time it would be assumed that we are working with a 16-bit compiler.  Ex.:   426 +782 -8000 -7605

Delete specific values from column with where condition?

Image
Delete specific values from column with where condition? Here, I want to delete values/data from specific one column with the WHERE condition. I don't want to delete the complete row. It is possible like-- UPDATE TABLE SET columnName = null WHERE YourCondition OR The general form for this would be an  UPDATE  statement: UPDATE < table name > SET ColumnA = < NULL , or '' , or whatever else is suitable for the new value for the column > WHERE ColumnA = < bad value > /* or any other search conditions */ Example: In following table, I want delete Address of student which id is 2 . Here we write query for that as follows: UPDATE Student SET Address = NULL WHERE Id = 2; and Result is as follows:

Types of C Constants

Image
Types of C Constants C constants can be divided into two major categories: Primary Constants Secondary Constants These constants are further categorized as shown in Figure 1.4. At this stage we would restrict our discussion to only Primary Constants, namely, Integer, Real and Character constants. Let us see the details of each of these constants. For constructing these different types of constants certain rules have been laid down. These rules are as under: Rules for Constructing Integer Constants   Rules for Constructing Real Constants   Rules for Constructing Character Constants

Constants, Variables and Keywords

Image
Constants, Variables and Keywords The alphabets, numbers and special symbols when properly combined form constants, variables and keywords. Let us see what are ‘constants’ and ‘variables’ in C. A constant is an entity that doesn’t change whereas a variable is an entity that may change. In any program we typically do lots of calculations. The results of these calculations are stored in computers memory. Like human memory the computer memory also consists of millions of cells. The calculated values are stored in these memory cells. To make the retrieval and usage of these values easy these memory cells (also called memory locations) are given names. Since the value stored in each location may change the names given to these locations are called variable names. Consider the following example. Here 3 is stored in a memory location and a name x is given to it. Then we are assigning a new value 5 to the same memory location x . This would overwrite the earlier value 3, since ...

A developer's Life

Image

The C Character Set

Image
The C Character Set A character denotes any alphabet, digit or special symbol used to represent information. Figure 1.2 shows the valid alphabets, numbers and special symbols allowed in C.

Getting Started with C

Image
Getting Started with C There is a close analogy between learning English language and learning C language. The classical method of learning English is to first learn the alphabets used in the language, then learn to combine these alphabets to form words, which in turn are combined to form sentences and sentences are combined to form paragraphs. Learning C is similar and easier. Instead of straight-away learning how to write programs, we must first know what alphabets, numbers and special symbols are used in C, then how using them constants, variables and keywords are constructed , and finally how are these combined to form an instruction. A group of instructions would be combined later on to form a program. This is illustrated in the Figure 1.1.

What is C

B efore we can begin to write serious programs in C , Four important aspects of any language : ·          are the way it stores data, ·          the way it operates upon this data, ·          how it accomplishes input and output, ·          How it lets you control the sequence of execution of instructions in a program.  We would discuss the first three of these building blocks in this chapter. What is C C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie . In the late seventies C began to replace the more familiar languages of that time like PL/I, ALGOL, etc. No one pushed C. Possibly why C seems so popular is because it is reliable, simple and easy to use . An opinion that is often heard today...