0

I'm trying to create a table from another table (CREATE TABLE...AS... statement), but I don't want to insert the rows from the first table. I only need the columns. How?

CREATE TABLE employees24
AS (
    SELECT employee_id AS "ID",
      first_name,
      last_name,
      salary,
      department_id AS "DEPT_ID"
    FROM employees);
Pang
  • 9,073
  • 146
  • 84
  • 117

2 Answers2

1

Something like create table employees24 as (select * from employees where 0 = 1); should work.

mathguy
  • 42,476
  • 6
  • 23
  • 50
1

To create an empty table you just need to pass a select, that will not return any rows:

CREATE TABLE employees24
AS (
    SELECT employee_id AS "ID",
      first_name,
      last_name,
      salary,
      department_id AS "DEPT_ID"
    FROM employees
    WHERE 1=2);
Gasper
  • 2,333
  • 1
  • 11
  • 16