Mysql
When to use MySQL
Why would you use MySQL over PostgreSQL? First, we need to consider the needs of the applications in terms of database requirements. If I want to create a Web application and performance is an issue, MySQL will be my choice because it’s fast and designed to work well with Web-based servers. However, if I want to create another application that demands transactions and foreign key references, PostgreSQL is the choice.
MySQL is relatively faster than PostgreSQL.
Database design will be simpler.
You can create a basic Web-driven Web site.
MySQL’s replication has been thoroughly tested.
There’s no need for cleanups in MySQL (Vacuum).
Mysql was written in c and c++.
To know second max sal
Select sal from emp order by sal desc limit 1,1;
The Row Holding the Maximum of a Certain Column
SELECT article, dealer, price
FROM shop
WHERE price=(SELECT MAX(price) FROM shop);
1.What is MySQL?
MySql is a Relational database management system, provided from open source community. Currently fast growing and hight used RDBMS. MySql Developed by MySql AB.
2.What is Postgres?
3.What are the basic steps in setting up an Oracle system?
4.What is a stored procedure, and which databases support it?
Set of sql statements. Mysql 5.0 supports procedures.
5.What is RMAN?
6.What is the TDS protocol?
7.What is required to connect to an oracle system remotely?
8.In MySQL, how do I create a database?
9.In MySQL, how do I grant access to a user to a specific database with read only permissions?
10.In MySQL, what table type is required for foreign keys to work?
InnoDB
11.Constraint: primary key. Foreign key, unique key
12.Connecting to server:
shell> mysql -h host -u user -p
Enter password: ********
SELECT VERSION(), CURRENT_DATE;
Use the SHOW statement to find out what databases currently exist on the server:
mysql> SHOW DATABASES;
If the test database exists, try to access it:
mysql> USE test
Database changed
mysql> GRANT ALL ON menagerie.* TO 'your_mysql_name'@'your_client_host';
where your_mysql_name is the MySQL username assigned to you and your_client_host is the host from which you connect to the server.
CREATE DATABASE menagerie;
USE menagerie
or
shell> mysql -h host -u user -p menagerie
Enter password: ********
Note that menagerie is not your password on the command just shown. If you want to supply your password on the command line after the -p option, you must do so with no intervening space (for example, as -pmypassword, not as -p mypassword). However, putting your password on the command line is not recommended, because doing so exposes it to snooping by other users logged in on your machine.
SHOW TABLES;
DESCRIBE pet;
LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;
mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
-> LINES TERMINATED BY '\r\n';
Some characteristics of extended regular expressions are:
· '.' matches any single character.
· A character class '[...]' matches any character within the brackets. For example, '[abc]' matches 'a', 'b', or 'c'. To name a range of characters, use a dash. '[a-z]' matches any letter, whereas '[0-9]' matches any digit.
· '*' matches zero or more instances of the thing preceding it. For example, 'x*' matches any number of 'x' characters, '[0-9]*' matches any number of digits, and '.*' matches any number of anything.
· A REGEXP pattern match succeed if the pattern matches anywhere in the value being tested. (This differs from a LIKE pattern match, which succeeds only if the pattern matches the entire value.)
· To anchor a pattern so that it must match the beginning or end of the value being tested, use '^' at the beginning or '$' at the end of the pattern.
To demonstrate how extended regular expressions work, the LIKE queries shown previously are rewritten here to use REGEXP.
To find names beginning with 'b', use '^' to match the beginning of the name:
mysql> SELECT * FROM pet WHERE name REGEXP '^b';
1.What are the different types of joins?
Different Types of Joins-
Inner Join
Outer Join - Right Outer Join
Left Outer Join
Cross Join
2.Explain normalization with examples.
The process of converting complex data structures into simple, stable data structures
3.What cursor type do you use to retrieve multiple recordsets?
REF Cursor
4.Diffrence between a “where” clause and a “having” clause
1.”where” is used to filter records returned by “Select”
2.”where” appears before group by clause
3.In “where” we cannot use aggrigate functions like where count(*)>2 etc
4.”having” appears after group by clause
5.”having” is used to filter records returned by “Group by”
6.In”Having” we can use aggrigate functions like where count(*)>2 etc
5.What is the difference between “procedure” and “function”?
6.How will you copy the structure of a table without copying the data?
select top 0 * into xyz from try
7.How to find out the database name from SQL*PLUS command prompt?
8.Tadeoffs with having indexes
9.Talk about “Exception Handling” in PL/SQL?
10.What is the diference between “NULL in C” and “NULL in Oracle?”
11.What is Pro*C? What is OCI?
12.Give some examples of Analytical functions.
13.What is the difference between “translate” and “replace”?
14.What is DYNAMIC SQL method 4?
15.How to remove duplicate records from a table?
16.What is the use of ANALYZing the tables?
17.How to run SQL script from a Unix Shell?
18.What is a “transaction”? Why are they necessary?
19.Explain Normalizationa dn Denormalization with examples.
20.When do you get contraint violtaion? What are the types of constraints?
21.How to convert RAW datatype into TEXT?
22.Difference - Primary Key and Aggregate Key
23.How functional dependency is related to database table design?
24.What is a “trigger”?
it’s a piece of sql that is activitied when a certain event happens.
25.Why can a “group by” or “order by” clause be expensive to process?
26.What are “HINTS”? What is “index covering” of a query?
27.What is a VIEW? How to get script for a view?
A Database View is a subset of the database sorted and displayed in a particular way.
28.What are the Large object types suported by Oracle?
29.What is SQL*Loader?
30.Difference between “VARCHAR” and “VARCHAR2″ datatypes.
Difference between Varchar and Varchar2 is both are variable length but only 2000 bytes of character of data can be store in varchar where as 4000 bytes of character of data can be store in varchar2.
31.What is the difference among “dropping a table”, “truncating a table” and “deleting all records” from a table.
Dropping : (Table structure + Data are deleted), Invalidates the dependent objects ,Drops the indexes
Truncating: (Data alone deleted), Performs an automatic commit, Faster than delete
Delete : (Data alone deleted), Doesn’t perform automatic commit
32.Difference between “ORACLE” and “MICROSOFT ACCESS” databases.
33.How to create a database link?
34.What is SQL?
SQL stands for 'Structured Query Language'.
35.What is SELECT statement?
The SELECT statement lets you select a set of values from a table in a database. The values selected from the database table would depend on the various conditions that are specified in the SQL query.
36.How can you compare a part of the name rather than the entire name?
SELECT * FROM people WHERE empname LIKE '%ab%'
Would return a recordset with records consisting empname the sequence 'ab' in em
37.What is the INSERT statement?
The INSERT statement lets you insert information into a database
38.How could I get distinct entries from a table?
The SELECT statement in conjunction with DISTINCT lets you select a set of distinct values from a table in a database. The values selected from the database table would of course depend on the various conditions that are specified in the SQL query. Example
SELECT DISTINCT empname FROM emptable
39.How to get the results of a Query sorted in any order?
You can sort the results and return the sorted results to your program by using ORDER BY keyword thus saving you the pain of carrying out the sorting yourself. The ORDER BY keyword is used for sorting.
SELECT empname, age, city FROM emptable ORDER BY empname
40.How can I find the total number of records in a table?
You could use the COUNT keyword , example
SELECT COUNT(*) FROM emp WHERE age>40
41.What is GROUP BY?
The GROUP BY keywords have been added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called. Without the GROUP BY functionality, finding the sum for each individual group of column values was not possible.
42.What is the difference among "dropping a table", "truncating a table" and "deleting all records" from a table.
Dropping : (Table structure + Data are deleted), Invalidates the dependent objects ,Drops the indexes
Truncating: (Data alone deleted), Performs an automatic commit, Faster than delete
Delete : (Data alone deleted), Doesn’t perform automatic commit
43.What are the Large object types suported by Oracle?
Blob and Clob.
44. Difference between a "where" clause and a "having" clause.
Having clause is used only with group functions whereas Where is not used with 45. What's the difference between a primary key and a unique key?
Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only.
46. What are cursors? Explain different types of cursors. What are the disadvantages of cursors? How can you avoid cursors?
Cursors allow row-by-row prcessing of the resultsets.
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven. See books online for more information.
Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.
Most of the times, set based operations can be used instead of cursors
Tuesday, July 7, 2009
Subscribe to:
Posts (Atom)