We describe the WFCAM Science Archive (WSA), which is the primary point of access for users of data from the wide-field infrared camera WFCAM on the United Kingdom Infrared Telescope (UKIRT), especially science catalogue products from the UKIRT Infrared Deep Sky Survey (UKIDSS). We describe the database design with emphasis on those aspects of the system that enable users to fully exploit the survey datasets in a variety of different ways. We give details of the database-driven curation applications that take data from the standard nightly pipeline-processed and calibrated files for the production of science-ready survey datasets. We describe the fundamentals of querying relational databases with a set of astronomy usage examples, and illustrate the results.