GETTING STARTED WITH A DATABASE Each row contains (Affordable web design)
Thursday, March 27th, 2008GETTING STARTED WITH A DATABASE Each row contains an individual record of related data. The significance of primary keys is explained in the next section. The intersection of a row and a column, where the data is stored, is called a field. So, for instance, the caption field for the third record in Figure 11-1 contains the value The Golden Pavilion in Kyoto and the primary key for that record is 3. The terms field and column are often used interchangeably, particularly by phpMyAdmin. A field holds one piece of information for a single record, whereas a column contains the same field for all records. How primary keys work Although Figure 11-1 shows image_id as a consecutive sequence from 1 to 8, they re not row numbers. Figure 11-2 shows the same table with the captions sorted in alphabetical order. The field highlighted in Figure 11-1 has moved to the seventh row, but it still has the same image_id and filename. Figure 11-2. Even when the table is sorted in a different order, each record can be identified by its primary key. Although the primary key is rarely displayed, it identifies the record and all the data stored in it. Once you know the primary key of a record, you can update it, delete it, or use it to display data in a separate page. Don t worry about how you find the primary key. You ll see in the next chapter that it s easily done using Structured Query Language (SQL), the standard means of communicating with all major databases. The important thing to remember is that you should assign a primary key to every record. A primary key doesn t need to be a number, but it must be unique. Social security, staff ID, or product numbers make good primary keys. They may consist of a mixture of numbers, letters, and other characters, but are always dif ferent. MySQL will generate a primary key for you automatically. Once a primary key has been assigned, it should never repeat, never be changed. 287
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.