Primary Key Each table should include a primary key that uniquely identifies each record stored in the table such as an Employee ID. - A table contains only 1 primary key. - A primary key can be composed of 1 or many fields. - A primary key is used to distinguish a record from another. - A primary key is used to speed up searching for records. - A primary key is unique, it doesn t contain repetitive values. - A primary key can accept the value 0. - A primary Key cannot be empty. - A primary key can have the following types: Text, Number or Autonumber - A primary key has an indexed: Yes (No duplicates). Foreign Key You can include the primary key fields in other tables to refer back to the table that is the source of the primary key. In those other tables, the fields are called foreign key or secondary keys. - A foreign key is related to the primary key in another table. - A foreign key contains repetitive values. - A foreign key can be unique. - A foreign key can have the type: Text or number. - A foreign key cannot be autonumber. - A Foreign Key has an Indexed: yes (duplicates ok). Informatics Access - 1 -
Practice 6 - Total Queries Given the following table: Factory (Factory code, name, location, number of employees) Product (Product code nom, price, factory code) Supplier (Supplier code, name) Supply (Product code, Supplier code, supplied quantity) Display the maximum price of all products. Field Table Total Price Product Max Display the minimum price of each supplier. (each supplier means: group by on the primary key of the table supplier) Field Price Supplier code Table product Supplier Total Min Group by Display the Total (sum) price of the supplier / whose name is Roy. (Note: if you have a criteria without a show, we use where instead group by) Field Price Name Table Product Supplier Total Sum where Roy Informatics Access - 2 -
Extra query Display the Total (sum) price and the name of supplier of the supplier/ whose name is Roy. (Note: if you have a criteria with a show, we use Group by) Field Price Name Table Product Supplier Total Sum Group by Roy Factory (Factory code, name, location, number of employees) Product (Product code nom, price, factory code) Supplier (Supplier code, name) Supply (Product code, Supplier code, supplied quantity) Display the Total number of products /of supplier whose name is Lara. Total number + name of table, means count on the primary key of the table. Field Product code Name Table Product Supplier Total Count where Lara Display the Total number of employees of all factories of every factory. Field Table Total Number of employees Factory sum Informatics Access - 3 -
Practice 7 Total queries Company Car Car price Rent Client (Company id, name) (Car id, name, Company id) (Car id, car price, price-day) (Client id, car id, rent date, number of days) (Client id, Name, Telephone, Address) Display total amount of clients who rent cars Audi R8 in January/2010. Field Amount: Name Rent date [number of days]*[price-day] Table Car Rent Total sum where Where Audi R8 Like */1/2010 Between 1/1/2010 and 31/1/2010 Note: Total number + name of table (count on the PK) Display the Total numbers of cars / of "BMW" company the Total numbers of cars of "Golf" company. Field Car id NAME Table car COMPANY Total Count Where BMW Golf Informatics Access - 4 -
Total number + name of field (Sum on the field) Display the total number of days /rented for the car "BMW X6" in the year 2013. Field Number of days Name Rent date Table Rent Car Rent Total Sum Where Where Bmw x6 Like */*/2013 Between 1/1/2013 and 31/12/2013 Extra query Display the total number of days and the name of car /rented for the car "BMW X6" in the year 2013. Field Number of days Name Rent date Table Rent Car Rent Total Sum Group by Where Bmw x6 Like */*/2013 Informatics Access - 5 -
Practice 8 Total queries Client Product Facture Facture detail (Client code, client name, address) (Product code, name, unit price, quantity stock) (Facture number, bill date, client code) (Facture number, product code, qty-purchase) Display the total amount of qty-purchase / of facture number 500. Field Amount: [qty-purchase]*[unit price] Facture number Table Facture Total Sum where 500 Informatics Access - 6 -