Wednesday, 15 April 2015

Drop a Table

The drop table command is used to delete a table and all rows in the table. To delete an entire table including all of its rows, issue the drop tablecommand followed by the tablename. drop table is different from deleting all of the records in the table. Deleting all of the records in the table leaves the table including column and constraint information. Dropping the table removes the table definition as well as all of its rows. drop table "tablename" Example: drop table myemployees_ts0211; Drop Table exercises Drop...

Deleting Records

The delete statement is used to delete records or rows from the table. delete from "tablename" where "columnname" OPERATOR "value" [and|or "column" OPERATOR "value"]; [ ] = optional [The above example was line wrapped for better viewing on this Web page.] Examples: delete from employee; Note: if you leave off the where clause, all records will be deleted! delete from employee where lastname = 'May'; delete from employee where firstname = 'Mike' or firstname = 'Eric'; To delete an entire record/row from a table,...

Updating Records

The update statement is used to update or change records that match a specified criteria. This is accomplished by carefully constructing a where clause. update "tablename" set "columnname" = "newvalue" [,"nextcolumn" = "newvalue2"...] where "columnname" OPERATOR "value" [and|or "column" OPERATOR "value"]; [] = optional [The above example was line wrapped for better viewing on this Web page.] Examples: update phone_book set area_code = 623 where prefix = 979; update phone_book set last_name = 'Smith', prefix=555,...

Inserting into a Table

The insert statement is used to insert or add a row of data into the table. To insert records into a table, enter the key words insert into followed by the table name, followed by an open parenthesis, followed by a list of column names separated by commas, followed by a closing parenthesis, followed by the keyword values, followed by the list of values enclosed in parenthesis. The values that you enter will be held in the rows and they will match up with the column names that you specify. Strings should be enclosed in...

Creating Tables

Creating Tables The create table statement is used to create a new table. Here is the format of a simple create table statement: create table "tablename" ("column1" "data type", "column2" "data type", "column3" "data type"); Format of create table if you were to use optional constraints: create table "tablename" ("column1" "data type" [constraint], "column2" "data type" [constraint], "column3" "data type" [constraint]); [ ] = optional Note: You may have as many columns as you'd like,...

Selecting Data

The select statement is used to query the database and retrieve selected data that match the criteria that you specify. Here is the format of a simple select statement: select "column1" [,"column2",etc] from "tablename" [where "condition"]; [] = optional The column names that follow the select keyword determine which columns will be returned in the results. You can select as many column names that you'd like, or you can use a "*" to select all columns. The table name that follows the keyword from specifies the table...

Table Basics

A relational database system contains one or more objects called tables. The data or information for the database are stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows. Columns contain the column name, data type, and any other attributes for the column. Rows contain the records or data for the columns. Here is a sample table called "weather". city, state, high, and low are the columns. The rows contain the data for this table: Weather citystatehighlow PhoenixArizona10590 TucsonArizona10192 FlagstaffArizona8869 San...