Sie sind auf Seite 1von 8

MySQL Interview Questions

How we can count duplicate entry in particular table against Primary Key ?
What are constraints?

• we can count the number of duplicated rows by using the following condition
Here vFirstName is not primarykey.

SELECT count( * )
FROM member
GROUP BY vFirstName
HAVING count( vFirstName ) >1
LIMIT 0 , 30

• select count(*) from tablename where count(*) >1 group by empno;

( jst checkin for to count duplicate records if not jst send reply to me)

• want to know how u will find primary key in duplicate data .can we find a
primary key in duplicate data.....

• Every table should have a primary key defined. If that is the case the RDBMS will not
allow a duplicate row to be inserted. The INSERT statement will fail and the table will
never have a duplicate (neither will the unique index).
The syntax in the previous answer (where count(*) > 1) is very questionable. suppose
you think that you have duplicate employee numbers. there's no need to count them to
find out which values were duplicate but the followin SQL will show only the empnos
that are duplicate and how many exist in the table:

Select empno count(*)

from employee

group by empno

having count(*) > 1

• Generally speaking aggregate functions (count sum avg etc.) go in the HAVING clause. I
know some systems allow them in the WHERE clause but you must be very careful in
interpreting the result. WHERE COUNT(*) > 1 will absolutely NOT work in DB2 or
ORACLE. Sybase and SQLServer is a different animal.
• What are the advantages of mysql comparing with oracle?

MySql has many advantages in comparison to Oracle.

1 - MySql is Open source, which can be available any time

2 - MySql has no cost of development purpose.

3 - MySql has most of features , which oracle provides

4 - MySql day by day updating with new facilities.

5 - Good for small application.

6 - easy to learn and to become master.

7 - MySql has a good power these days.

even though MySql having so many advantages, Oracle is best database ever in Software
development.

compared to Oracle MySql is easy to install as MySql takes split of second to install
and it has other features like case insensitivity MySql has query browsers and those
can also be used for Oracle

How to display nth highest record in a table for example? How to display 4th
highest (salary) record from customer table?

select max(salary) from tablename where salary not in (select salary from
tablename order by salary desc limit n q)

What are the limitations of mysql in Comparison of Oracle?

Every column in a database table is assigned a data type. The data type maybe
native to the database management system or may be a custom data type. Each Oracle9i
Database native data type belongs to one of six categories: character number date
large object (LOB) raw and row identifier. Oracle date data types only store valid
dates support automatic time zone conversion and store sub-second precision.
MySQL categorizes data types into string numeric and date and time types. Unlike
Oracle MySQL date data types can store invalid dates do not support time zones
and the precision of time values is limited to one second.

MySQL supports six different types of tables four of which do not support
transactions (MyISAM MERGE ISAM and HEAP) and two of which support
transactions (InnoDB and BDB). The multiple table types are a result of the initial
MySQL design where fast non-transactional tables were the only option. Because
non-transactional tables do not support referential integrity transactions and hot
backups no mission-critical application development could utilize these tables.

How can i store images in database?

• you need to work with LOB / BLOB / CLOB large object datatypes.

• In practice for MySQL the images can be stored onto hard dirve directly and
the path is stored as string in mysql

How many drivers in MYSQL?

• There are eleven drivers in MYSQL .Six of them from MySQL AB and five by
MYSQL Communities.They are1.PHP Driver 2.ODBC Driver 3.JDBC Driver
4.ado.net 5.mxj 6.CAPI

• 1.PHP DRIVER 2.PERL DRIVER 3.PYTHON DRIVER 4.RUBY DRIVER 5.C++


WRAPPER

1. How to create the stored procedures in mysql and it will be write on


where?
2. Difference between SQL stored procedures, MYSQL stored procedures, SQL
Server stored procedure

How are triggers created in MySQL?

CREATE TRIGGER `tgr_name` AFTER UPDATE ON `addresses` FOR EACH ROW begin
update products set countryName = new.countryName where
products.shippingAddressId = old.id;
end;

What are the data types available in MySQL?

DATA TYPES in mysql varchar =>


