11

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}
honk
  • 9,137
  • 11
  • 75
  • 83
Cherry Wu
  • 3,844
  • 9
  • 43
  • 63
  • Read here for a very detailed answer about Temp Tables Vs Table Variable http://stackoverflow.com/questions/11857789/when-should-i-use-a-table-variable-vs-temporary-table-in-sql-server – M.Ali Feb 05 '14 at 21:22
  • I thought table variable means the variables in the table, now I just knew it means @t here. – Cherry Wu Feb 05 '14 at 21:38

2 Answers2

18

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.

honk
  • 9,137
  • 11
  • 75
  • 83
Maverick
  • 1,167
  • 1
  • 8
  • 16
4

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

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

Brent
  • 578
  • 3
  • 12