MySQL InterviewDoc copy
MySQL InterviewDoc copy
By BobIT
MySQL
1- What is database?
2- What is DBMS”
DBMS stands for Database Management System. DBMS is a system software responsible
for the creation, retrieval, updating and management of the database. It ensures that
our data is consistent, organized and is easily accessible by serving as an interface
between the database and its end users or application software.
RDBMS stands for Relational Database Management System. The key difference here,
compared to DBMS, is that RDBMS stores data in the form of a collection of tables and
relations can be defined between the common fields of these tables. Most modern
database management systems like MySQL, Microsoft SQL Server, Oracle, IBM DB2 and
Amazon Redshift are based on RDBMS.
4- What is SQL?
SQL stands for Structured Query Language. It is the standard language for relational
database management systems. It is especially useful in handling organized data
comprised of entities (variables) and relations between different entities of the data.
SQL is a standard language for retrieving and manipulating structured databases. On the
contrary, MySQL is a relational database management system, like SQL Server, Oracle or
IBM DB2, that is used to manage SQL databases.
Constraints are used to specify the rules concerning data in the table. It can be applied
for single or multiple fields in an SQL table during creation of table or after creationg
using the ALTER TABLE command. The constraints are:
By BobIT
NOT NULL - Restricts NULL value from being inserted into a column.
CHECK - Verifies that all values in a field satisfy a condition.
DEFAULT - Automatically assigns a default value if no value has been specified for the
field.
UNIQUE - Ensures unique values to be inserted into the field.
INDEX - Indexes a field providing faster retrieval of records.
PRIMARY KEY - Uniquely identifies each record in a table.
FOREIGN KEY - Ensures referential integrity for a record in another table.
A primary key is a combination of fields which uniquely specify a row. This is a special
kind of unique key, and it has implicit NOT NULL constraint. It means, Primary key values
cannot be NULL.
A Unique key constraint uniquely identified each record in the database. This provides
uniqueness for the column or set of columns.
A Primary key constraint has automatic unique constraint defined on it. But not, in the
case of Unique Key.
There can be many unique constraints defined per table, but only one Primary key
constraint defined per table.
A foreign key is one table which can be related to the primary key of another table.
Relationship needs to be created between two tables by referencing foreign key with
the primary key of another table.
By BobIT
There are various types of join which can be used to retrieve data and it depends on the
relationship between tables.
Inner Join.
Inner join return rows when there is at least one match of rows between the tables.
Right Join.
Right join return rows which are common between the tables and all rows of Right-hand
side table. Simply, it returns all the rows from the right-hand side table even though
there are no matches in the left-hand side table.
Left Join.
Left join return rows which are common between the tables and all rows of Left-hand
side table. Simply, it returns all the rows from Left hand side table even though there
are no matches in the Right-hand side table.
Full Join.
Full join return rows when there are matching rows in any one of the tables. This means,
it returns all the rows from the left-hand side table and all the rows from the right-hand
side table.
Constraint can be used to specify the limit on the data type of table. Constraint can be
specified while creating or altering the table statement. Sample of constraint are.
NOT NULL.
CHECK.
DEFAULT.
UNIQUE.
PRIMARY KEY.
FOREIGN KEY.
Self-join is set to be query used to compare to itself. This is used to compare values in a
column with other values in the same column in the same table. ALIAS ES can be used
for the same table comparison.
By BobIT
Cross join defines as Cartesian product where number of rows in the first table
multiplied by number of rows in the second table. If suppose, WHERE clause is used in
cross join then the query will work like an INNER JOIN.
SQL clause is defined to limit the result set by providing condition to the query. This
usually filters some rows from the whole set of records.
UNION operator is used to combine the results of two tables, and it eliminates duplicate
rows from the tables.
MINUS operator is used to return rows from the first query but not from the second
query. Matching records of first and second query and other rows from the first query
will be displayed as a result set.
TRUNCATE removes all the rows from the table, and it cannot be rolled back. DROP
command removes a table from the database and operation cannot be rolled back.
Both of these datatypes are used for characters but varchar2 is used for character
strings of variable length whereas char is used for character strings of fixed length. For
example, if we specify the type as char(5) then we will not be allowed to store string of
any other length in this variable but if we specify the type of this variable as varchar2(5)
then we will be allowed to store strings of variable length, we can store a string of
length 3 or 4 or 2 in this variable.
By BobIT
Data definition language or DDL allows to execute queries like CREATE, DROP and
ALTER. That is, those queries which define the data.
Primary key cannot have NULL value, the unique constraints can have NULL values.
There is only one primary key in a table, but there can be multiple unique constrains.
The primary key creates the cluster index automatically, but the Unique key does not
A Foreign key is a field which can uniquely identify each row in another table. And this
constraint is used to specify a field as Foreign key. That is, this field points to primary key
of another table. This usually creates a kind of link between the two tables.
By BobIT
28- How to learn a name how many times there are in table?
By BobIT