Friday, 5 September 2014

Mysql Interview Questions And Answers - Atomicity, Dedlock, Client Program, Mysql Mode, Mysql Sensitivity Of Identifiers And Mysql Errors

Question: what is the difference between where and having clause in mysql?
Answer:
where can restrict each row or record
having clause restrict group of records.



Question: What is Atomicity?
Answer:
This means whether execution of "all" statements or "no" statements.



Question: What is Deadlock?
Answer:
A failure or inability to proceed due to two transactions having some data that the other needs.



Question: What is mysql client program ?
Answer:
It is a command-line program that acts as a text-based front end for the MySQL Server. It's used for issuing queries and viewing the results in the terminal window.

mysql --help
mysql --version
mysql --V
In many cases, a given option has both a long and a short form. Long options consist of a word preceded by double dashes(e.g. --) whereas short options consist of a single letter preceded by a single dash(e.g. -).


Question: What is difference between Interactive Mode and Batch Mode of mysql client?
Answer: In Interactive modes, you put simple query to get the result, In this results is return in window.
In Batch Mode, you put your all the queries in sql file and run it from mysql client OR from scheduler job.  



Question: What is difference between \g and \G?
Answer: Both are the statement terminator alike semicolon(;). 

\g end the query statement and output the result in horizontal.
\G end the query statement and output the result in vertically and mainly used when output is large. 


Question: How to manage MySQL case sensitivity of identifiers?
Answer: Database name and table name are stored as file, So In window its case-insenstive and in unix it is case senstive.
Column name, index, and trigger are not case sensitive.
Column aliases are not case sensitive
 

Question: What is difference between identifier-quoting- character and string-quoting-character?
Answer:
backtick(`) are identifer quoting character and used  quote for dbname, tableName and filedName
Single Quote('), Double Quote(") are string quoting character

 

Question: What is SQL Query to print the warnings?
Answer: show warnings;


Question: What is SQL Query to print the warnings in Vertically?

Answer: show warning\G;display the warnings in vertical tabs;


Question: How to use limit in mysql warning?

Answer: show warning limit 1,2 \G;display the warnings in vertical tabs for 2nd & 3rd;



Question: In Mysql, How to disable the sql notes?
Answer: set sql_notes=0;



Question: How to get the detail of error in mysql?
Answer: perror 13; 
show the error message detail




Facebook login with javascript SDK example

Facebook login with javascript SDK example


Follow the Simple Steps to integrate Facebook Login with javascript SDK in your website, in 10 Mins.

Step: 1
Add Following html in Web Page
<a href="javascript:void(0)" onclick="return fblogin()">Facebook Login</a>


Step: 2
Add Following javaScript function, and get FACEBOOK_APPLICATION_ID from https://developers.facebook.com/.
var myWindow=null;
function fblogin(){
    var appId =FACEBOOK_APPLICATION_ID;/** facebook application id */
    var URLAfterAuth = 'http://www.example.com/ajax/fblogin';/* After authentication go to this page **/
    var str= window.location.href;
    if (myWindow && !myWindow.closed) { //exist and is not closed
        myWindow.close();
        myWindow=null; //delete the object

    }else{            
            myWindow = window.open('https://www.facebook.com/dialog/oauth?redirect_uri='+URLAfterAuth+'&display=popup&response_type=code&client_id='+appId+'&ret=login', 'mywindow','left=100,top=50,width=500,height=500,toolbar=0,resizable=0');                       

    }

}


Step: 3
Add Following script in ajax/fblogin URL
        //Add jQuery File
        <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
        <div id="fb-root">
</div>
<script>
             var str= window.location.href;             
            
            window.fbAsyncInit = function() {
                FB.init({
                    appId      : FACEBOOK_APPLICATION_ID                    
                    status     : true, 
                    cookie     : true,
                    xfbml      : true,
                    oauth      : true                    
                });
                FB.Event.subscribe('auth.authResponseChange', function(response) {                    
                    // Here we specify what we do with the response anytime this event occurs. 
                    if (response.status === 'connected') {
                        saveuserdetail();
                    } else if (response.status === 'not_authorized') {                        
                        FB.login();
                    } else {
                        FB.login();
                    }
                })  
  
            };
        
            function saveuserdetail() {                
                FB.api('/me', function(response) {
                    $.ajax({
                        type: "POST",
                         url: '/ajax/register/',/** Facebook will send user detail send in this URL **/
                        data: response,
                        success: function(msg){                            
                            if(msg['login']=='success'){   
                                 window.opener.location.reload();
                                 window.close();
                            }
                        },
                        dataType: 'json'
                    });
                });
            }
            (function(d){
                var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
                js = d.createElement('script'); js.id = id; js.async = true;
                js.src = "//connect.facebook.net/en_US/all.js";
                d.getElementsByTagName('head')[0].appendChild(js);
            }(document));
        </script>        
        Please wait ....
        


Step: 4
(After Facebook authentication facebook send user to this URL),
URL: ajax/register
print_r($_POST);//Here will have all details