Posts

Showing posts with the label SQL

SQL - Delete

Image
The SQL DELETE statement is used to delete row(s) of data. Suppose we have a table of students looking like this. The last row is a test record and should be deleted. Delete from tblStudent  where FirstName='TestFirst' The result is below. Notice that the action of "DELETE" is permanent. After records are deleted, they are permanently gone. Therefore, you have make sure all the criteria is correct before issuing the DELETE command.

SQL - Update

Image
The SQL UPDATE statement is used to update values of rows, columns or cells. Suppose we have a table of student looking like this. The table name is "tblStudent". Suppose we found error with the home state of the student with StudentID 1001. Suppose he is from TX, not CT. Then we use the following statement to make the change. update tblStudent set HomeState='TX' where StudentID=1001 The result is below.

SQL - Select

Image
Suppose we have a table of student looking like this. The table name is "tblStudent". 1. Select all cases and all columns Select * from tblStudent SQL is case-insensitive, which means that "select", "Select" and "SELECT" are all equivalent. The "*" in the above SQL statement means selecting all columns. The result is below. 2. Select specific columns Select StudentID, FirstName, LastName from tblStudent The result is below. 3. Generate new fields in the displayed result Select  StudentID,  FirstName+ ' '+ LastName as FullName,  TotalScore/3 as AvgScore  from tblStudent The result is below. 4.  Select with a criteria Here we want to select all cases with TotalScore is at or above 200. Select * from tblStudent where TotalScore>=200 The result is below. The criteria can contain multiple conditions, such as: Select * from tblStudent where TotalScore>=200 and Math>70 5. Select with ordered result Select * from tblStudent ord...