Skip to main content

Posts

Showing posts with the label SQL Server copy table from one database to another

SQL Server AS keyword

The AS keyword is used to assign an alias name of a column or a table Syntax: SELECT COL1, COL1 FROM Table_Name AS DEMO -- CREATE TABLE CREATE TABLE [dbo].[Tbl_Demo]( [ID] [ int ] IDENTITY( 1 , 1 ) NOT NULL , [Name] [ varchar ]( 500 ) NULL , [Age] [ int ] NULL , [IsActive] [ bit ] NULL , [IsDeleted] [ bit ] NULL , CONSTRAINT [PK_Tbl_Demo] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON ) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO --INSERT TABLE ROWS SET IDENTITY_INSERT [dbo].[Tbl_Demo] ON GO INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES ( 1 , N 'Anil Singh' , 30 , 1 , 0 ) GO INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES ( 2 , N 'Aradhya' , 3 , 1 , 0 ) GO INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VAL...

SQL Server copy table from one database to another

Hello everyone, I am going to share the T-SQL query for copy table from one database to another database using SQL Server 2012 . The query detail as given below. Table of Content Syntax for copy table from one database to another. Query for copy table from one database to another. Syntax /* COPY TABLE DATA FROM ONE DATABASE TO ANOTHER DATABASE IN SQL SERVER 2012 */ SELECT * INTO DB1 . dbo . [Employee] FROM DB2 . dbo . [User] Query for copy table from one database to another /* COPY TABLE DATA FROM ONE DATABASE TO ANOTHER DATABASE */ SELECT * INTO OBPC . [dbo] . [User]      FROM MASTER . [dbo] . [User] You can use the Wizard method to generate SQLServer scripts and for Wizard you can follow below links. http://blog.sqlauthority.com/2009/07/29/sql-server-2008-copy-database-with-data-generate-t-sql-for-inserting-data-from-one-table-to-another-table/ http://www.c-sharpcorner.com/UploadFile/rohatash/copy-table-with-dat...