Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql server alter column

ALTER TABLE table_name 
ALTER COLUMN column_name new_data_type(size);
Comment

SQL Modify Column in a Table

#SQL Server

ALTER TABLE Customers
ALTER COLUMN age VARCHAR(2);

#MySQL

ALTER TABLE Customers
MODIFY COLUMN age VARCHAR(2);

#Oracle

ALTER TABLE Customers
MODIFY age VARCHAR(2);

#PostgreSQL

ALTER TABLE Customers
ALTER COLUMN age TYPE VARCHAR(2);
Comment

alter table

ALTER TABLE table_name MODIFY column_name datatype NOT NULL;
Comment

alter table

ALTER TABLE table_name MODIFY COLUMN column_name datatype;
Comment

sql alter column

Changes the data type of a table’s column.
Example: In the ‘users’ table, make the column ‘incept_date’ into a
‘datetime’ type.
ALTER TABLE users
ALTER COLUMN incept_date datetime;
Comment

sql alter table

-- With check if field already exists

IF NOT EXISTS(SELECT 1 FROM sys.columns 
          WHERE Name = N'Email'
          AND Object_ID = Object_ID(N'dbo.Customers'))
BEGIN    
	ALTER TABLE Customers
    ADD Email varchar(255);
END
Comment

alter table

ALTER TABLE table_name 
DROP PRIMARY KEY;
Comment

alter table

ALTER TABLE table_name 
ADD CONSTRAINT MyUniqueConstraint CHECK (CONDITION);
Comment

alter table

ALTER TABLE table_name 
DROP CONSTRAINT MyUniqueConstraint;
Comment

alter table

ALTER TABLE table_name 
ADD CONSTRAINT MyPrimaryKey PRIMARY KEY (column1, column2...);
Comment

alter table

ALTER TABLE table_name 
ADD CONSTRAINT MyUniqueConstraint UNIQUE(column1, column2...);
Comment

alter table

ALTER TABLE table_name 
DROP INDEX MyUniqueConstraint;
Comment

PREVIOUS NEXT
Code Example
Sql :: 2nd highest value in sql 
Sql :: postgresql héritage 
Sql :: sql join on a subquery 
Sql :: psql check tables command 
Sql :: create unique constraint postgres 
Sql :: copy a table mysql 
Sql :: setval in postgres 
Sql :: best sql collation 
Sql :: what is non relational database 
Sql :: dublicate row sql 
Sql :: set column width in sqlplus 
Sql :: mssql describe stored procedure sqlcmd 
Sql :: export database sql file from xampp using cmd 
Sql :: copy from one table to another postgres using matching column 
Sql :: sql unique 
Sql :: control files oracle 
Sql :: min mysql 
Sql :: mysql query to select the highest value 
Sql :: GUI for sqlite mac 
Sql :: sql rename column in select 
Sql :: trigger sql 
Sql :: time in sql server 
Sql :: hour must be between 1 and 12 
Sql :: mysqli_free_result 
Sql :: mysql order by rand limit 1 really slow 
Sql :: SQL SUM() Function 
Sql :: homebrew mysql service not starting 
Sql :: sql update by id 
Sql :: database stuck at restoring state 
Sql :: mysql select smaller of two values 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =