Question

In: Computer Science

1. Using the alter table command, add a new column named gender making sure that only...

1. Using the alter table command, add a new column named gender making sure that only values of M, F or O are allowed.

2. Modify the data in the customers table to change the state for customers with ID number 2, 4, and 5 to NV.

3. Create a sequence that starts with -100 and increments by 10. Show the first value of the sequence.

4. Create a table named MYDATA with the following columns: id (primary key) and name. Use your sequence created in question 28 to insert 2 rows for the table. Make up your own data for name.

5. Create an index on the CANDIDATE table on the upper-case values of the last name column.

Solutions

Expert Solution

#############################################################################

Answer to Question 1

Two step answer to this is

Step 1 : Create a sample table first, In this case we are creating a table named "alterexample" with id,firstname,lastname and birthday as keys

Step 2 : Alter the table "alterexample" to add the gender column, allowing valid values 'M','F' & 'O'

Code Snippet for Step 1 in Question 1

#*********MYSQL CODE SNIPPET STARTS HERE *************

CREATE TABLE alterexample
( id INT(11) NOT NULL AUTO_INCREMENT,
last_name VARCHAR(30) NOT NULL,
first_name VARCHAR(25),
birthday DATE,
CONSTRAINT id_pk PRIMARY KEY (id)
);

#*********MYSQL CODE SNIPPET ENDS HERE *************

Code Snippet for Step 2 in Question 1

#*********MYSQL CODE SNIPPET STARTS HERE *************

ALTER TABLE alterexample
ADD COLUMN gender enum('M','F','O') AFTER first_name;

#*********MYSQL CODE SNIPPET ENDS HERE *************

##############################################################################

Answer to Question 2

#The assumptions made are table name is "customer" the column name is "state"

#*********MYSQL CODE SNIPPET ENDS HERE *************

update customer
SET state = 'NV'
WHERE customer_id IN (2,4,5)

#*********MYSQL CODE SNIPPET ENDS HERE *************

##############################################################################

##############################################################################

Answer to Question 3

#Creating a sequence for the customer table created in the question 2

#*********MYSQL CODE SNIPPET BEGINS HERE *************

SELECT @mysequence:=-110;
SELECT *, @mysequence:=@mysequence+10 AS mysequence FROM customer ORDER BY state;

#*********MYSQL CODE SNIPPET ENDS HERE *************

##################################################################

Answer to Question 4

Step1 : Create the table

Step 2 : Use the sequence to load the table

Step 1 : Create the MYDATA table

#*********MYSQL CODE SNIPPET ENDS HERE *************
CREATE TABLE MYDATA
( id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
CONSTRAINT id_pk PRIMARY KEY (id)
);

#*********MYSQL CODE SNIPPET ENDS HERE *************

#*********MYSQL CODE SNIPPET STARTS HERE *************

INSERT INTO MYDATA
SELECT @mysequence:=@mysequence+10 AS id, last_name AS name FROM customer where state = 'AZ' ORDER BY state

#*********MYSQL CODE SNIPPET ENDS HERE *************

##################################################################

Answer to Question 5

#*********MYSQL CODE SNIPPET STARTS HERE *************
CREATE TABLE candidate
( candidate_id INT(11) NOT NULL AUTO_INCREMENT,
last_name VARCHAR(30) NOT NULL,
first_name VARCHAR(25),
birthday DATE,
CONSTRAINT candidate_pk PRIMARY KEY (candidate_id)
);

create index upper_col1 on candidate ( (upper(last_name)) )

#*********MYSQL CODE SNIPPET ENDS HERE *************

##################################################################


Related Solutions

