Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between DECLARE TABLE and CREATE TABLE?

I need to translate given T-SQL statements into another language. These T-SQL statements are using DECLARE TABLE. What's the difference between DECLARE TABLE and CREATE TABLE?

For example, what’s the difference between the following two lines?

declare @t table (account_id varchar(512), num_events int);
Create table t {account_id varchar(512), num_events int}
like image 882
Cherry Wu Avatar asked Feb 05 '14 21:02

Cherry Wu


2 Answers

The only difference between DECLARE TABLE and CREATE TABLE is:

  • DECLARE TABLE: You will create a table on the fly and use that table later on in the query and not store it physically.

  • CREATE TABLE: You will create a table physically inside the database.

like image 132
Maverick Avatar answered Oct 16 '22 17:10

Maverick


The difference is that "Declare table" would be a table level variable.

The "create table" will create a table in the database.

like image 32
Brent Avatar answered Oct 16 '22 19:10

Brent