All pastes #947424 Raw Edit

wkk

public text v1 · immutable
·published 2008-03-18 14:19 UTC
rendered paste body
[root@gandalf root]# mysql -p < mondir.sql
Enter password:
[root@gandalf root]# cat mondir.sql
CREATE DATABASE IF NOT EXISTS mondir;
USE mondir;
CREATE TABLE IF NOT EXISTS clients (
        client          VARCHAR(20) NOT NULL
);

CREATE TABLE IF NOT EXISTS projects (
        client          VARCHAR(20) NOT NULL,
        project         VARCHAR(10) NOT NULL
);

CREATE TABLE IF NOT EXISTS date (
        date            DATE
);

CREATE TABLE IF NOT EXISTS size_day (
        client          VARCHAR(20) NOT NULL,
        project         VARCHAR(10) NOT NULL,
        date            DATE,
        size            BIGINT(10) NOT NULL
);

ALTER TABLE clients
        ADD PRIMARY KEY (client);

ALTER TABLE projects
        ADD PRIMARY KEY (project),
        ADD FOREIGN KEY (client) REFERENCES clients(client);

ALTER TABLE date
        ADD PRIMARY KEY (date);

ALTER TABLE size_day
        ADD FOREIGN KEY (client) REFERENCES clients(client),
        ADD FOREIGN KEY (project) REFERENCES projects(project),
        ADD FOREIGN KEY (date) REFERENCES date(date);
[root@gandalf root]# mysql -u mondir -p mondir
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 35193
Server version: 5.0.41 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show tables;
+------------------+
| Tables_in_mondir |
+------------------+
| clients          |
| date             |
| projects         |
| size_day         |
+------------------+
4 rows in set (0,00 sec)

mysql> insert into projects(client,project) values ('teste','nada');
Query OK, 1 row affected (0,00 sec)

mysql> select * from projects;
+--------+---------+
| client | project |
+--------+---------+
| teste  | nada    |
+--------+---------+
1 row in set (0,00 sec)

mysql> show columns from projects;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| client  | varchar(20) | NO   | MUL |         |       |
| project | varchar(10) | NO   | PRI |         |       |
+---------+-------------+------+-----+---------+-------+
2 rows in set (0,00 sec)

mysql>