Using only the spring gun with the catcher removed, fire the steel ball, making sure the...
Using only the spring gun with the catcher removed, fire the steel ball, making sure the launch velocity is horizontal. Using carbon paper (and something to catch the ball after impact with the floor), determine the ball’s horizontal range and its total vertical displacement (i.e., height at point of firing). Repeat several times in order to obtain statistical data. Derive a formula in symbolic form for the initial velocity of the projectile in terms of the following three quantities only:...
Using the table and symbol functions in MSWORD, solve the following proof, making sure to number...
Using the table and symbol functions in MSWORD, solve the following proof, making sure to number and justify each line of the proof (including listing premises). (∀x)(∀y)Pxy ⊢(Ǝx)(Ǝy)Pxy
1. Write three command statements to back up the `Orders` Table for data only, structure with...
1. Write three command statements to back up the `Orders` Table for data only, structure with data and structure only using mysqldump. 2. Write the command statement to import the data using mysqlimport from customers.csv file. 3. What's the difference to use the LOAD DATA LOCAL INFILE vs mysqlimport. 4. Write SQL statements: a. Create a database user "cis495_dev1" with password "dolphins". b. Create the database "cis495Demo". c. Grant user "cis495_user1" with "select" ,"delete" and "execute" permission to DB "cis495Demo"....
Question 1.​ Answer the following questions by making a truth table. Be sure to explain what...
Question 1.​ Answer the following questions by making a truth table. Be sure to explain what feature of the truth table you’ve drawn justifies your answer. (That is, indicate which part, or parts, of the table show what the answer to the question is and why) a) Is ¬P, P ↔ Q, P → Q a logically consistent set of sentences? b) Is A ∧ (B ∨ C), ¬((A ∨ B) ∧ C) a logically consistent set of sentences? c)...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence”...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence” with the following attributes (columns): A field named “id” which has data type auto_increment, A field named “country_name” which has data type varchar(50), and A field named “independence_date” which has type “date.” After you create the table, run the following SQL command: INSERT INTO independence(country_name, independence_date) VALUE (‘United States’,’1776-07-04’) Submit a 1-page Microsoft Word document that shows the following: The SQL command you used...
1. Show how to redirect the standard output of the date command to a file named...
1. Show how to redirect the standard output of the date command to a file named currentdate. 2. Continuing from the previous question: Show how to append the standard output of the who command to the file currentdate. 3. The password file (/etc/passwd) contains one line for each userid registered with the system. Show how to display the number of userids in the passwd file on the screen. 4. Employ a pipe to combine the who and the wc commands...
Create a new table named CUSTOMER_STATUS.The table will hold the Customer_Status_Id and the Customer_Status_Description with possible...
Create a new table named CUSTOMER_STATUS.The table will hold the Customer_Status_Id and the Customer_Status_Description with possible values: Inactive, Active, Very_Active These values will be used to characterize the customers so that:                   Inactive Customers => Have 0 orders                   Active Customers => Have between 1 and 3 orders Very Active Customers => Have 4 or more orders
Using MongoDB, what command would you enter to retrieve this document using only the zip code...
Using MongoDB, what command would you enter to retrieve this document using only the zip code 11242? db.inspections.find(???????) Database: city Collection: inspections {"_id":{"$oid":"56d61033a378eccde8a898ae"}, "id":"23536-2015-ENFO", "certificate_number":5373970, "business_name":"NZO CORP.", "date":"Apr 22 2015", "result":"Violation Issued", "sector":"Grocery-Retail - 808", "address":{"city":"BROOKLYN", "zip":11242, "street":"COURT ST", "number":26}}
Consider the following contingency table that is based on a sample survey. Column 1 Column 2...
Consider the following contingency table that is based on a sample survey. Column 1 Column 2 Column 3 Row 1 136 90 83 Row 2 96 54 88 Row 3 125 75 110 a. Write the null and alternative hypotheses for a test of independence for this table. H 0 : Rows and columns are ; H 1 : Row and columns are . b. Calculate the expected frequencies for all cells assuming that the null hypothesis is true. Round...
Consider the following contingency table that is based on a sample survey. column 1 column 2...
Consider the following contingency table that is based on a sample survey. column 1 column 2 column 3 row 1 137 86 77 row 2 93 51 86 row 3 126 76 112 a. Write the null and alternative hypotheses for a test of independence for this table. H0: Rows and columns are: Independent or dependent H1: Rows and columns are: Independent or dependent b. Calculate the expected frequencies for all cells assuming that the null hypothesis is true. Round...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT