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,564
  • 146
  • 81
  • 122

2 Answers2

2

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

  • thanks alot. i was wondering around and finally found the desired solution to the problem – Jency Nov 17 '22 at 12:42
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,752
  • 1
  • 12
  • 16