What are Database and Columns?
In the database, you store the complete information about your business, social media etc. Some databases support relational databases. Means tables, every table consist of columns. Columns also called attributes.
How to Change the Table Columns Name?
SQL provides multiple ways to change your databases or tables columns name. We can easily change columns name through a simple query. Almost all the Database management systems provide queries as well as graphical user interfaces to change the columns name.
Change the column Using Query in SQL
The query for changing the name of an old column name with a new name is given below,
EXEC sp_rename “ Old column name “ , “ New Column name ” , “ COLUMN “ ;
Also, we can use an alternative solution for change the name of the column in the table.
ALTER TABLE tableName
CHANGE ‘ oldcolname ’ ‘ newcolname ’ datatype ( length ) ;
Also, database management systems provide build-in functions to change the existed columns name. Like this,
ALTER TABLE tableName
RENAME COLUMN ‘ oldcolname ‘ TO ‘ newcolname ‘ datatype ( length ) ;
sp_rename ‘ employees.last_name ‘ , ‘ lname ‘ , ‘ COLUMN ‘ ;
ALTER TABLE employees
ALTER COLUMN last_name VARCHAR ( 75 ) NOT NULL ;
How to Change Column Name in SQL Oracle
Oracle provides a query for changing the name of existing table columns,
RENAME COLUMN tableName.columnName TO newColumnName ;
How to Change Column Name in SQLite
In SQLite, you cannot change the name of the column. If you want to change the name of the column then you first delete the existing table and copy its data to a new table and change its columns name.
PRAGMA foreign_keys = off ;
BEGIN TRANSACTION ;
ALTER TABLE table1 RENAME TO _table1_old ;
CREATE TABLE table1 (
column1 datatype [ NULL | NOT NULL ] ,
column2 datatype [ NULL | NOT NULL ] ,
INSERT INTO table1 ( column1 , column2 , . . . column_n )
SELECT column1 , column2 , . . . column_n
FROM table1_old ;
PRAGMA foreign_keys = on ;
How to Change Column Name in SQL server 2008
EXEC sp_RENAME ‘ table_name.old_name ‘ , ‘ new_name ‘ , ‘ COLUMN ‘ ;
Use single quotes to enclose your old and new columns name.
Renaming a column SQL Server
You can easily change the columns name from your SQL server using the query:
EXEC sp_rename ‘ table_name.old_col_name ‘ , ‘ new_col_name ‘ , ‘ COLUMN ‘ ;
For example, we are changing the name of the column address from the customer table, the query is :
EXEC sp_rename ‘ customer.address ‘ , ‘ full_address ‘ , ‘ COLUMN ‘ ;
This query is not for m=only SQL server, using this you can change the table, databases, object and index etc.