Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Create Table and Types - Intro to Relational Databases

Get Embed Code
4 Languages

Showing Revision 3 created 05/24/2016 by Udacity Robot.

  1. You can add a new empty table to your
    database with the create table command.
  2. When you create a table, you'll give
    the name of the table, and the names and
  3. the types of each column.
  4. You can also set constraints on each
    column and on the row as a whole.
  5. We'll talk about constraints shortly,
    but for now, let's focus on types.
  6. Here's the simplest form of the create
    table command that doesn't have any
  7. constraints, only columns with their
    types, and gives the table a name.
  8. Now, we've dealt with text and integer
    types previously, and back in lesson
  9. two, I gave you a big, long list of lots
    and lots of types that SQL supports.
  10. The exact set of types that you can use
    will vary from system to system though.
  11. If you're working with a database system
    that doesn't natively support the type
  12. you need,
    there's usually a way to work around it.
  13. For instance,
    PostgreSQL has a specific type for
  14. IP addresses, but MySQL does not.
  15. MySQL programmers usually use an integer
    or a text string to store IP addresses.
  16. Of the databases we've used in this
    course, PostgreSQL has a proper type for
  17. dates and times, but SQLite actually
    just stores dates as strings.
  18. Database systems will often give you
    shortcuts to declare a particular
  19. kind of column.
  20. For instance, in PostgreSQL, you can
    have a column that stores the time and
  21. date along with the time zone so
  22. you can do comparisons of data recorded
    in different places around the world.
  23. The full SQL standard name for that
    column type is timestamp with time zone,
  24. but PostgreSQL lets us
    abbreviate it as timestamptz.
  25. Normally, if you're creating
    a database for a new application,
  26. you'll set up the database upfront as
    part of the installation procedure.
  27. It's technically possible to send create
    table commands from your app code, but
  28. it's usually a bad idea to do
    that outside of initial setup.
  29. Your database design is really
    a part of your app's code.
  30. It's just a part written in
    SQL instead of in Python.
  31. So, creating tables isn't like creating
    values in your program's variables.
  32. It's more like having your
    app rewrite its own code.
  33. That's not something that's very common.