gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

69 linhas
5.6KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>2.3. Creating a New Table</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="tutorial-concepts.html" title="2.2. Concepts" /><link rel="next" href="tutorial-populate.html" title="2.4. Populating a Table With Rows" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">2.3. Creating a New Table</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="tutorial-concepts.html" title="2.2. Concepts">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="tutorial-sql.html" title="Chapter 2. The SQL Language">Up</a></td><th width="60%" align="center">Chapter 2. The <acronym xmlns="http://www.w3.org/1999/xhtml" class="acronym">SQL</acronym> Language</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="tutorial-populate.html" title="2.4. Populating a Table With Rows">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="TUTORIAL-TABLE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">2.3. Creating a New Table</h2></div></div></div><a id="id-1.4.4.4.2" class="indexterm"></a><p>
  3. You can create a new table by specifying the table
  4. name, along with all column names and their types:
  5. </p><pre class="programlisting">
  6. CREATE TABLE weather (
  7. city varchar(80),
  8. temp_lo int, -- low temperature
  9. temp_hi int, -- high temperature
  10. prcp real, -- precipitation
  11. date date
  12. );
  13. </pre><p>
  14. You can enter this into <code class="command">psql</code> with the line
  15. breaks. <code class="command">psql</code> will recognize that the command
  16. is not terminated until the semicolon.
  17. </p><p>
  18. White space (i.e., spaces, tabs, and newlines) can be used freely
  19. in SQL commands. That means you can type the command aligned
  20. differently than above, or even all on one line. Two dashes
  21. (<span class="quote">“<span class="quote"><code class="literal">--</code></span>”</span>) introduce comments.
  22. Whatever follows them is ignored up to the end of the line. SQL
  23. is case insensitive about key words and identifiers, except
  24. when identifiers are double-quoted to preserve the case (not done
  25. above).
  26. </p><p>
  27. <code class="type">varchar(80)</code> specifies a data type that can store
  28. arbitrary character strings up to 80 characters in length.
  29. <code class="type">int</code> is the normal integer type. <code class="type">real</code> is
  30. a type for storing single precision floating-point numbers.
  31. <code class="type">date</code> should be self-explanatory. (Yes, the column of
  32. type <code class="type">date</code> is also named <code class="structfield">date</code>.
  33. This might be convenient or confusing — you choose.)
  34. </p><p>
  35. <span class="productname">PostgreSQL</span> supports the standard
  36. <acronym class="acronym">SQL</acronym> types <code class="type">int</code>,
  37. <code class="type">smallint</code>, <code class="type">real</code>, <code class="type">double
  38. precision</code>, <code class="type">char(<em class="replaceable"><code>N</code></em>)</code>,
  39. <code class="type">varchar(<em class="replaceable"><code>N</code></em>)</code>, <code class="type">date</code>,
  40. <code class="type">time</code>, <code class="type">timestamp</code>, and
  41. <code class="type">interval</code>, as well as other types of general utility
  42. and a rich set of geometric types.
  43. <span class="productname">PostgreSQL</span> can be customized with an
  44. arbitrary number of user-defined data types. Consequently, type
  45. names are not key words in the syntax, except where required to
  46. support special cases in the <acronym class="acronym">SQL</acronym> standard.
  47. </p><p>
  48. The second example will store cities and their associated
  49. geographical location:
  50. </p><pre class="programlisting">
  51. CREATE TABLE cities (
  52. name varchar(80),
  53. location point
  54. );
  55. </pre><p>
  56. The <code class="type">point</code> type is an example of a
  57. <span class="productname">PostgreSQL</span>-specific data type.
  58. </p><p>
  59. <a id="id-1.4.4.4.8.1" class="indexterm"></a>
  60. Finally, it should be mentioned that if you don't need a table any
  61. longer or want to recreate it differently you can remove it using
  62. the following command:
  63. </p><pre class="synopsis">
  64. DROP TABLE <em class="replaceable"><code>tablename</code></em>;
  65. </pre><p>
  66. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tutorial-concepts.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tutorial-sql.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="tutorial-populate.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.2. Concepts </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.4. Populating a Table With Rows</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1