A variable section from 0 to 255 characters long.
tinyint => A string with a maximum length of 255 characters.
text => A string with a maximum length of 65535 characters.
date => YYYY-MM-DD.
smallint mediumint int => -2147483648 to 2147483647 normal 0 to
4294967295 UNSIGNED.
bigint => -9223372036854775808 to 9223372036854775807 normal 0 to
18446744073709551615 UNSIGNED.
float => A small number with a floating decimal point.
double => A large number with a floating decimal point.
decimal => A DOUBLE stored as a string , allowing for a fixed decimal point.
datetime => YYYY-MM-DD HH:MM:SS. timestamp => YYYYMMDDHHMMSS.
time => HH:MM:SS. year
char => CHAR( ) A fixed section from 0 to 255 characters long.
tinyblob tinytext
blob => A string with a maximum length of 65535 characters.BLOB stands for
Binary Large OBject.
mediumblob => A string with a maximum length of 16777215 characters.
longblob => A string with a maximum length of 4294967295 characters.

longtext enum => Short for ENUMERATION which means that each column may have
one of a specified possible values.
set => Similar to ENUM except each column may have more than one of the
specified possible values. bool binary

What is RELOAD privileges in MySQL used for?

• Reload privileges are mainly used when a new user is created and
you want to apply the changes without re starting Mysql
syntax to use:
mysql -u username -ppassword -e"flush privileges";

• Reload privileges are used to apply any changes on settings related to


privileges without re starting Mysql's current session
syntax to use:
mysql -u username -p password -e "flush privileges";

How is sub queries handled in MySQL?

Sub queries in MySQL handled nested way You can see the example and
understand yourself -

SELECT name headofstate population FROM Country WHERE population


(SELECT MAX(population) FROM Country);

What are the Performance and Scalability characteristics of MySQL?

How is Sequences handled in MySQL?

• Sequences are handled by primary key or by unique in which primary keys


don't allow any duplicate rows and null values are not accepted. Sequences
and unique allows multiple NULL values and duplicates values are not
allowed
• sequence handle is a concept by which we can provide a auto a auto
genrated key to database like we have to provide primary key that is unique
then we can use the sequence

What are the vital advantages of MYSQL?


It is opensourse sw easy to download and install and very easy forsall application

What is Query Cache in MySQL?


Query Cache stores both SELECT statenment and its result; if any similar query recives later it
will retrive result from query plan;
Query Cache is not use full for server side Prepared Statement

What are the levels of triggers supported by MySQL?


MySQL 5.1 triggers only support each-row level

How is Exception Handling hanled in MySQL?


In MySQL exception handling is done through

Declare {Continue|Exit} handler set <error variable> <some value>

So whenever an error has occured the error variable is set a value and then depending upon
continue or exit handler the next statement is executed or the procedure exits.

RE: How is Exception Handling hanled in MySQL?


Most programming languages have some type of error handling that allow the programmer to
deal with errors or exceptions that are raised within the program. It’s likely you will have at some
time encountered errors within SQL statements. It’s these errors that can be handled within the
handlers section of a stored procedure. An error warning or exception is handled using the
following syntax.

DECLARE handler_type HANDLER FOR condition_value[ ...] sp_statement

The handler type is the action that will happen if the handler is called. This can be either continue
to carry on processing the procedure exit to leave the procedure and rollback (which as yet is
unsupported) but likely to be useful when dealing with transactions. Errors can be handled on a
number levels which can be categorized in the following groups. This is defined in the
condition_value section.

The different categories are as follows.


1. SQLSTATE
2. SQLWARNING
3. NOT FOUND
4. SQLEXCEPTION
5. mysql_error_code
6. condition_name
Error numbers within MySQL are grouped by SQLSTATE so a handler defined with
SQLSTATE will handle all of the conditions raised under a particular SQLSTATE code.

The next levels are SQLWARNING which groups SQLSTATE codes beginning with 01.
NOTFOUND is for errors with an SQLSTATE beginning with 02.

SQLEXCEPTION which is any SQLSTATE outside of these 2 groups.

Mysql_error_code is for individual errors and exceptions.

