Database

Join Tables from Different Databases in SQL Server

Here is a template that you can use to join tables from two different databases in SQL Server: SELECT table_1.*, table_2.* FROM [Database_1].[Table_Schema].[Table_Name_1] table_1 JOIN [Database_2].[Table_Schema].[Table_Name_2] table_2 ON table_1.id = table_2.id In the next section, you’ll see how to join two tables from two different database in SQL Server. The tables and databases will be …

Join Tables from Different Databases in SQL Server Read More »

How to Create a Temporary Table in SQL Server

Here are two approaches to create a temporary table in SQL Server: (1) The SELECT INTO approach: SELECT Column1,Column2,Column3,… INTO #NameOfTempTable FROM [DatabaseName].[TableSchema].[TableName] WHERE condition (2) The CREATE TABLE approach: CREATE TABLE #NameOfTempTable ( Column1 datatype, Column2 datatype, Column3 datatype, . . ColumnN datatype ) Note that once you created the table under the second …

How to Create a Temporary Table in SQL Server Read More »

LEFT JOIN in SQL Server (examples included)

You can use a LEFT JOIN in SQL Server to get all the records from the left table, and the records from the right table where there is a match (if there is no match, you’ll get NULL under the selected fields from the right table): SELECT table_1.*, table_2.* FROM [database_name].[table_schema].[left_table_name] table_1 LEFT JOIN [database_name].[table_schema].[right_table_name] …

LEFT JOIN in SQL Server (examples included) Read More »

How to Delete Records from a Table in SQL Server

Here are two approaches to delete records from a table in SQL Server: (1) Delete records based on specified conditions: DELETE FROM [database_name].[table_schema].[table_name] WHERE condition (2) Delete all the records in a given table: DELETE FROM [database_name].[table_schema].[table_name] In the next section, you’ll see how to apply the above approaches using a practical example. The Example: …

How to Delete Records from a Table in SQL Server Read More »

How to Insert Records Into a Table in SQL Server

Here is a template that you can use in order to insert records into a table in SQL Server: INSERT INTO [database_name].[table_schema].[table_name] (column1,column2,column3,…) VALUES (‘column1_value1’, ‘column2_value1’, …), (‘column1_Value2’, ‘column2_value2’, …), . . (‘column1_valueN’, ‘column2_valueN’, …) Let’s now review an example to see how to apply the above syntax in practice. The Example For demonstration purposes, …

How to Insert Records Into a Table in SQL Server Read More »