2014-05-09 2 views
-4

저는 Postgres를 처음 사용하여 몇 가지 도움이 필요했습니다. MySQL에서 다음 테이블을 만들었지 만 Postgres에서 동일한 테이블을 만드는 데 문제가 있습니다. 어떻게 데이터베이스 Postgres에서이 테이블을 만들 수 있습니까? 테이블을 만드는 방법에 대한테이블 구조를 만들 수 없습니다.

CREATE TABLE `categorias` (
    `id_categorias` int(10) unsigned NOT NULL AUTO_INCREMENT, 
    `categoria_nome` varchar(255) NOT NULL, 
    `categoria_slug` varchar(200) NOT NULL, 
    `data_alteracao` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    PRIMARY KEY (`id_categorias`), 
    UNIQUE KEY `id_categorias_UNIQUE` (`id_categorias`) 
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='Tabela de Categorias para os arquivos de exemplo do Catálogo'; 


CREATE TABLE `produtos` (
    `id_produto` int(10) unsigned NOT NULL AUTO_INCREMENT, 
    `id_categoria` int(10) unsigned NOT NULL, 
    `nome` varchar(255) NOT NULL, 
    `descricao` text NOT NULL, 
    `foto` varchar(45) NOT NULL, 
    `preco` decimal(10,2) unsigned NOT NULL, 
    `slug` varchar(255) NOT NULL, 
    `data_alteracao` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    PRIMARY KEY (`id_produto`), 
    KEY `FK_produtos_categoria` (`id_categoria`), 
    CONSTRAINT `FK_produtos_categoria` FOREIGN KEY (`id_categoria`) REFERENCES `categorias` (`id_categorias`) 
) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8; 
+2

[같은 것은하지가 않습니다 "postgre".] (http : //wiki.postgr esql.org/wiki/Identity_Guidelines) –

답변

0
CREATE TABLE categorias 
(
    id_categorias serial NOT NULL, 
    categoria_nome varchar(255) NOT NULL, 
    categoria_slug varchar(200) NOT NULL, 
    data_alteracao timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    PRIMARY KEY (id_categorias), 
    constraint id_categorias_unique UNIQUE (id_categorias) 
); 

COMMENT on table categorias is 'Tabela de Categorias para os arquivos de exemplo do Catálogo'; 

CREATE TABLE produtos 
(
    id_produto serial NOT NULL, 
    id_categoria int NOT NULL, 
    nome varchar(255) NOT NULL, 
    descricao text NOT NULL, 
    foto varchar(45) NOT NULL, 
    preco decimal(10,2) NOT NULL, 
    slug varchar(255) NOT NULL, 
    data_alteracao timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    PRIMARY KEY (id_produto), 
    CONSTRAINT FK_produtos_categoria FOREIGN KEY (id_categoria) REFERENCES categorias (id_categorias) 
); 

create index idx_fk_produtos_categoria on produtos (id_categoria); 

자세한 내용은 매뉴얼에서 찾을 수 있습니다

관련 문제