Category: SQL


Objective: To insert new rows into TableB based on the records / values on the TableA.

  • Database Structure
    • Table A: [Database1].[TableA]
      • Columns: [Name], [Address],[Email]
    • Table B: [Database2].[TableB]
      • Columns: Same as [TableA]

SQL

INSERT INTO [Database2].[TableB] ([Name], [Address],[Email]) SELECT [Name], [Address],[Email] FROM  [Database1].[TableA] WHERE [ID] IN (1,3,5);

OUTCOME

The command above will copy records whichever with ID = 1, 3, or 5  from TableA to Table B.

***************************

DBCC SHRINKDATABASE(dbname)

****************************

Powered by WordPress | Theme: Motion by 85ideas.