Wednesday, 4 January 2012

Top SQL Interview Question and Answers




1.   What are two methods of retrieving SQL?
2.   What cursor type do you use to retrieve multiple recordsets?

3.   What is the difference between a "where" clause and a "having" clause?
"Where" is a kind of restiriction statement. You use where clause to restrict all the data from DB.Where clause is using before result retrieving. But Having clause is using after retrieving the data.Having clause is a kind of filtering command.

4.   What is the basic form of a SQL statement to read data out of a table?
The basic form to read data out of table is ‘SELECT * FROM table_name; ‘ An answer: ‘SELECT * FROM table_name WHERE xyz= ‘whatever’;’ cannot be called basic form because of WHERE clause.

5.   What structure can you implement for the database to speed up table reads?
Follow the rules of DB tuning we have to: 1] properly use indexes ( different types of indexes) 2] properly locate different DB objects across different tablespaces, files and so on.3] create a special space (tablespace) to locate some of the data with special datatype ( for example CLOB, LOB and …)

6.   What are the tradeoffs with having indexes?
1. Faster selects, slower updates. 2. Extra storage space to store indexes. Updates are slower because in addition to updating the table you have to update the index.

7.   What is a "join"?
‘join’ used to connect two or more tables logically with or without common field.

8.   What is "normalization"? "Denormalization"? Why do you sometimes want to denormalize?
Normalizing data means eliminating redundant information from a table and organizing the data so that future changes to the table are easier. Denormalization means allowing redundancy in a table. The main benefit of denormalization is improved performance with simplified data retrieval and manipulation. This is done by reduction in the number of joins needed for data processing.

9.   What is a "constraint"?
 A constraint allows you to apply simple referential integrity checks to a table. There are four primary types of constraints that are currently supported by SQL Server: PRIMARY/UNIQUE - enforces uniqueness of a particular table column. DEFAULT - specifies a default value for a column in case an insert operation does not provide one. FOREIGN KEY - validates that every value in a column exists in a column of another table. CHECK - checks that every value stored in a column is in some specified list. Each type of constraint performs a specific type of action. Default is not a constraint. NOT NULL is one more constraint which does not allow values in the specific column to be null. And also it the only constraint which is not a table level constraint.