If you wanted to deal with 2 not found errors in a different way you could do this using the
particular error code in two separate handlers. Condition_name allows us to define our own
names for an SQLSTATE or error code.

The final part of the handler is the set condition which is an area used to define code to be
performed if the handler is called. It’s likely you would set a variable in this are which could be
used later to determine if the handler has been called.

What is the command for counting all the rows in a table in MySQL?

Select count(*) from table_name

How to view all Stored Procedures in MySQL?


show procedure status;

What are the Platforms supported by MySQL?

5.1 5.0 4.1


Operating System Architecture Active Active Extended
Red Hat
Red Hat Enterprise Linux 5 x86, X86_64 • •
Red Hat Enterprise Linux 4 x86, x86_64, Intel IA64 • • •
Red Hat Enterprise Linux 3 x86, x86_64, Intel IA64 • • •
Novell
Novell - SuSE Enterprise Linux 10 x86, x86_64, Intel IA64 • •
Novell - SuSE Enterprise Linux 9 x86, x86_64, Intel IA64 • • •
Debian
Debian GNU/Linux 4.0 x86, x86_64 • •
Debian GNU/Linux 3.1 PowerPC, x86 • • •
Debian GNU/Linux 3.0 PowerPC • •
Microsoft
Microsoft Windows 2008 Server x86, X86_64 • •
Microsoft Windows Vista x86, X86_64 • •
Microsoft Windows 2003 Server x86 • • •
Microsoft Windows 2003 Server X86_64 • •
Microsoft Windows XP x86 • • •
Microsoft Windows XP X86_64 • •
Microsoft Windows 2000 Server x86 • •
Sun
SPARC (32 and 64 bit),
Sun Solaris 10 • •
x86_64, x86/32-bit
SPARC (32 and 64 bit), x86/32-
Sun Solaris 9 • • •
bit
SPARC (32 and 64 bit), x86/32-
Sun Solaris 8 • • •
bit
OpenSolaris 2008.11 x86, x86_64 •
OpenSolaris 2008.05 x86, x86_64 •
HP
HP-UX 11.31 (11i v3)
(Note: please read bug #38549 Intel IA64 • •
before installation.)
HP-UX 11.23 (11i v2) Intel IA64 • • •
PA-RISC 2.0, 64-bit; PA-RISC
HP-UX 11.11 (11i v1) • • •
1.1 and 2.0
IBM
IBM AIX 5.3 IBM VisualAge C++, 64-bit • •
i5/OS V5R4 POWERPC_64, POWERPC_32• •
i5/OS V6R1 POWERPC_64, POWERPC_32• •
Apple
x86, x86_64, PowerPC_64,
Apple Mac OS X v10.5 • •
PowerPC_32
x86, PowerPC_64,
Apple Mac OS X v10.4 • • •
PowerPC_32
Apple Mac OS X v10.4 x86_64 • •
Apple Mac OS X v10.3 PowerPC_32 • •
SCO
SCO OpenServer 6.0 x86 • •
FreeBSD
FreeBSD 7 x86 •
FreeBSD 7 AMD64 / Intel EM64T •
FreeBSD 6 x86 • • •
FreeBSD 6 AMD64 / Intel EM64T • • •
Various
x86_64 dynamic glibc-2.3 • • •
x86_64, dynamic glibc-2.3, icc • • •
IBM/Motorola PowerPC,
Other Linux: • •
IBM/POWER, glibc-2.3
Fedora, IBM/Motorola PowerPC,
openSuSE, •
IBM/POWER
CentOS,
S/390 • • •
Redhat,
Ubuntu x86, dynamic glibc-2.3 • • •
x86, dynamic glibc-2.3, icc • • •
x86, static glibc 2.2 •
IA64, glibc-2.3, dynamic, gcc • •

How to view all Triggers in MySQL?


show triggers;

How MySQL helps in reducing the Total Cost of Ownership (TCO) of database?
Mysql is a open source so u can get the source code and complie ur self
or get pre compiled setups based on the OS for free

And if we consider other leading Database sources mysql is much cheper and easy to manage

Das könnte Ihnen auch gefallen