BhSite - Tutorial de MySql - pag08 <a href="http://www.bhsite.com.br">hospedagem</a> DE SITES REGISTRO DE DOMINIO GRATIS

Via Boleto Bancário
Login:
Senha:
Hospedagem de Sites
- Estrutura
- Contratar
- Planos
- Revenda
Registro de Domínios
- Registre seu Domínio
Suporte
- Help Desk
- Atendimento via E-mail
Atendimento Telefônico
Atendimento Telefônico

Suporte BHSite (Hospedagem de Sites)
 


Guia passo a passo do MySQL


Tutorial de MySQL

 

Página 8

| article | dealer | price |
+---------+--------+-------+
|    0001 | B      |  3.99 |
|    0002 | A      | 10.99 |
|    0003 | C      |  1.69 |
|    0004 | D      | 19.95 |
+---------+--------+-------+

 

Usando chaves estrangeiras

Você não necessita de chaves estrangeiras para unir 2 tabelas. O MySQL não faz a checagem de certificar que as chaves da tabela são referências e isto não é feito automaticamente apagando as filas da tabela com uma definição de chave estrangeira. Se você usa as chaves normais, ele trabalhará perfeitamente.

 

CREATE TABLE persons (
    id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
    name CHAR(60) NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE shirts (
    id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
    style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
    color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
    owner SMALLINT UNSIGNED NOT NULL REFERENCES persons,
    PRIMARY KEY (id)
);

INSERT INTO persons VALUES (NULL, 'Antonio Paz');

INSERT INTO shirts VALUES
(NULL, 'polo', 'blue', LAST_INSERT_ID()),
(NULL, 'dress', 'white', LAST_INSERT_ID()),
(NULL, 't-shirt', 'blue', LAST_INSERT_ID());

INSERT INTO persons VALUES (NULL, 'Lilliana Angelovska');

INSERT INTO shirts VALUES
(NULL, 'dress', 'orange', LAST_INSERT_ID()),
(NULL, 'polo', 'red', LAST_INSERT_ID()),
(NULL, 'dress', 'blue', LAST_INSERT_ID()),
(NULL, 't-shirt', 'white', LAST_INSERT_ID());

SELECT * FROM persons;
+----+---------------------+
| id | name                |
+----+---------------------+
| 1  | Antonio Paz         |

 



hospedagem DE SITES E REGISTRO DE DOMÍNIO GRATIS É NA BHSITE.COM.BR