10.       What types of index data structures can you have?
 An index helps to faster search values in tables. The three most commonly used index-types are: - B-Tree: builds a tree of possible values with a list of row IDs that have the leaf value. Needs a lot of space and is the default index type for most databases. - Bitmap: string of bits for each possible value of the column. Each bit string has one bit for each row. Needs only few space and is very fast.(however, domain of value cannot be large, e.g. SEX(m,f); degree(BS,MS,PHD) - Hash: A hashing algorithm is used to assign a set of characters to represent a text string such as a composite of keys or partial keys, and compresses the underlying data. Takes longer to build and is supported by relatively few databases.

11.       What is a "primary key"?
 A PRIMARY INDEX or PRIMARY KEY is something which comes mainly from database theory. From its behavior is almost the same as an UNIQUE INDEX, i.e. there may only be one of each value in this column. If you call such an INDEX PRIMARY instead of UNIQUE, you say something about

your table design, which I am not able to explain in few words. Primary Key is a type of a constraint enforcing uniqueness and data integrity for each row of a table. All columns participating in a primary key constraint must possess the NOT NULL property.

12.       What is a "functional dependency"?
   How does it relate to database table design? - Functional dependency relates to how one object depends upon the other in the database. for example, procedure/function sp2 may be called by procedure sp1. Then we say that sp1 has functional dependency on sp2.

13.       What is a "trigger"?
   Triggers are stored procedures created in order to enforce integrity rules in a database. A trigger is executed every time a data-modification operation occurs (i.e., insert, update or delete). Triggers are executed automatically on occurance of one of the data-modification operations. A trigger is a database object directly associated with a particular table. It fires whenever a specific statement/type of statement is issued against that table. The types of statements are insert,update,delete and query statements. Basically, trigger is a set of SQL statements A trigger is a solution to the restrictions of a constraint. For instance:
   1.A database column cannot carry PSEUDO columns as criteria where a trigger can.
   2. A database constraint cannot refer old and new values for a row where a trigger can.

14. Why can a "group by" or "order by" clause be expensive to process?
   Processing of "group by" or "order by" clause often requires creation of Temporary tables to process the results of the query. Which depending of the result set can be very expensive.

15.       What is "index covering" of a query?
  Index covering means that "Data can be found only using indexes, without touching the tables"

16.       What types of join algorithms can you have?

17.       What is a SQL view?
 An output of a query can be stored as a view. View acts like small table which meets our criterion. View is a precomplied SQL query which is used to select data from one or more tables. A view is like a table but it doesn’t physically take any space. View is a good way to present data in a particular format if you use that query quite often. View can also be used to restrict users from accessing the tables directly. 

[+/-] Read More...

Top 55 Php Interview Questions


PHP (hyper text Preprocessor) is a computer scripting language. Designed for producing dynamic web pages, with syntax from C, Java and Perl, PHP code is embedded within HTML pages for server side execution it has evolved to include a command line interface capability and can be used in standalone graphical applications. PHP was originally created by Rasmus Lerdorf in 1995; the main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification. Released under the PHP License, the Free Software Foundation considers it to be free software. PHP is a widely used general-purpose scripting language that is especially suited for web development, taking PHP code as its input and creating web pages as output.
It can be deployed on most web servers and on almost every operating system and platform free of charge. From this you can create more complex loops and functions to make your page generate more specialized data. PHP is installed on more than 25 million websites and 1 million web servers.

  1. What is PHP?
  2. What is a Session?
  3. What is meant by PEAR in php?
  4. How can we know the number of days between two given dates using PHP?
  5. What is the difference between $message and $$message?
  6. What does a special set of tags do in PHP?
  7. What is a Persistent Cookie?
  8. How can we repair a MySQL table?
  9. What are the differences between require and include, include_once?
  10. What is meant by urlencode and urldecode?
  11. How do you define a constant?
  12. What is the difference between mysql_fetch_object and mysql_fetch_array?
  13. How To Get the Uploaded File Information in the Receiving Script?
  14. How can i execute a PHP script using command line?
  15. Would i use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example?
  16. How To Create a Table?
  17. How can we encrypt the username and password using PHP?
  18. What is the functionality of the functions STRSTR() and STRISTR()?
  19. How To Protect Special Characters in Query String?
  20. What are the differences between DROP a table and TRUNCATE a table?
  21. WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?
  22. What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods?
  23. What is the difference between the functions unlink and unset?
  24. How can we register the variables into a session?
  25. How can we create a database using PHP and mysql?
  26. How many ways we can retrieve the date in result set of mysql using php?
  27. What is the difference between htmlentities() and htmlspecialchars()?
  28. So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?
  29. How can we destroy the session, how can we unset the variable of a session?
  30. How many values can the SET function of MySQL take?
  31. How many ways we can we find the current date using MySQL?
  32. What is meant by MIME?
  33. How can we know that a session is started or not?
  34. What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?
  35. What is the difference between PHP4 and PHP5?
  36. How to retrieve values from one database server and store them in other database server using PHP?
  37. What are the functions for IMAP?
  38. How can we increase the execution time of a php script?
  39. How to set cookies?
  40. How to reset/destroy a cookie?
  41. What are the current versions of Apache, PHP, and MySQL?
  42. What are the features and advantages of OBJECT ORIENTED PROGRAMMING?
  43. What are the reasons for selecting LAMP (Linux, Apache, MySQL, Php) instead of combination of other software programs, servers and operating systems?
  44. What is the use of friend function?
  45. What are the difference between abstract class and interface?
  46. What are the advantages of stored procedures, triggers, indexes?
  47. What is maximum size of a database in mysql?
  48. What type of inheritance that php supports?
  49. How to increase the performance of MySQL select query?
  50. How to use the COM components in php?
  51. How to set a cron and how can I execute it in Unix, Linux, and windows?
  52. How many ways I can redirect a PHP page?
  53. How to store the uploaded file to the final location?
  54. Explain about Type Juggling in php?
  55. How can I embed a java programme in php file and what changes have to be done in php.ini file?

[+/-] Read More...

Some of frequently asked php interview question by interviewer


Here is the some of frequently asked php interview question by interviewer
1 What does a special set of tags <?= and ?> do in PHP? – The output is displayed directly to the browser.
2  What’s the difference between include and require? – It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
3  I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem? – PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.
4   Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars in this example? – In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like "{$a},000,000 mln dollars", then you definitely need to use the braces.
5   How do you define a constant? – Via define() directive, like define ("MYCONSTANT", 100);
6   How do you pass a variable by value? – Just like in C++, put an ampersand in front of it, like $a = &$b
7   Will comparison of string "10" and integer 11 work in PHP? - Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.
8   When are you supposed to use endif to end the conditional statement? – When the original if was followed by : and then the code block without braces.
9   Explain the ternary conditional operator in PHP? – Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.
10  How do I find out the number of parameters passed into function? – func_num_args() function returns the number of parameters passed in.
11   If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b? – 100, it’s a reference to existing variable.
12   What’s the difference between accessing a class method via -> and via ::? – :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.
13   Are objects passed by value or by reference? – Everything is passed by value.
14   How do you call a constructor for a parent class? – parent::constructor($value)
15   What’s the special meaning of __sleep and __wakeup? – __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.
16  Why doesn’t the following code print the newline properly?    <?php 
            $str = ‘Hello, there.nHow are you?nThanks for visiting TechInterviews’; 
            print $str; 
    ?> 
Because inside the
single quotes the n character is not interpreted as newline, just as a sequence of two characters – and n.
17   Would you initialize your strings with single quotes or double quotes? – Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.
18  How come the code <?php print "Contents: $arr[1]"; ?> works, but <?php print "Contents: $arr[1][2]"; ?> doesn’t for two-dimensional array of mine? – Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.
19   What is the difference between characters �23 and x23? – The first one is octal 23, the second is hex 23.
20  With a heredoc syntax, do I get variable substitution inside the heredoc contents? – Yes.
21  I want to combine two variables together:
 $var1 = 'Welcome to ';
 $var2 = 'TechInterviews.com';
     What will work faster? Code sample 1:
$var 3 = $var1.$var2;
     Or code sample 2:
          $var3 = "$var1$var2";
Both examples would provide the same result – $var3 equal to "Welcome to TechInterviews.com". However, Code Sample 1 will work significantly faster. Try it out with large sets of data (or via concatenating small sets a million times or so), and you will see that concatenation works significantly faster than variable substitution.
22 For printing out strings, there are echo, print and printf. Explain the differences. – echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:
 <?php echo 'Welcome ', 'to', ' ', 'TechInterviews!'; ?>
and it will output the string "Welcome to TechInterviews!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.
23  I am writing an application in PHP that outputs a printable version of driving directions. It contains some long sentences, and I am a neat freak, and would like to make sure that no line exceeds 50 characters. How do I accomplish that with PHP? – On large strings that need to be formatted according to some length specifications, use wordwrap() or chunk_split().
24     What’s the output of the ucwords function in this example?
 $formatted = ucwords("TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS");
 print $formatted;
What will be printed is TECHINTERVIEWS IS COLLECTION OF INTERVIEW QUESTIONS.

ucwords() makes every first letter of every word capital, but it does not lower-case anything else. To avoid this, and get a properly formatted string, it’s worth using strtolower() first.
25   What’s the difference between htmlentities() and htmlspecialchars()? – htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.
26    What’s the difference between md5(), crc32() and sha1() crypto on PHP? – The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.
28  So if md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()? – Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.

[+/-] Read More...