Discuss some reasons for changing the structure of a table. Provide at least 3 unique examples and lots of details |
To add a column to a table using SQL, we specify that we want to change the table structure via the ALTER TABLE command, followed by the ADD command to tell the RDBMS that we want to add a column.
Syntax
The SQL syntax for ALTER TABLE Add Column is,
ALTER TABLE "table_name"
ADD "column_name" "Data Type";
Examples
Let's look at the example. Assuming our starting point is the Customer table created in the CREATE TABLE section:
Table Customer
Column Name | Data Type |
First_Name | char(50) |
Last_Name | char(50) |
Address | char(50) |
City | char(50) |
Country | char(25) |
Birth_Date | datetime |
Example 1: Add one column to a table
Our goal is to add a column called "Gender". To do this, we key in:
MySQL:
ALTER TABLE Customer ADD Gender char(1);
Oracle:
ALTER TABLE Customer ADD Gender char(1);
SQL Server:
ALTER TABLE Customer ADD Gender char(1);
The resulting table structure is:
Table Customer
Column Name | Data Type |
First_Name | char(50) |
Last_Name | char(50) |
Address | char(50) |
City | char(50) |
Country | char(25) |
Birth_Date | datetime |
Gender | char(1) |
Sometimes we need to change the data type of a column. To do this, we use the ALTER TABLE Modify Column command. For Oracle and MySQL, the SQL syntax for ALTER TABLE Modify Column is,
ALTER TABLE "table_name"
MODIFY "column_name" "New Data Type";
For SQL Server, the syntax is,
ALTER TABLE "table_name"
ALTER COLUMN "column_name" "New Data Type";
Let's look at the example. Assuming our starting point is the Customer table created in the CREATE TABLE section:
Table Customer
Column Name | Data Type |
First_Name | char(50) |
Last_Name | char(50) |
Address | char(50) |
City | char(50) |
Country | char(25) |
Birth_Date | datetime |
Our goal is to alter the data type of the "Address" column to char(100). To do this, we key in:
MySQL:
ALTER TABLE Customer MODIFY Address char(100);
Oracle:
ALTER TABLE Customer MODIFY Address char(100);
SQL Server:
ALTER TABLE Customer ALTER COLUMN Address char(100);
Resulting table structure:
Table Customer
Column Name | Data Type |
First_Name | char(50) |
Last_Name | char(50) |
Address | char(100) |
City | char(50) |
Country | char(25) |
Birth_Date | datetime |
Sometimes we will wish to delete a column from an existing table in SQL. To do this, we specify that we want to change the table structure via the ALTER TABLE command, followed by a specification indicating that we want to remove a column. The detailed syntax for each database is as follow:
In MySQL, the syntax for ALTER TABLE Drop Column is,
ALTER TABLE "table_name"
DROP "column_name";
In Oracle and SQL Server, the syntax for ALTER TABLE Drop Column is,
ALTER TABLE "table_name"
DROP COLUMN "column_name";
Let's look at the example. Assuming our starting point is the Customer table created in the CREATE TABLE section:
Table Customer
Column Name | Data Type |
First_Name | char(50) |
Last_Name | char(50) |
Address | char(50) |
City | char(50) |
Country | char(25) |
Birth_Date | datetime |
Our goal is to drop the "Birth_Date" column. To do this, we key in:
MySQL:
ALTER TABLE Customer DROP Birth_Date;
SQL Server:
ALTER TABLE Customer DROP COLUMN Birth_Date;
Oracle:
ALTER TABLE Customer DROP COLUMN Birth_Date;
The resulting table structure is:
Table Customer
Column Name | Data Type |
First_Name | char(50) |
Last_Name | char(50) |
Address | char(50) |
City | char(50) |
Country | char(25) |
Discuss some reasons for changing the structure of a table. Provide at least 3 unique examples...
Discuss some reasons for changing the structure of a table. Provide at least 3 unique examples and lots of details
1. Discuss some differences between a service business and a merchandising business. Provide unique examples of each in your discussion. Are there some businesses that incorporate both approaches and have products and services? If so, provide examples of these also. 2. Define Cost of Merchandise Sold in the context of an example of a business. In other words, define it by illustrating it as it pertains to a business you have chosen. As always, make your choice unique from your...
Provide/discuss some examples where the application of traveling salesman or vehicle routing methods can improve the transportation efficiency. (Unique, Within 200-250 Words, No Handwriting Please)
Discuss Sarbanes-Oxley and the Five Elements of Internal Control. Provide a substantive response. Include unique examples and specific illustrations
discuss the main features of the clinton health care reform plan, provide some reasons why it was not enacted.
Discuss the the potential competitive advantage in seeking accreditation or certification. Provide some examples of the certification that you would like to pursue.
Provide at least two examples of respiratory airway diseases. Discuss the causes and clinical management both medical and nursing perspective.
What are some drivers of the Shared Value Mindset? Provide at least 2 examples and justification.
describe 3 reasons why psychologists are interested in classical conditioning and provide examples.
Identify three (3) reasons why individuals create new business ventures. Next discuss any goals or motives that would drive you to become an entrepreneur. Provide examples for your response. Discuss at least (3) fundamental drivers for establishing a new venture then share two (2) common sources that provide the ideas for these business opportunities. Be sure to support your response.