Temporary tables in SQL:
Local temp table:
create table #table_name ( column_name data_type, column_name data_type )
Create table #Student ( StudentId int, StudentName varchar(50) )
Global temp table:
create table ##table_name ( column_name data_type, column_name data_type )
Create table ##Student ( StudentId int, StudentName varchar(50) )
Table variable in SQL:
Declare @table_name table ( Column_name data_type, Column_name data_type )
Declare @Student table ( StudentId int, StudentName varchar(50) )
DECLARE @StudentTb TABLE ( StudentId INT, StudentName VARCHAR(40) ); SELECT TABLE_CATALOG, TABLE_SCHEMA, COLUMN_NAME, DATA_TYPE FROM tempdb.INFORMATION_SCHEMA.COLUMNS insert into @Studenttb values(1,'Test') select * from @StudentTb GO --this line will give an error as a new batch execution is started with Go -- select * from @StudentTb --table is not avaliable with a new batch SELECT TABLE_CATALOG, TABLE_SCHEMA, COLUMN_NAME, DATA_TYPE FROM tempdb.INFORMATION_SCHEMA.COLUMNS
Output:
Difference between Temp table and Table variable in SQL:
Point of comparison | Temp table | Temporary variable |
Scope | A temp table remain until the instance is alive or all sessions are closed depending upon the type of the temp table (local or global temp table) | A temporary variable remains only for any particular batch execution in which it is created |
Indexes | We can create index on temp table as any normal SQL table | It is not possible to create explicit indexes on temporary variable. However, we can have implicit indexes in form of constraints such as primary constraint or unique constraint |
Transactions | Temp table supports transactions | Table variable does not support transactions |
DDL Commands | A temp table supports DDL commands. For example, we can alter a temp table after it is created | A temporary variable does not support DDL commands. For example, we cannot alter a table created using a temp variable |
Truncate | A temp table can be truncated | A temporary variable cannot be truncated |
Functions | A temp table cannot be used with user defined functions | A temporary variable can be used with user defined functions |
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular