CREATE DATABASE sdx_v1;
USE sdx_v1;
CREATE TABLE sdx_user ( 
code varchar(50) NOT NULL,
passwd varchar(50), 
first_name varchar(100), 
last_name varchar(100), 
language char(2), 
PRIMARY KEY (code)
);
CREATE TABLE sdx_privilege (
user_code varchar(50) NOT NULL,
db_code varchar(100) NOT NULL,
type char(1) NOT NULL,
PRIMARY KEY (user_code,db_code)
); 
CREATE TABLE sdx_db (
code varchar(100) NOT NULL,
admin_name varchar(100),
admin_email varchar(255),
PRIMARY KEY (code) 
);
CREATE TABLE sdx_group 
(db VARCHAR(100) NOT NULL, 
name VARCHAR(255) NOT NULL, 
description VARCHAR(255), 
PRIMARY KEY(db, name)
);
CREATE TABLE sdx_user_group 
(db VARCHAR(100) NOT NULL, 
user VARCHAR(50) NOT NULL,  
gr VARCHAR(255) NOT NULL, 
ty CHAR(1) NOT NULL, 
PRIMARY KEY (db, user, gr, ty)
);
INSERT INTO sdx_user (first_name, last_name, code, passwd, language) 
VALUES ('', 'Administrateur', 'admin', 'nimda', 'fr');
INSERT INTO sdx_privilege ( user_code, db_code, type ) 
VALUES ('admin', ' ', 's');
GRANT ALL PRIVILEGES 
ON sdx_v1.*
TO sdx@localhost 
IDENTIFIED BY 'xml';
