SQL /MySQL Flashcards

1
Q

What is SQL?

A

SQL stands for Structured Query Language and it is used to communicate with the Database. This is a standard language used to perform tasks such as retrieval, updation, insertion, and deletion of data from a database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is RDBMS?

A

RDBMS stands for Relational Database Management System. RDBMS store the data into the collection of tables, which is related by common fields between the columns of the table. It also provides relational operators to manipulate the data store into the tables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is DBMS?

A

A Database Management System (DBMS) is a program that controls creation, maintenance and use of a database. DBMS can be termed as File Manager that manages data in a database rather than saving it in file systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a primary key?

A

A combination of fields which uniquely specify a row. This is a special kind of unique key and it has an implicit NOT NULL constraint. Primary key values cannot be NULL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a Database?

A

An organized form of data for easy access, storing, retrieval, and managing of data. A structured form of data which can be accessed in many ways.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are tables and fields?

A

A table is a set of data that are organized in a model with Columns and Rows. Columns are vertical and Rows are horizontal. A table has a specified number of columns called fields but can have any number of rows which are called a record.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a unique key?

A

A unique key constraint uniquely identifies 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.

There can be many unique constraint defined per table, but only one Primary key constraint defined per table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a foreign key?

A

A foreign key in 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Join?

A

This is a keyword used to query data from more tables based on the relationship between the fields of the tables. Keys play a major role when JOINs are used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an Inner Join?

A

An inner join returns rows when there is at least one match of rows between the tables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a Right Join?

A

Right join returns rows which are common between the tables and all rows of Right hand side table. It returns all the rows from the right hand side table even though there are no matches in the left hand side table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a Left Join?

A

Left join returns rows which are common between the tables and all rows of Left hand side table. it returns all the rows from Left hand side table even though there are no matches in the Right hand side table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a Full Join?

A

Full join returns rows when there are matching rows in any one of the tables. It returns all the rows from the left hand side table and all the rows from the right hand side table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a relationship and what are they?

A

Database Relationships is defined as the connection between the tables in a database. The various data basing relationships are:

  • One to One Relationship
  • One to Many Relationship
  • Many to One Relationship
  • Self-Referencing Relationship
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a Query?

A

A Query is a question to the database. A DB query is code written in order to get information back from the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a stored procedure?

A

Stored Procedure is a function that consists of many SQL statements to access the database system. Several SQL statements are consolidated into a stored procedure that can be executed at any time whenever required.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a constraint?

A

Constraint can be used to specificy the limit on the data type of the table. Constraint can be specified while creating or altering the table statement. Sample of constraints include:

  • NOT NULL
  • CHECK
  • DEFAULT
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is Auto Increment?

A

Auto Increment keyword allows the user to create a unique number to be generated when a new record is inserted into the table. AUTO INCREMENT keyword can be used whenever PRIMARY KEY is used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is CLAUSE?

A

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.

Ex:
Query that has WHERE condition
Query that has HAVING condition.

20
Q

What is an ALIAS command?

A

ALIAS name can be given to a table or column. This alias name can be referred in WHERE clause to identify the table or column.

21
Q

What is the difference between TRUNCATE and DROP statements?

A

TRUNCATE removes all the rows from the table and it cannot be rolled back. DROP removes a table from a database and cannot be rolled back.

22
Q

How to select unique records from a table?

A

Select unique records from a table by using DISTINCT keyword.

SELECT DISTINCT StudentID, StudentName from Student

23
Q

What is MySQL?

A

MySQL s an open source relational DBMS which is built, supported, and distributed by MySQL AB (now acquired by Oracle)

24
Q

Why is MySQL used?

A

MySQL database server is reliable, fast and very easy to use. It is a pure relational database.

25
Q

What is the default port for MySQL?

A

3306

26
Q

What is meant by % and _ in a LIKE statement?

A

% corresponds to 0 or more characters, _ is exactly one character

27
Q

How can we get the number of rows affected by a query?

A

SELECT COUNT (user_id) FROM users;

28
Q

How do you connect to MySQL via the command line?

A

mysql -u (username) -p

29
Q

How do you connect to a specific DB in MySQL at login via the command line?

A

mysql -u (username) -p (database)

30
Q

How do you exit MySQL in the command line?

A

exit;

31
Q

How do you create a database with a specified name ?

A

CREATE DATABASE database_name;

32
Q

How do you choose a database or change the current database to another database?

A

USE database_name;

33
Q

How do you delete a database?

A

DROP DATABASE database_name;

34
Q

How do you show all databases in the current MySQL DB server?

A

SHOW DATABASES;

35
Q

How do you view all tables in a current DB?

A

SHOW TABLES;

36
Q

How do you create a table?

A

CREATE TABLE table_name(
column_name column_type
);

37
Q

How do you add a new column into a table?

A

ALTER TABLE table
ADD [COLUMN] column_name column_definition [FIRST | AFTER existing_column]

Can add the column as the first column or after a specific column. If the position is not specified, it will be added last.

38
Q

How do you drop a column from a table?

A

ALTER TABLE table_name

DROP [COLUMN] column_name;

39
Q

How do you show the columns of a table?

A

DESCRIBE table_name;

40
Q

How do you delete a table?

A

DROP TABLE table_name;

41
Q

How do you add a Primary Key to a table?

A

ALTER TABLE table_name

ADD PRIMARY KEY (column name);

42
Q

How do you remove a Primary key from a table?

A

ALTER TABLE table_name

DROP PRIMARY KEY;

43
Q

How do you select all data from a data?

A

SELECT * FROM table_name;

44
Q

How do you query data from one or more columns of a table?

A

SELECT
column1, column2, …
FROM
table_name;

45
Q

How do you remove duplicate rows from the result of a query?

A

SELECT
DISTINCT (column)
FROM
table_name;

46
Q

How do you query data with a filter using a WHERE clause?

A

SELECT select_list
FROM table_name
WHERE condition;

47
Q

What is the difference between a relational and non-relational database?

A

A relational database is a digital database based on the relational model of data. Data is stored in tables containing rows (which represents an entry) and columns (which stores and sorts a specific type of information).

Relation DB have fast query times, are not as scalable. Relation DB do better when you know how the data will be queried.

A non-relational database (or NoSQL) is a database that provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular references used in relational databases. Non-relation al there is no specific relationship between them. They do not have primary keys. Queries are not based on keys and relations to retrieve data, it’s more about having an idea of data you are looking for.

Non-relational DB perform better when you do not know how your data will be queried.