How to Create a Table in BigQuery

Here's an example of creating a users table in BigQuery:

create table `project-id.dataset.funky_users` (
  first_name STRING,
  last_name STRING,
  has_tried_popsql BOOL,
  number_of_friends INT64 not null -- chance to specify not null constraints
);

Table names must:

  • contain only letters (a-z, A-Z), numbers (0-9), or underscores (_),
  • start with a letter or underscore,
  • be shorter than 1024 characters,
  • and not use table decorators (e.g. snapshot or range decorators like [new_table@-3600000])

🧐 Points of clarification:

  • BigQuery uses underscores for table names (e.g. funky_users, not funky-users). - Project IDs in BigQuery, however, accept hyphens (-) but not underscores (_). 🤷
  • Note the backticks around the project, database, and table names. - Be sure to use a period instead of a colon between the project, database, and table names too.

Need a refresher on BigQuery data types? We've got just the thing.

Previous

Next

Ready for a modern SQL editor?