sql-server - without - sql server drop column
How to change column datatype in SQL database without losing data (6)
I have SQL Server database and I just realized that I can change the type of one of the columns from
How can I do that without losing the data that is already entered into that table?
I can modify the table field's datatype, with these following query: and also in the Oracle DB,
ALTER TABLE table_name MODIFY column_name datatype;
In compact edition will take size automatically for datetime data type i.e. (8) so no need to set size of field and generate error for this operation...
Replace datatype without losing data
alter table tablename modify columnn newdatatype(size);
You can easily do this using the following command. Any value of 0 will be turned into a 0 (BIT = false), anything else will be turned into 1 (BIT = true).
ALTER TABLE dbo.YourTable ALTER COLUMN YourColumnName BIT
The other option would be to create a new column of type
BIT, fill it from the old column, and once you're done, drop the old column and rename the new one to the old name. That way, if something during the conversion goes wrong, you can always go back since you still have all the data..
if you use T-SQL(MSSQL); you should try this script:
ALTER TABLE [Employee] ALTER COLUMN [Salary] NUMERIC(22,5)
if you use MySQL; you should try this script:
ALTER TABLE [Employee] MODIFY COLUMN [Salary] NUMERIC(22,5)
if you use Oracle; you should try this script:
ALTER TABLE [Employee] MODIFY [Salary] NUMERIC(22,5)