Chap 9 - databases, SQL Flashcards

1
Q

define database

A

-structured collection of data that can be added, remved, changed or updated
-can have many tables in it

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

3 uses of storing on a databases & eg

A

1) people info
-patients in hospital
-students in skl
2) things info
-books in library
-cars sold
3) events info
-hotel booking
race results

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

define flat files

A

a simple table with fields and records and it not related to other databases

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

the problem with flat files

A

when data is changed in a file, it is not reflected in another
-causes confusion & inconsistency

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

solution to flat file (advantages over them)

A

-a central database that is accessible on diff applications
-changes made by 1 app are reflected on another
-1 central database needs less memory than many databases
-access rights on who can access, edit & modify info
eg, laptop, phone

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

format of a database

A

-tabular structure
-field - table with 1 type of info
records - row of all data on a person/ thing
field field field
info info info

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

data types in tables compared to python

A

text - string
character - character
boolean - boolean
integer - integer
real - float
data/ time eg. 2/2/12

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

uses of data types

A

-all field need a data type to classify how to store, display and perform operation on it

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

define primary key & its use

A

-a field with never repeating data values
-to uniquely identify records
-usually char & no.
-automatically generated in order
eg, C1, C2
-choose data type with no repeating data

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

how do you get a foreign key

A

-when a primary key is added in a table with an already existing primary key
-the old primary key is a foreign key which can repeat
eg. primary key - no. orders, foreign key - customer id

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

what would happen without primary key

A

-insertion issues - rows are uniquely identified
-updating issues

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

what is SQL

A

Structed Query Language

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

note: about SQL
-case insensitive
-no need indentation
- , separates items
-end each command with ;
-anything that is text, except command words, in “ “

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

command words for SQL

A

-create database
-drop database
-create table
-insert into
-select ___ from
-where
-sum
-count
-order by

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

how to create database

A

create database database name;

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

how to create table

A

create table table name(
field name data type & (limit),
field name data type & (limit)
);
-comma separates fields
-add limit in ( ) depending on data type
-select database before making table
-( ) for everything before ;

17
Q

how to write data types in SQL & limit

A

text - varchar (250) - max limit is 255 so it doesn’t go over 1 byte
integer - int - no limit

18
Q

how to insert data in table

A

insert into table name (field name, field name, field name)
values
(info, info, info),
(info, info, info); -end of line so add ;
-add “ “ for varchar
-write values in order of fields
-if not enough field, remaining data is left

19
Q

how to select data in table

A

1) selecting everything: output - table, data
select * from table name;
2) select 1 field: output - specific field, data
select field name from table name;
3) select many fields: add comma after fields
select field name , field name from table name;

20
Q

how to select data based on condition in table
-comparison uses =
-uses and & or like python

A

1) 1 condition:
select _ from table name
where condition;
2) many conditions:
select _ from table name
where condition and/ or condition;
-uses operations for condition
-date after eg. date> 2010- 0- 01
eg.
select * from students
where age>10 and grade = “grade 3”;

21
Q

how to delete database

A

drop database database name;

22
Q

how to find sum

A

select sum (field name) from table name;
eg. select sum (ages) from students;
-only for integers & real
-can add condition but ; is after condition

23
Q

note: change the way you write capital Y

A
24
Q

note: the field names, tables names and data are case sensitive

A
25
Q

how to count

A

select count (field name) from table name;
eg. select count (firstname) from students;
-displays how many fields in the table
-for all data types

26
Q

diff btw sum & count

A

sum - sum of no.s
count - no. items

27
Q

how to use order by

A

select _ from students
order by field name asc/ desc ;
asc = ascending order, desc = descending order (for letters & no.s)
-after condition

27
Q

what happens if condition isn’t specified

A

-checks if there is data in that field & displays the ones with it
-eg. where age;

28
Q

which is first: condition or order by

A

condition
order by