Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews DB Oracle Interviews:Concepts and ArchitectureData AccessDatabase ArchitectureDatabase ManagementDatabase Security OracleDistributed ProcessingFlexfieldForms ReportsGeneral OracleMemory ManagementMTO-SAP Financial AccountingOCIOracle AOLOracle AROracle Backup RecoveryOracle D2KOracle DatabaseOracle Database DeveloperOracle DB OptimizationOracle DBAOracle DeveloperOracle ETLOracle Forms 3.0Oracle Forms 4.0Oracle GLOracle PL-SQLOracle RMANOracle ScenariosOracle SecurityOracle SQLOracle System ArchitectureOracle Technology Network (OTN)Programmatic ConstructsRAC (Real Application Clusters)SQL Plus
Copyright © 2018. All Rights Reserved
Oracle Database Interview Question:
How To Add a New Column to an Existing Table with a Default Value?
Submitted by: AdministratorIf 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;
<pre>FIRST_NAME LAST_NAME VACATION
-------------------- ------------------------- ----------
Steven King 10
Neena Kochhar 10
Lex De Haan 10</pre>
As you can see, the "DEFAULT 10" clause did inserted 10 to all existing data rows.
Submitted by: Administrator
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;
<pre>FIRST_NAME LAST_NAME VACATION
-------------------- ------------------------- ----------
Steven King 10
Neena Kochhar 10
Lex De Haan 10</pre>
As you can see, the "DEFAULT 10" clause did inserted 10 to all existing data rows.
Submitted by: Administrator
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.