Step 1. Create a table or use an existing database table. In our case, we create a Test table in SQL Server using the following SQL query.
- CREATE TABLE Test
- (ID INT,
- FirstName VARCHAR(40),
- LastName VARCHAR(40))
Step 2. Insert some records to this table. If you already have a database table with data in it, you don't need this step. My table data looks like this:
ID FirstName LastName
1 Pankaj pandey
2 Rahul Pandey
3 Ramesh Mishra
4 Raja Singh
Step 3. We can use an INSERT INTO SQL query to read data of an existing database table and insert into a new table. If there is no database table, the query will create a new table.
Here is the INSERT INTO command:
- Select * into <New Table Name> from <Existing Table Name>
Here is our query that will read data from the Test table and insert into a new table called DummyTest.
- SELECT * INTO dummytest FROM Test
Step 4. Check the results. Run this command:
I will return exact same data that we have in the Test table.
ID FirstName LastName
1 Pankaj pandey
2 Rahul Pandey
3 Ramesh Mishra
4 Raja Singh