![]() ![]() SELECT 5, 'MATTS', '4755#55522', 'NOT KNOWN', 'WOODOO', 'COMMONS', 'UNITED KINGDOM', 'ADVANCE INTO EmployeeDetails (EmpID, EmpName, Mobile, PresentAddress, Area, City,Country, Qualification, Email) SELECT 4, 'DEWANE PAUL', '5741115523', 'SPACE, 1 OF 1', 'ANDALUSIAN', 'PARALLEL', 'NEW RIVER', INTO EmployeeDetails (EmpID, EmpName, Mobile, PresentAddress, Area, City,Country, Qualification, Email) SELECT 3, 'GREEN FIELD', '4517825469', 'UNIVERSAL NEW AVE', 'BOURNNILE', 'BRISDON', 'NEW START', INTO EmployeeDetails (EmpID, EmpName, Mobile, PresentAddress, Area, City,Country, Qualification, Email) SELECT 2, 'MIKE PEARL', '2152313213', 'B BLOCK NICE STREET', 'WENEN', 'TACOCA', 'SCODD', 'GRADUATE', INTO EmployeeDetails (EmpID, EmpName, Mobile, PresentAddress, Area, City,Country, Qualification, Email) SELECT 1, 'CHIN YEN', '1234567879', '1 MAIN AVE', 'WA', 'TACOCA', 'USA', INTO EmployeeDetails (EmpID, EmpName, Mobile, PresentAddress, Area, City,Country, Qualification, Email) INSERT INTO EmployeeDetails (EmpID, EmpName, Mobile, PresentAddress, Area, City,Country, Qualification, Email) (EmpID, EmpName, Mobile, PresentAddress, Area, City, Country, Qualification, Email) SELECT 6, 'PLANK OTO', 'ACCOUNTANT', 'ACCOUNTS', GETDATE()ĬREATE TABLE. SELECT 4, 'DEWANE PAUL', 'PROGRAMMER', 'IT', GETDATE() SELECT 3, 'GREEN FIELD', 'ACCOUNTANT', 'ACCOUNTS', GETDATE() SELECT 2, 'MIKE PEARL', 'SENIOR ACCOUNTANT', 'ACCOUNTS', GETDATE() SELECT 1, 'CHIN YEN', 'LAB ASSISTANT', 'LAB', GETDATE() INSERT INTO Employee (EmpID, EmpName, Designation, Department, JoiningDate) (6, 'PLANK OTO', 'ACCOUNTANT', 'ACCOUNTS', GETDATE()) (4, 'DEWANE PAUL', 'PROGRAMMER', 'IT', GETDATE()), (3, 'GREEN FIELD', 'ACCOUNTANT', 'ACCOUNTS', GETDATE()), (2, 'MIKE PEARL', 'SENIOR ACCOUNTANT', 'ACCOUNTS', GETDATE()), (1, 'CHIN YEN', 'LAB ASSISTANT', 'LAB', GETDATE()), ( EmpID, EmpName, Designation, Department, JoiningDate) Lets check the table DataTblDev1, and you can see data is copied into table and there are only Id, Name, and country column in table.CONSTRAINT PRIMARY KEY CLUSTERED ( EmpID) SELECT Id, Name, Country INTO Dev_Db.dbo.DataTblDev1 In case if you do not want to copy the data for all columns, you can also specify the column’s name that you want copy in Target table.įollowing statement copy only Id, Name, and Country data into Target table named DataTblDev1. Lets verify the records in table, and you can see data is copied successfully in table DataTblDev. įollowing Select into statemement copies the data of table DataTbl to the database Dev_Db in new table DataTblDev. Lets copy the this data into Dev_db’s table. You can see, now you have accessed the database Prod_db table’s data into database Dev_Db. To access the data from table which exists in different databases hosted in same SQL Server instance, you need to provide full qualify name for table such as table name including database name, and schema (database_name.schema_name.table_name) as shown below. Now we will access the data of table DataTbl which in Prod_db (consider as Source table) into Dev_Db (Consider as Target table). Copying records from one database to another Now we have a table in Prod_Db, Lets copy the table data into another database. ('Mark Hanery', 'South Africa', 'Prod Admin'),Īs you can see, table named DataTbl is created in Prod_Db. INSERT INTO dbo.demo(Name, Country, CreatedBy) Here we have a table in Prod_Db as shown below. To demonstrate this, Lets create a sample table named DataTbl in Prod_Db and insert some records into table. Now you have a requirement to access a data from table in Prod_Db database into table in Dev_Db.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |