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:
  • 691 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Altering column size in SQL Server

#1
How to change the column size of the `salary` column in the `employee` table from `numeric(18,0)` to `numeric(22,5)`

Reply

#2
alter table Employee alter column salary numeric(22,5)
Reply

#3
Running `ALTER COLUMN` without mentioning attribute `NOT NULL` will result in the column being changed to nullable, if it is already not. Therefore, you need to first check if the column is nullable and if not, specify attribute `NOT NULL`. Alternatively, you can use the following statement which checks the nullability of column beforehand and runs the command with the right attribute.

IF COLUMNPROPERTY(OBJECT_ID('Employee', 'U'), 'Salary', 'AllowsNull')=0
ALTER TABLE [Employee]
ALTER COLUMN [Salary] NUMERIC(22,5) NOT NULL
ELSE
ALTER TABLE [Employee]
ALTER COLUMN [Salary] NUMERIC(22,5) NULL
Reply

#4
ALTER TABLE [table_name] ALTER COLUMN [column_name] varchar(150)
Reply

#5
ALTER TABLE [Employee]
ALTER COLUMN [Salary] NUMERIC(22,5) NOT NULL
Reply

#6
Interesting approach could be found here: [How To Enlarge Your Columns With No Downtime by spaghettidba](

[To see links please register here]

)

> If you try to enlarge this column with a straight “ALTER TABLE” command, **you will have to wait for SQLServer to go through all the rows and write the new data type**

> ALTER TABLE tab_name ALTER COLUMN col_name new_larger_data_type;
> To overcome this inconvenience, there is a magic column enlargement pill that your table can take, and it’s called **Row Compression.** (...)
> With Row Compression, your fixed size columns can use only the space needed by the smallest data type where the actual data fits.

When table is compressed at `ROW` level, then `ALTER TABLE ALTER COLUMN` is metadata only operation.
Reply

#7
You can use `ALTER` command to modify the table schema.

The syntax for modifying the column size is

ALTER table table_name modify COLUMN column_name varchar (size);
Reply

#8
ALTER TABLE "Employee" MODIFY ("Salary" NUMERIC(22,5));
Reply

#9
For Oracle For Database:

`ALTER TABLE table_name MODIFY column_name VARCHAR2(255 CHAR);`
Reply

#10
In this case, you need to use ALTER TABLE statement to increase column size.

Here is the syntax for it

ALTER TABLE table_name
MODIFY column_name
varchar(new_length);
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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