Rohit Kainth
How to insert ONLY HEADER of one table into another table?
By Rohit Kainth in SQL Server on Oct 09 2018
  • Shashidhar R
    Oct, 2024 26

    u complete structure of table we can use copy script

    • 0
  • Shashidhar R
    Oct, 2024 26

    select *into new_table_name from tablename where 2=0

    • 0
  • Ekta PandeyPareta
    Feb, 2020 28

    I think question is interesting but not framed correctly. Please find below my query I used for this question and as per your soluction, question should be “How to create table with same column without using create table command”.

    Please take it positvely and your question is really interesting, it drew my attention :).

    Regards,
    Ekta Pandey Pareta

    • 0
  • Ekta PandeyPareta
    Feb, 2020 28

    SELECT C.NAME INTO #TEST FROM SYS.COLUMNS C JOIN SYS.OBJECTS O ON C.OBJECT_ID = O.OBJECT_ID WHERE O.NAME = ‘YOURTABLENAME’
    SELECT * FROM #TEST

    • 0
  • Mamta Rajpoot
    Oct, 2018 27

    First we create a table with only header , no data should be inserted. After that by using insert into command we can move the header of first table to second table.create table table1 ( Id int, name varchar(10)) Go Select * into table2 from table1 where 1=2

    • 0
  • Rohit Kainth
    Oct, 2018 9

    We can do so by adding a condition at the end of the T-SQLCREATE TABLE TEST_WF (ID INT, NAME VARCHAR(5))INSERT INTO TEST_WF VALUES (1,'A'),(2,'B'),(3,'B'),(4,'C'),(5,'C'),(6,'C')SELECT * INTO TEST FROM TEST_WF WHERE 1=2By adding the false condition or the condition which can not be true, we can insert Headers only from one table to another table.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS