change the size of datatype in sql
You may try this for Oracle:-
alter table tablename modify
(
column_name varchar2(13)
);
Also If you dont have any data in the table then you can also drop
the table and then create
the table with the columname as varchar2(13)
Altering column size in SQL Server
ALTER TABLE [Employee]
ALTER COLUMN [Salary] NUMERIC(22,5) NOT NULL
How to change column datatype in SQL Server database without losing data?
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..
How to reduce size of SQL Server table that grew from a datatype change
Well it's clear you're not getting any space back ! :-)
When you changed your text fields to CHAR(60), they are all filled up to capacity with spaces. So ALL your fields are now really 60 characters long.
Changing that back to VARCHAR(60) won't help - the fields are still all 60 chars long....
What you really need to do is run a TRIM function over all your fields to reduce them back to their trimmed length, and then do a database shrinking.
After you've done that, you need to REBUILD your clustered index in order to reclaim some of that wasted space. The clustered index is really where your data lives - you can rebuild it like this:
ALTER INDEX IndexName ON YourTable REBUILD
By default, your primary key is your clustered index (unless you've specified otherwise).
Marc
How do I alter the precision of a decimal column in Microsoft SQL Server?
ALTER TABLE Testing ALTER COLUMN TestDec decimal(16,1)
Just put decimal(precision, scale)
, replacing the precision and scale with your desired values.
I haven't done any testing with this with data in the table, but if you alter the precision, you would be subject to losing data if the new precision is lower.
How can I change data type of a column in SQL Server?
To change the type with SQL run the following
Alter table dbo.[Tag] alter column [Size] int NOT NULL
To change the type through an EF migration use
AlterColumn("dbo.Tag", "Size", c => c.Int(nullable: false));
How do you change the datatype of a column in SQL Server?
ALTER TABLE TableName
ALTER COLUMN ColumnName NVARCHAR(200) [NULL | NOT NULL]
EDIT
As noted NULL/NOT NULL should have been specified, see Rob's answer as well.
Related Topics
How to Pivot Rows to Columns in MySQL Without Using Case
How to "Reset" Running Sum After It Reaches a Threshold
MySQL Datetime Group by 15 Mins
Find Min and Max for Subsets of Consecutive Rows - Gaps and Islands
How to Select First N Rows from a Table in T-Sql
SQL Server Audit Logout Creates Huge Number of Reads
SQL How to Have a "Conditionally Unique" Constraint on a Table
How to Get the Date and Time from Timestamp in Postgresql Select Query
Is It Better to Do an Equi Join in the from Clause or Where Clause
How to Find All Open/Active Connections in Db2 (8.X)
Problem with MySQL Insert Max()+1
SQL Query - Select * from View or Select Col1, Col2, ... Coln from View
How to Use a Returned Column Value as a Table Name in an SQLite Query
Row_Number Simulation in SQL Server 2000