[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [TEKNIK] postgres



On Thu, 24 Feb 2005 21:26:45 +0100, Martin Schiøtz wrote:

> Jeg havde egentlig forestillet mig at ' qd_id' både var PK og
> indexering og af samme årsag foretaget SEQUENCE og NOT NULL på '
> qd_id'.

Det forstår jeg ikke helt.

Men i øvrigt kan du med PostgreSQL benytte pseudo-datatypen SERIAL for at
gøre din tabel-skabelse lidt simplere:

CREATE TABLE tabelnavn (
  tabelnavn_id SERIAL PRIMARY KEY,
  ...
);

SERIAL gør, at en SEQUENCE automatisk bliver oprettet, og at værdierne
til tabelnavn_id trækkes fra den.

Og i øvrigt er NOT NULL implicit i PRIMARY KEY.

Din SQL for skabelse af qdisk-tabellen kan indskrænkes til:

CREATE TABLE qdisk (
   qd_id SERIAL PRIMARY KEY,
   qd_name VARCHAR(255) NOT NULL,
   qd_net VARCHAR(18) NOT NULL,
   qd_burst INT DEFAULT 0 NOT NULL,
   qd_cburst INT DEFAULT 0 NOT NULL,
   qd_perturb INT DEFAULT 4 NOT NULL,
   qd_prio INT DEFAULT 5 NOT NULL,
   qd_date TIMESTAMP DEFAULT LOCALTIMESTAMP NOT NULL,
   qd_param_1 VARCHAR(255) DEFAULT NULL,
   qd_param_2 VARCHAR(255) DEFAULT NULL,
   sh_id INT NOT NULL REFERENCES machine ON DELETE RESTRICT,
   ab_id INT NOT NULL REFERENCES machine ON DELETE RESTRICT
);

Mht. qd_prio, så lugter den lidt af at have et begrænset værdirum. Hvis
den fx. aldrig må ligge uden for 0-9, kunne du tilføje nogle
CHECK-constraints på kolonnen, såsom CHECK(qd_prio>=0 AND qd_prio<10).

> Ok - men med andre ord bør jeg altså lade postgres gøre det, men kan
> jeg selv oprette en index'ering, som postgres vil respektere/bruge?

Du kan/skal selv oprette relevant indeksering. Men det ville være fjollet
at skabe et index på din qd_id kolonne, eftersom at PostgreSQL allerede
har skabt et index for den kolonne.

-- 
Greetings from Troels Arvin, Copenhagen, Denmark



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:26 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *