This shows the tables I have in the donor database. Note that I have a table also named donor. Probably not a great idea from a person’s point of view, but the system has no problem.
Notice the types that I used here – I actually prefer varchar rather than char because varchar does not have the spaces added after the data. However, in this example I used char. I also used float to express a field that is not an integer but has 2 decimal places. I used date for a date field – note how the date is stored. In the example below, I used varchar.
Now I am going to insert a record and then I am going to delete the record I inserted. Note that you can use drop followed by the name of the table to drop a whole table – I did not illustrate it here – be careful!
Now I want to change the address of Al Richards and make it 111 East St. Note that his id is 44444.
This shows the update command and the updated record.
In this example I am saying that the contact has to be John Smith and either the state has to be MA or the yrgoal has to be greater than 500. Both of the records that are shown have a contact of John Smith so I continue on to check to see if they either have a state = ‘RI’ or yrgoal > 500. The records shown do not have a yrgoal greater than 500 but they do have a state of MA.
The % can be used to stand for any number of characters so I want something that starts with J.
In this example, I needed to use is not null so I got an error.
SQL has a series of functions you can use such as sum, avg and count.
Now I am sorting. First I sorted on just yrgoal and then I sorted first by state and then within state I sorted by yrgoal. In the examples below, I used desc to make the sort in descending order. Note that desc applies to just the element it follows.