Saturday, July 20, 2013

SQL Server Solve Error: Database diagram support objects cannot be installed because this database does not have a valid owner

Hello friend, In this post i would like share solution of one small problem, which occurs many times in SQL Server.

When we restore Database to any other server and try to create database diagram then it does not allow to create database diagram and its give error

Error:

Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects

Solution is very small. just execute below query:

Replace MYDB with your DB name then execute the query

ALTER AUTHORIZATION ON DATABASE::MYDB TO sa

After executing above query we can create DB diagram

Thursday, July 18, 2013

C Programming Questions and Answers, C Interview Questions, GATE previous year Questions in C Programming

Hello friend, In this post I am going to create a huge collection of all types of Questions with Answers. Wherever I will find any question that is important for GATE or any interview, I will post it here

For programming in C/ C++, you can use Dev C++ IDE, it is free IDE for C and C++ developer, Link to download


Q. What is the difference between the declaration and definition of a variable?

Ans: The definition is the one that actually allocate space, and provides an initialization value, if any. There can be many declaration, but there must be exactly one definition

Q. What is the difference between a statement and a block?

Ans: A statement is single C expression terminated with a semicolon. A block is a series of statements, the group of which is inclosed in curly braces.

Q. How to add two numbers without using arithmetic operators?

OR

Q. Write a function that returns sum of two integers. The function should not use any of the arithmetic operators (+, ++, -, --, .. etc).

Ans: We can not use arithmetic operator but we can use C Bitwise Operators, below is the function that will add two number without using arithmetic operators

int AddNumbers(int x, int y)
{
    if (y == 0)
        return x;
    else
        return AddNumbers( x ^ y, (x & y) << 1);
}

Q. How many squares does a chess-board contain?

Ans: Total number of squares = 8²+7²+...+1² = 204
This concept can be generalized to calculate number of squares in any N*N matrix
1² + 2² + 3² + ....n² = n(n+1)(2n+1)/6

Q. How many rectangles does a chess-board contain?

Ans: Total = [n(n+1)/2]^2
Here n is 8

Wednesday, July 17, 2013

Programming and Data Structure

In this post, I am going to cover all the topics related to GATE and other technical interviews which comes under programming in C and Data Structure.
C is the most basic fundamental language that every CS/IT engineer should know. Also I would say everyone should know at least one computer programming language to understand this fastest growing digital world. Currently we are using many highly technical gadgets those are very user friendly, but one should know after how much effort that product is available to use by a totally non-technical person.
In this post I am going to cover most fundamental concepts of computer science those every Software Engineer should know.

Followings are the important topics related to Programming and Data Structure:

  1. What is C Programming Language
  2. Scope
  3. Binding
  4. Abstract Data Types
  5. Array
  6. Pointer
  7. Stack
  8. Queues
  9. Functions
  10. Recursion
  11. Parameter Passing
  12. Link List
  13. Trees
  14. Binary Search Tree
  15. Binary Heap

What is C Programming Language

C is a programming language developed in 1972 by Dennis Ritchie in Bell Lab. C is reliable, simple, and easy to use. If you know C then you can quickly learn any programming language. No one can directly learn C++ or JAVA, so C is the first step for programming learner. Like a child can not start talking directly without learning words. So in simple language C is the letters and words and Grammar of programming languages.

We can compare C language with any spoken language for example:English

In English language we have:

Alphabets                                   --> Words                                    --> Sentences   -->   Paragraph

Similarly in C language we have

Alphabets, Digits, Special Symbol --> Constants, Variables, Keywords --> Instructions --> Programs

Alphabets similar to English language, digits (0-9), special symbols like (~,!,@,#,$,%,^,&, etc.)

Constants are of two types: Primary constants and Secondary constants

Primary constants are followings:

  • Integer Constants
  • Real Constants (Fractional, exponential)
  • Characters Constants

Secondary constants are followings:

  • Array
  • Pointer
  • Structure
  • Union
  • Enum

Scope

The scope is the context within the program in which an identifier/ variable is valid and can be resolved to find the entity associated to the identifier. A scope in any programming is a region of the program where a defined variable can have its existence and beyond that variable can not be accessed. There are three places where variables can be declared in C programming language.

  1. Inside a function or a block which is called local variables
  2. Outside of all functions which is called global variables
  3. In the definition of function parameters which is called parameters

Local Variables

Local variables are the variables declared inside a function or any block. They can be used only by statements that are inside that function or block of code. They can not be used outside that function or block in which they have been declared. For example in below code var1, var2, var3 are local variables

#include <stdio.h>  
#include <conio.h>
/* declaration of global variable*/
int global_var;

int main(){
    
     /* declaration of local variables  */
    int var1;
    int var2;
    int var3;
    
    /* initialization of local variables */
    var1 = 10;
    var2 = 20;
    var3 = var1 + var2;
    global_var = var3 + 1;
    printf ("Value of var1 = %d, var2 = %d and var3 = %d\n", var1, var2, var3);
    printf ("Global variable global_var = %d\n", global_var);
    system("pause");
    return 0;
}

Global Variables

Global variables are defined outside of a function, usually on top of the program. The global variables will hold their value throughout the lifetime of your program and they can be accessed inside any of the functions defined for the program.

A global variable can be accessed by any function. That is, a global variable is available for use throughout your entire program after its declaration. In above example global_var is a global variable declared on top that can be used in any function.

Function

Function ........