Database Related Questions
Database Related Questions
& Answers
1.What is a database?
A database is basically a collection of structured data in such a way that it can easily be
retrieved, managed and accessed in various ways. One of the simplest forms of databases
is a text database. Relational databases are the most popular database system which
includes the following:
MySQL
Oracle Database
SQL server
Sybase
Informix
IBM db2
NO SQL
Among all these databases, MySQL is one of the easiest databases to work with. Let me
walk you through about this in detail.
2 .What is MySQLdb?
4 .Database Operations[CRUD]:
There are numerous operations a programmer can perform using databases and SQL in
order to have sound knowledge of database programming and MySQL.
I have demonstrated the CRUD operations below
o Create– It is an SQL statement used to create a record in the table or can say it is
used for creating a table.
o Read- It is used for fetching useful information from the database.
o Update- This particular SQL statement is used for updating the records in the table
or updating the table.
o Delete- As the name itself justifies this command is used for deleting the table.
5. What is the difference between MySQL and SQL?
SQL is known as the standard query language. It is used to interact with the database like
MySQL. MySQL is a database that stores various types of data and keeps it safe.
A PHP script is required to store and retrieve the values inside the database.
There is a major difference between a database and a table. The differences are as follows:
o Tables are a way to represent the division of data in a database while the database is
a collection of tables and data.
o Tables are used to group the data in relation to each other and create a dataset. This
dataset will be used in the database. The data stored in the table in any form is a part
of the database, but the reverse is not true.
First of all, the MYSQL server is free to use for developers and small enterprises.
MySQL's community is tremendous and supportive; hence any help regarding MySQL is
resolved as soon as possible.
MySQL has very stable versions available, as MySQL has been in the market for a long
time. All bugs arising in the previous builds have been continuously removed, and a very
stable version is provided after every update.
There are many tables that remain present by default. But, MyISAM is the default database
engine used in MySQL. There are five types of tables that are present:
o MyISAM
o Heap
o Merge
o INNO DB
o ISAM
Installing MySQL on our system allows us to safely create, drop, and test web applications
without affecting our live website's data. There are many ways to use MySQL on our system,
but the best way is to install it manually. The manual installation allows us to learn more
about the system and provides more control over the database. Manual installation of
MySQL has several benefits:
o Backing up, reinstalling, or moving databases from one location to another can be
achieved in a second.
o It provides more control to how and when MySQL server starts and closes.
We can check the MySQL version on Linux using the below command:
mysql -v
If we use the MySQL in windows, opening the MySQL command-line tool displayed the
version information without using any flags.
A column is a series of cells in a table that stores one value for each row in a table. We can
add columns in an existing table using the ALTER TABLE statement as follows:
ALTER TABLE table_name
We can delete a table in MySQL using the Drop Table statement. This statement removes
the complete data of a table, including structure and definition from the database
permanently. Therefore, it is required to be careful while deleting a table. After using the
statement, we cannot recover the table in MySQL. The statement is as follows:
The foreign key is used to link one or more tables together. It matches the primary key field
of another table to link the two tables. It allows us to create a parent-child relationship with
the tables. We can add a foreign key to a table in two ways:
o Using the CREATE TABLE Statement
o Using the ALTER TABLE Statement
Following is the syntax to define a foreign key using CREATE TABLE OR ALTER TABLE
statement:
[CONSTRAINT constraint_name]
FOREIGN KEY [foreign_key_name] (col_name, ...)
REFERENCES parent_tbl_name (col_name,...)
Importing database in MySQL is a process of moving data from one place to another place.
It is a very useful method for backing up essential data or transferring our data between
different locations. For example, we have a contact book database, which is essential to
keep it in a secure place. So we need to export it in a safe place, and whenever it lost from
the original location, we can restore it using import options.
While creating a table, we have kept one of the column names incorrectly. To change or
rename an existing column name in MySQL, we need to use the ALTER TABLE and
CHANGE commands together. The following are the syntax used to rename a column in
MySQL:
ALTER TABLE table_name
CHANGE COLUMN old_column_name new_column_name column_definition [FIRST|
AFTER existing_column];
Suppose the column's current name is S_ID, but we want to change this with a more
appropriate title as Stud_ID. We will use the below statement to change its name:
ALTER TABLE Student CHANGE COLUMN S_ID Stud_ID varchar(10);
We can insert data in a MySQL table using the INSERT STATEMENT. This statement
allows us to insert single or multiple rows into a table. The following is the basic syntax to
insert a record into a table:
INSERT INTO table_name ( field1, field2,...fieldN )
VALUES ( value1, value2,...valueN );
If we want to insert more than one rows into a table, use the below syntax:
INSERT INTO table(field1, field2,...fieldN)
VALUES
(value1, value 2, ...),
(value1, value2, ...),
...
(value1, value2, ...);
We can connect two or more tables in MySQL using the JOIN clause. MySQL allows various
types of JOIN clauses. These clauses connect multiple tables and return only those records
that match the same value and property in all tables. The following are the four easy ways to
join two or more tables in MySQL:
o Inner Join
o Left Join
o Right Join
o Cross Join
MySQL primary key is a single or combination of the field used to identify each record in a
table uniquely. A primary key column cannot be null or empty. We can remove or delete a
primary key from the table using the ALTER TABLE statement. The following syntax is used
to drop the primary key:
ALTER TABLE table_name DROP PRIMARY KEY;
Auto Increment is a constraint that automatically generates a unique number while inserting
a new record into the table. Generally, it is used for the primary key field in a table. In
MySQL, we can set the value for an AUTO_INCREMENT column using the ALTER TABLE
statement as follows:
ALTER TABLE table_name AUTO_INCREMENT = value;
25. Explain the role of the PEP 249 specification in Python database programming
28. What is the difference between a relational database and a non- relational
database?
29. What is the purpose of the commit() and rollback() methods in PostgreSQL
transactions?