Databases Flashcards

1
Q

What’s the select statement used for?

A

The select statement is used to query the database and retrieve selected data that match the criteria that you specify.

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

Give an example of a select statement

A
select "column1"
  [,"column2",etc] 
  from "tablename"
  [where "condition"];
  [] = optional
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is some of the syntax around columns?

A

The column names that follow the select keyword determine which columns will be returned in the results. You can select as many column names that you’d like, or you can use a “*” to select all columns.

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

How do you select what table to draw results from?

A

The table name that follows the keyword from specifies the table that will be queried to retrieve the desired results.

select “column1”
[,”column2”,etc]
from “tablename” (

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

What does the where keyword do?

A
The where clause (optional) specifies which data values or rows will be returned or displayed, based on the criteria described after the keyword where.
Conditional selections used in the where clause:
=	Equal
>	Greater than
<	Less than
>=	Greater than or equal
<=	Less than or equal
<>	Not equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the LIKE condition do when it follows the where keyword?

A

The LIKE pattern matching operator can also be used in the conditional selection of the where clause. Like is a very powerful operator that allows you to select only rows that are “like” what you specify. The percent sign “%” can be used as a wild card to match any possible character that might appear before or after the characters specified.

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

Give some examples of how to use the LIKE condition

A

select first, last, city
from empinfo
where first LIKE ‘Er%’;

This SQL statement will match any first names that start with 'Er'. Strings must be in single quotes.
Or you can specify;
select first, last
   from empinfo
   where last LIKE '%s';

This statement will match any last names that end in a ‘s’.

select * from empinfo
where first = ‘Eric’;

This will only select rows where the first name equals ‘Eric’ exactly.

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

How do you use the create table statement?

A
The create table statement is used to create a new table. Here is the format of a simple create table statement:
create table "tablename"
("column1" "data type",
 "column2" "data type",
 "column3" "data type");
Format of create table if you were to use optional constraints:
create table "tablename"
("column1" "data type" 
         [constraint],
 "column2" "data type" 
         [constraint],
 "column3" "data type" 
        [constraint]);
 [ ] = optional
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the most common data types used in tables?

A

char(size)-Fixed-length character string. Size is specified in parenthesis. Max 255 bytes.
varchar(size)-Variable-length character string. Max size is specified in parenthesis.
number(size) Number value with a max number of column digits specified in parenthesis.
date-Date value
number(size,d)-Number value with a maximum number of digits of “size” total, with a maximum number of “d” digits to the right of the decimal.

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

Give an example of how you’d create a table

A
create table employee
(first varchar(15),
 last varchar(20),
 age number(3),
 address varchar(30),
 city varchar(20),
 state varchar(20));

To create a new table, enter the keywords create table followed by the table name, followed by an open parenthesis, followed by the first column name, followed by the data type for that column, followed by any optional constraints, and followed by a closing parenthesis. It is important to make sure you use an open parenthesis before the beginning table, and a closing parenthesis after the end of the last column definition. Make sure you separate each column definition with a comma. All SQL statements should end with a “;”.

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

What are constraints?

A

When tables are created, it is common for one or more columns to have constraints associated with them. A constraint is basically a rule associated with a column that the data entered into that column must follow. For example, a “unique” constraint specifies that no two records can have the same value in a particular column. They must all be unique. The other two most popular constraints are “not null” which specifies that a column can’t be left blank, and “primary key”. A “primary key” constraint defines a unique identification of each record (or row) in a table.

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

What is the insert statement used for?

A

The insert statement is used to insert or add a row of data into the table.

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

How do you use the insert statement?

A

To insert records into a table, enter the key words insert into followed by the table name, followed by an open parenthesis, followed by a list of column names separated by commas, followed by a closing parenthesis, followed by the keyword values, followed by the list of values enclosed in parenthesis. The values that you enter will be held in the rows and they will match up with the column names that you specify. Strings should be enclosed in single quotes, and numbers should not.

insert into “tablename”
(first_column,…last_column)
values (first_value,…last_value);

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

Give an example of how you’d use the insert statement

A

insert into employee
(first, last, age, address, city, state)
values (‘Luke’, ‘Duke’, 45, ‘2130 Boars Nest’,
‘Hazard Co’, ‘Georgia’);
Note: All strings should be enclosed between single quotes: ‘string’

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

What does the update statement do?

A
The update statement is used to update or change records that match a specified criteria. This is accomplished by carefully constructing a where clause.
update "tablename"
set "columnname" = 
    "newvalue"
 [,"nextcolumn" = 
   "newvalue2"...]
where "columnname" 
  OPERATOR "value" 
 [and|or "column" 
  OPERATOR "value"];

[] = optional

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

Give an example of how you’d use update

A

update phone_book
set area_code = 623
where prefix = 979;

update phone_book
set last_name = ‘Smith’, prefix=555, suffix=9292
where last_name = ‘Jones’;

update employee
set age = age+1
where first_name=’Mary’ and last_name=’Williams’;

17
Q

What does the delete statement do?

A

The delete statement is used to delete records or rows from the table.

delete from "tablename"
where "columnname" 
  OPERATOR "value" 
[and|or "column" 
  OPERATOR "value"];
[ ] = optional
18
Q

Give an example of how you’d use the delete statement

A

delete from employee
where lastname = ‘May’;

delete from employee
where firstname = ‘Mike’ or firstname = ‘Eric’;

To delete an entire record/row from a table, enter “delete from” followed by the table name, followed by the where clause which contains the conditions to delete. If you leave off the where clause, all records will be deleted.

19
Q

What is SQL?

A

Structured Query Language (SQL) is a specialized programming language for manipulating databases

20
Q

Define table

A

A method for implementing an entity ad attributes as a group of related data

21
Q

define query

A

a search or sort carried out on data that retrieves the answer to a question

22
Q

Define client-server database

A

When a database is implementing on a server so multiple users can access it from their workstations. The processing, for example a query, will take place on the server.

23
Q

What does DBMS mean?

A

Database management system (DBMS) software that enables the management of all aspects of a database including adding, updating and querying data

24
Q

What is a common problem with shared databases?

A

If two people are trying to update the database at the same time this can cause issues when they try to save data in the same location. The first person to save data will save it in the location then when the second person saves it will overwrite the first persons data.

25
Q

What are some solutions to having multiple users write to the same database?

A

Record locks - a technique used to lock the second user who tries to access a data file to a read-only version.

Serialization - a technique to ensure that only one transaction can take place at a time.

Timestamp ordering - Every transaction that takes place on a database is given a timestamp. This timestamp is used to work out if the current transaction should be complete.

Commitment ordering - Looks at both the time the command was made and whether an action has precedence over other commands. If two commands are made at the same time the one that has precedence over the other will take place first

26
Q

What is a relational databases?

A

a method of creating a database using related tables, with relationships between the tables.

27
Q

Define entity

A

An object which data is stored about.

28
Q

What is an attribute?

A

A characteristic or piece of information about an entity which would be stored as a field in relation to a database.

29
Q

What is an entity relationship diagram?

A

A visual method of describing relationships between entities.
A single line means one. A bird foot meant many.

30
Q

Define primary key

A

An attribute used to uniquely identify every record within a table.

31
Q

Define entity identifier

A

An attribute which can uniquely identify each instance of an entity.

32
Q

define foreign key

A

A primary key in another table used to link tables together.

33
Q

what is normalization?

A

The process of ensuring that a relational database is structured efficiently. ( no redundant data)

34
Q

How s first normal format (1NF) achieved?

A

It is achieved by ensuring that a table doesn’t contain repeating attributes or repeating groups and that all data in a table is atomic (all of it’s their or none of it is).

35
Q

How s second normal format (2NF) achieved?

A

second normal format is achieved by getting the table/database to first normal format and then removing attributes that depend upon part or all of the primary key by creating additional tables.

36
Q

How s third normal format (3NF) achieved?

A

By getting the database to second normal format and then removing non-key attributes that depend on other non-key attributes by creating additional tables.

37
Q

What characteristics must a database have to be fully normalized?

A
  • All of the data must be atomic/ no repeating groups / no repeating attributes
  • There should be no partial dependencies, where a non-key attribute depends upon part nut not all of the primary key
  • There should be no non-key dependencies, where a non-key attribute depends upon another non-key attribute.