how to create new table from existing table in sql server

bohar

bohar

@bohar-wQr9Oe Oct 21, 2024
I want to use only one query - the problem is: how to create new table from existing table in sql server

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Leo

    Leo

    @leo-ZJQlmh Nov 12, 2010

    create table newtable_name like database_name.old_table_name;

    insert into newtable_name selcet * from database_name.old_table_name;

    This will copy your previous table to new table. Happy computing.
  • Sahithi Pallavi

    Sahithi Pallavi

    @sahithi-oJZaYj Nov 12, 2010

    create table new-table-name (column-list) as select (column-list) from existing-table-name;

    What's this then?
  • Saandeep Sreerambatla

    Saandeep Sreerambatla

    @saandeep-sreerambatla-hWHU1M Nov 12, 2010

    In Oracle,

    Create table temp as select * from old table. -- will this not do?
  • Sahithi Pallavi

    Sahithi Pallavi

    @sahithi-oJZaYj Nov 12, 2010

    English-Scared
    In Oracle,

    Create table temp as select * from old table. -- will this not do?
    This is same as the query I have given.

    create table new-table-name (column-list) as select (column-list) from existing-table-name;

    In your query, temp is the new-table-name and old table refers to the existing-table-name. I had specified the column-list to select particular columns and you used * to select all the columns, Isn't it?

    This will definitely works.
  • bohar

    bohar

    @bohar-wQr9Oe Nov 13, 2010

    select * into table_new from table_old
    this query work in sqlserver,but i have no idea that about, this will work in oracle,mysql or not
  • 4M4N

    4M4N

    @4m4n-jQmegc Nov 13, 2010

    Suppose u have table employee having cols eno, ename, salary and adress, now for making exact copy of that table of name emp2 the following query can be used

    create table emp2(eno int, ename varchar(50), salary int, address varchar(50)) select eno , ename , salary , address from employee;
    (tested)