1 / 4

Criação de Tabelas

Criação de Tabelas. CREATE TABLE nome_da_tabela ( <<<atributo tipo_de_dados nulidade chave (se não for composta)>>> . . . <<< primary key (atributo 1, atributo 2) [Vale para um ou vários atributos chaves]>>>

Télécharger la présentation

Criação de Tabelas

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Criação de Tabelas

  2. CREATE TABLE nome_da_tabela ( <<<atributo tipo_de_dados nulidade chave (se não for composta)>>> . . . <<<primarykey (atributo 1, atributo 2) [Vale para um ou vários atributos chaves]>>> <<< foreignkey (atributo) referencestabela_repositório (atributo_origem) >>> ) Ex.: SQL SERVER 2008 CREATE TABLE pessoa ( CPF VARCHAR(11) NOT NULL, NOME VARCHAR(100) NOT NULL, NASCIMENTO DATETIME NULL, IDADE INT NULL, SALÁRIO MONEY NULL, DEPARTAMENTO INT NOT NULL PRIMARY KEY (CPF) FOREIGN KEY (DEPARTAMENTO) REFERENCES DEPTO (ID_DEPTO) ) Ex.: ORACLE SQL DEVELOPER CREATE TABLE PESSOA ( CPF VARCHAR(11) NOT NULL, NOME VARCHAR(100) NOT NULL, NASCIMENTO DATE NULL, IDADE INT NULL, SALÁRIO NUMBER(8,2) NULL, DEPARTAMENTO INT NOT NULL, PRIMARY KEY (CPF), FOREIGN KEY (DEPARTAMENTO) REFERENCES DEPTO (ID_DEPTO) ) ATENÇÃO !! PK é sempre NOT NULL

  3. INSERT INTO tabela (atributo 1, atributo 2, ... , atributo n) VALUES (dado do atrib. 1, dado do atrib. 2, ... , dado do atrib. n) Utiliza-se essa notação quando não se sabe como a tabela foi criada, quando não se quer inserir dados em todos os atributos ou quando se quer, arbitrariamente, inserir os dados em ordem diferente da qual a tabela foi criada Exemplo: INSERT INTO pessoa (cpf, nome, idade, departamento) VALUES (‘12873568220’, ‘Fulano’, 35, 3) Quando se quer inserir os dados na ordem a qual a tabela foi criada, pode-se omitir os atributos Exemplo: INSERT INTO pessoa VALUES (‘24589634780’, ‘Cicrano’, ’12/03/1985’, 27,3587.34,2)

  4. Para consultar os valores inseridos na tabela, sem filtros: SELECT * FROM tabela

More Related