Chap 9 - databases, SQL Flashcards
define database
-structured collection of data that can be modified
-can have many tables in it
3 uses of storing on a databases & eg
1) people info
-patients in hospital
-students in skl
2) things info
-books in library
-cars sold
3) events info
-hotel booking
race results
define flat files
a simple table with fields and records and it not related to other databases
the problem with flat files
when data is changed in a file, it is not reflected in another
-causes confusion & inconsistency
solution to flat file (advantages over them)
-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
format of a database
-tabular structure
-field - table with 1 type of info
records - row of all data on a person/ thing
field field field
info info info
data types in tables compared to python
text - string
character - character
boolean - boolean
integer - integer
real - float
data/ time eg. 2/2/12
uses of data types
-all field need a data type to classify how to store, display and perform operation on it
define primary key & its use
-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 do you get a foreign key
-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
what would happen without primary key
-insertion issues - rows are uniquely identified
-updating issues
what is SQL
Structed Query Language
note: about SQL
-case insensitive
-no need indentation
- , separates items
-end each command with ;
-anything that is text, except command words, in “ “
command words for SQL
-create database
-drop database
-create table
-insert into
-select ___ from
-where
-sum
-count
-order by
how to create database
create database database name;