1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.38 2005/01/17 01:29:02 tgl Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/ddl.sgml,v 1.39 2005/01/22 22:56:35 momjian Exp $ -->
2
2
3
3
<chapter id="ddl">
4
4
<title>Data Definition</title>
@@ -275,7 +275,7 @@ CREATE TABLE products (
275
275
CREATE TABLE products (
276
276
product_no integer,
277
277
name text,
278
- price numeric <emphasis>CHECK (price> 0)</emphasis>
278
+ price numeric <emphasis>CHECK (price> 0)</emphasis>
279
279
);
280
280
</programlisting>
281
281
</para>
@@ -303,7 +303,7 @@ CREATE TABLE products (
303
303
CREATE TABLE products (
304
304
product_no integer,
305
305
name text,
306
- price numeric <emphasis>CONSTRAINT positive_price</emphasis> CHECK (price> 0)
306
+ price numeric <emphasis>CONSTRAINT positive_price</emphasis> CHECK (price> 0)
307
307
);
308
308
</programlisting>
309
309
So, to specify a named constraint, use the key word
@@ -320,9 +320,9 @@ CREATE TABLE products (
320
320
CREATE TABLE products (
321
321
product_no integer,
322
322
name text,
323
- price numeric CHECK (price> 0),
324
- discounted_price numeric CHECK (discounted_price> 0),
325
- <emphasis>CHECK (price> discounted_price)</emphasis>
323
+ price numeric CHECK (price> 0),
324
+ discounted_price numeric CHECK (discounted_price> 0),
325
+ <emphasis>CHECK (price> discounted_price)</emphasis>
326
326
);
327
327
</programlisting>
328
328
</para>
@@ -350,20 +350,20 @@ CREATE TABLE products (
350
350
product_no integer,
351
351
name text,
352
352
price numeric,
353
- CHECK (price> 0),
353
+ CHECK (price> 0),
354
354
discounted_price numeric,
355
- CHECK (discounted_price> 0),
356
- CHECK (price> discounted_price)
355
+ CHECK (discounted_price> 0),
356
+ CHECK (price> discounted_price)
357
357
);
358
358
</programlisting>
359
359
or even
360
360
<programlisting>
361
361
CREATE TABLE products (
362
362
product_no integer,
363
363
name text,
364
- price numeric CHECK (price> 0),
364
+ price numeric CHECK (price> 0),
365
365
discounted_price numeric,
366
- CHECK (discounted_price> 0 AND price> discounted_price)
366
+ CHECK (discounted_price> 0 AND price> discounted_price)
367
367
);
368
368
</programlisting>
369
369
It's a matter of taste.
@@ -377,10 +377,10 @@ CREATE TABLE products (
377
377
product_no integer,
378
378
name text,
379
379
price numeric,
380
- CHECK (price> 0),
380
+ CHECK (price> 0),
381
381
discounted_price numeric,
382
- CHECK (discounted_price> 0),
383
- <emphasis>CONSTRAINT valid_discount</> CHECK (price> discounted_price)
382
+ CHECK (discounted_price> 0),
383
+ <emphasis>CONSTRAINT valid_discount</> CHECK (price> discounted_price)
384
384
);
385
385
</programlisting>
386
386
</para>
@@ -442,7 +442,7 @@ CREATE TABLE products (
442
442
CREATE TABLE products (
443
443
product_no integer NOT NULL,
444
444
name text NOT NULL,
445
- price numeric NOT NULL CHECK (price> 0)
445
+ price numeric NOT NULL CHECK (price> 0)
446
446
);
447
447
</programlisting>
448
448
The order doesn't matter. It does not necessarily determine in which