Question

In: Computer Science

How do I start to code in mysql to Alter table to modify column remove not...

How do I start to code in mysql to Alter table to modify column

remove not null constraint

First drop the foreign key associated with

Drop the column

Add the column back with new definition

Add the foreign key back

This Is what I wrote so far

alter table employees modify column repotsTo remove null:

Solutions

Expert Solution

  1. To remove the NOT NULL contraints, you need to identify the following:
    • Foreign Key Contraint on Table Employees
      Lets assume that the Foreign Key constraint name is "fk",
    • Name of the column and table name of the other table which the foreign key is bound to. (replace <Table Name> and <column_name> with these values in last part, Make sure you keep the () in the line. )
    • Datatype of the column reportsT, use the below code to get the datatype(I am assuming its varchar(255))

      SELECT DATA_TYPE 
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE 
           TABLE_NAME = 'employees' AND 
           COLUMN_NAME = 'reportsTo'
      
  2. Now, drop the Foreign Key Constraint,
    ALTER TABLE `employees`
            DROP FOREIGN KEY `fk`;
    
  3. Now, Drop the Column,
    ALTER TABLE `employees` DROP `reportsTo`;
  4. Add the column back,
    ALTER TABLE `employees` ADD `reportsTo` varchar(255);
  5. Add the foreign key back
    ALTER TABLE employees ADD CONSTRAINT fk FOREIGN KEY (reportsTo) REFERENCES <Table Name>(<column_name>);


Related Solutions

If there are 32 concurrent processes, how will you modify the following code? Process i do...
If there are 32 concurrent processes, how will you modify the following code? Process i do { while (turn == j);                critical section; turn = j;                remainder section } while (true);
How do I go back to the start of the main method with the given code?...
How do I go back to the start of the main method with the given code? Hello I am making this java program and there is a point in the code where if the user types the character y it will start the program back at the beginning of the main method. How can I do this without drastically changing the code? For instance, if I type y, the program will go back to line 1 and repeat the entire...
How do i remove the decimals out of the output? Do I need to int a...
How do i remove the decimals out of the output? Do I need to int a new value, or use Math.round? import java.util.Scanner; public class Main { public static void main(String[] args) { double numbers[] = new double[5];    inputArray(numbers); maxNumber(numbers); minNumber(numbers); }    public static void inputArray( double[] numbers) { Scanner in = new Scanner(System.in);    for(int i = 0; i < numbers.length; i++) { numbers[i] = in.nextDouble(); } }    public static void maxNumber(double[] numbers) { double maxNum...
how do i start with this question
how do i start with this question
How can I write java program code that do reverse, replace, remove char from string without...
How can I write java program code that do reverse, replace, remove char from string without using reverse, replace, remove method. Only string method that I can use are length, concat, charAt, substring, and equals (or equalsIgnoreCase).
modify code to write the output as an HTML table to a file in the output...
modify code to write the output as an HTML table to a file in the output directory. The file that is saying to work at : SOURCE CODE IN PERL: print "Enter principal amount: "; $P=; while($P<=0) { print "Principal must be positive. Try again: "; $P=; } print "Enter number of times interest is applied in a year: "; $n=; while($n!=12 && $n!=4 && $n!=2 && $n!=1) { print "It must be 12, 4, 2 or 1. Try again:...
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...
This is in Python: Alter your code for previous Do It Now problem, with the change...
This is in Python: Alter your code for previous Do It Now problem, with the change that the row should only be printed by the second number that the user enters. For example, the user enters two numbers of 5 and 7 for the two input lines in the code, and the following will be printed: 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 =...
look this code is a correct but i want modify it to allow the client to...
look this code is a correct but i want modify it to allow the client to have three attempts to login to the server package hw2; import java.net.*; import java.util.Formatter; import java.util.Random; import java.util.Scanner; import java.io.*; public class Client {    Socket server;    int port;    Formatter toNet = null;    Scanner fromNet = null;    Scanner fromUser = new Scanner(System.in);    public Client() {        try {            // login at server at local host...
look this code is a correct but i want modify it to allow the client to...
look this code is a correct but i want modify it to allow the client to have three attempts to login to the server package hw2; import java.net.*; import java.util.Formatter; import java.util.Random; import java.util.Scanner; import java.io.*; public class Client {    Socket server;    int port;    Formatter toNet = null;    Scanner fromNet = null;    Scanner fromUser = new Scanner(System.in);    public Client() {        try {            // login at server at local host...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT