Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 754 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Altering a column: null to not null

#11
You will have to do it in two steps:

1. Update the table so that there are no nulls in the column.

<!---->

UPDATE MyTable SET MyNullableColumn = 0
WHERE MyNullableColumn IS NULL

2. Alter the table to change the property of the column

<!---->

ALTER TABLE MyTable
ALTER COLUMN MyNullableColumn MyNullableColumnDatatype NOT NULL

Reply

#12
You can change the definition of existing DB column using following sql.

ALTER TABLE mytable modify mycolumn datatype NOT NULL;
Reply

#13
Let's take an example:

TABLE NAME=EMPLOYEE

And I want to change the column `EMPLOYEE_NAME` to `NOT NULL`. This query can be used for the task:

ALTER TABLE EMPLOYEE MODIFY EMPLOYEE.EMPLOYEE_NAME datatype NOT NULL;
Reply

#14
First, make all current `NULL` values disappear:

UPDATE [Table] SET [Column]=0 WHERE [Column] IS NULL

Then, update the table definition to disallow "NULLs":

ALTER TABLE [Table] ALTER COLUMN [Column] INTEGER NOT NULL
Reply

#15
1. First make sure the column that your changing to not does not have null values
select count(*) from table where column's_name is null

2. Impute the missing values. you can replace the nulls with empty string or 0 or an average or median value or an interpolated value. It depends on your back fill strategy or forward fill strategy.

3. Decide if the column values need to be unique or non-unique. if they need to be unique than add an unique constraint. Otherwise, see if performance is adequate or if you need to add an index.

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through