MySQL Interview Questions
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
( 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:
from employee
group by empno
• 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?
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)
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.
• 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
• 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
CREATE TRIGGER `tgr_name` AFTER UPDATE ON `addresses` FOR EACH ROW begin
update products set countryName = new.countryName where
products.shippingAddressId = old.id;
end;
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
• 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";
Sub queries in MySQL handled nested way You can see the example and
understand yourself -
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.
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 next levels are SQLWARNING which groups SQLSTATE codes beginning with 01.
NOTFOUND is for errors with an SQLSTATE beginning with 02.
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?
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