- In MySQL, how do I create a database?
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
[create_specification [create_specification] ...]
- In MySQL, how do I create a table?
CREATE TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
[table_options] [select_statement]
- What’s the default port for MySQL Server?
3306
- Explain the difference between FLOAT, DOUBLE and REAL?
FLOATs store floating point numbers with 8 place accuracy and take up 4 bytes. DOUBLEs store floating point numbers with 16 place accuracy and take up 8 bytes. REAL is a synonym of FLOAT for now.
- How would you change a column from VARCHAR(20) to VARCHAR(30)?
ALTER TABLE tablename CHANGE fieldname fieldname VARCHAR(30).
- How would you delete a column?
ALTER TABLE tablename DROP fieldname.
- What do % and _ mean inside LIKE statement?
% corresponds to 0 or more characters, _ is exactly one character.
- How do you concatenate strings in MySQL?
CONCAT (string1, string2, string3)
- What are mysql db engines?
MyISAM, Heap, Merge, INNO DB, ISAM
- What is the difference between truncate and drop?
Truncate will empty the data of table
Drop will delete the data and structure of table
- What is the difference between group by and order by?
Group by controls the presentation of the rows, order by controls the presentation of the columns for the results of the SELECT statement.
- What is a view? Why use it?
view is a virtual table made up of data from base tables and other views, but not stored separately.
- What is the basic difference between a join and a union?
A join selects columns from 2 or more tables. A union selects rows.
- What is the syntax of creating INDEX in Mysql?
CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name
[index_type]
ON tbl_name (index_col_name,...)
- How can you see all indexes defined for a table?
SHOW INDEX FROM tabllename;
- How will get the information about the columns in a table
DESCRIBE tbl_name
or
DESC tbl_name
- Explain advantages of InnoDB over MyISAM?
Row-level locking, transactions, foreign key constraints and crash recovery.
- Explain advantages of MyISAM over InnoDB
Much more conservative approach to disk space management - each MyISAM table is stored in a separate file, which could be compressed then with myisamchk if needed. With InnoDB the tables are stored in tablespace, and not much further optimization is possible. All data except for TEXT and BLOB can occupy 8,000 bytes at most. No full text indexing is available for InnoDB. TRhe COUNT(*)s execute slower than in MyISAM due to tablespace complexity.
- Use mysqldump to create a copy of the database?
mysqldump -h mysqlhost -u username -p mydatabasename > dbdump.sql
- If the value in the column is repeatable, how do you find out the unique values?
Use DISTINCT in the query
Eg:- SELECT DISTINCT name FROM members