Sunday, May 1, 2011

Basic MySql Database Questions with Answers | MySql Mostly Asked Question in Interview

SOCIALIZE IT →


Q 1 how to do login in mysql with unix shell
A: By below method if password is pass and user name is root
A# [mysql dir]/bin/mysql -h hostname -u root -p pass

Q 2 how you will Create a database on the mysql server with unix shell
A: mysql> create database databasename;

Q 3 how to list or view all databases from the mysql server.
A: mysql> show databases;

Q4 How Switch (select or use) to a database.
A: mysql> use databasename;

Q 5 How To see all the tables from a database of mysql server.
A: mysql> show tables;

Q 6 How to see table’s field formats or description of table .
A: mysql> describe tablename;

Q7 How to delete a database from mysql server.
A : mysql> drop database databasename;

Q 8 How we get Sum of column
A : mysql> SELECT SUM(*) FROM [table name];

Q9 How to delete a table
A : mysql> drop table tablename;

Q 10 How you will Show all data from a table.
A : mysql> SELECT * FROM tablename;

Q 11 How to returns the columns and column information pertaining to the designated table
A: mysql> show columns from tablename;

Q12 How to Show certain selected rows with the value “pcds”
A : mysql> SELECT * FROM tablename WHERE fieldname = “pcds”;

Q13 How will Show all records containing the name “sonia” AND the phone number ’9876543210′
A: mysql> SELECT * FROM tablename WHERE name = “sonia” AND phone_number = ’9876543210′;

Q 14 How you will Show all records not containing the name “sonia” AND the phone number ’9876543210′ order by the phone_number field.
A: mysql> SELECT * FROM tablename WHERE name != “sonia” AND phone_number = ’9876543210′ order by phone_number;

Q 15 How to Show all records starting with the letters ‘sonia’ AND the phone number ’9876543210′
A : mysql> SELECT * FROM tablename WHERE name like “sonia%” AND phone_number = ’9876543210′;

Q16 How to show all records starting with the letters ‘sonia’ AND the phone number ’9876543210′ limit to records 1 through 5.
A: mysql> SELECT * FROM tablename WHERE name like “sonia%” AND phone_number = ’9876543210′ limit 1,5;

Q 17 Use a regular expression to find records. Use “REGEXP BINARY” to force case-sensitivity. This finds any record beginning with r.
A :mysql> SELECT * FROM tablename WHERE rec RLIKE “^r”;

Q 18How you will Show unique records.
A: mysql> SELECT DISTINCT columnname FROM tablename;

Q 19 how we will Show selected records sorted in an ascending (asc) or descending (desc)
A : mysql> SELECT col1,col2 FROM tablename ORDER BY col2 DESC;
mysql> SELECT col1,col2 FROM tablename ORDER BY col2 ASC;

Q20 how to Return total number of rows.
A: mysql> SELECT COUNT(*) FROM tablename;

Q21 How to Join tables on common columns.
A: mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id

0 comments :

Post a Comment