Collections:
Add a New Column to an Existing Table with a Default Value in Oracle
How To Add a New Column to an Existing Table with a Default Value in Oracle?
✍: FYIcenter.com
If you want to add a new column to an existing table, and insert a default value in this column on all existing data rows, you can use the ALTER TABLE ... ADD statement with the DEFAULT clause. Here is an example script:
SQL> CREATE TABLE emp_dept_90 2 AS SELECT * FROM employees WHERE department_id=90; Table created. SQL> ALTER TABLE emp_dept_90 2 ADD (vacation NUMBER DEFAULT 10); Table altered. SQL> SELECT first_name, last_name, vacation 2 FROM emp_dept_90; FIRST_NAME LAST_NAME VACATION -------------------- ------------------------- ---------- Steven King 10 Neena Kochhar 10 Lex De Haan 10
As you can see, the "DEFAULT 10" clause did inserted 10 to all existing data rows.
⇒ Rename a Column in an Existing Table in Oracle
⇐ Add a New Column to an Existing Table in Oracle
2019-05-25, 1922🔥, 0💬
Popular Posts:
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...
How to download and install the scaled-down database AdventureWorksLT in SQL Server? If you want to ...
How To Start MySQL Server in MySQL? If you want to start the MySQL server, you can run the "mysqld" ...
How To List All Stored Procedures in the Current Database in SQL Server Transact-SQL? If you want to...
How To Get the Definition of a Stored Procedure Back in SQL Server Transact-SQL? If you want get the...