Beruflich Dokumente
Kultur Dokumente
Database changed
mysql> show tables;
+---------------------+
| Tables_in_posyandu2 |
+---------------------+
| anggkk
|
| balita
|
| kk
|
| lacak
|
| pemulihan
|
| pmt
|
| timbang
|
| vitamin
|
+---------------------+
8 rows in set (0.00 sec)
mysql> create table job(job_id int(4) Primary KEy, title char(20));
Query OK, 0 rows affected (2.05 sec)
mysql> insert into job values(1,'programmer'),(2,'Tester');
Query OK, 2 rows affected (0.08 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into job values(3,'Manager'),(4,'Spy');
Query OK, 2 rows affected (1.20 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into job values(5,'Detective'),(6,'Forensics');
Query OK, 2 rows affected (1.83 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into job values(7,'Developer');
Query OK, 1 row affected (0.05 sec)
mysql> create table employee(id char(3) primary key,
-> first_name char(10),
-> last_name char(20),
-> start_date date,
-> end_date date,
-> salary float(20),
-> city char(30),
-> jod_id int(3),
-> foreign key(job_id) references job(job_id));
ERROR 1072 (42000): Key column 'job_id' doesn't exist in table
mysql> create table employee(id char(3) primary key,
-> first_name char(10),
-> last_name char(20),
-> start_date date,
-> end_date date,
-> salary float(20),
-> city char(30),
-> job_id int(3),
-> foreign key(job_id) references job(job_id));
Query OK, 0 rows affected (0.14 sec)
mysql> insert into job values (1,'Jason','Martin','1996/07/25','2006/07/25',1235
.56,1);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into job values (1,'Jason','Martin','1996/07/25','2006/07/25',1235
.56,'Toronto',1);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into employee values (1,'Jason','Martin','1996/07/25','2006/07/25'
,1235.56,'Toronto',1);
Query OK, 1 row affected (0.05 sec)
mysql> insert into employee values (2,'Alison','Mathews','1976/03/21','2086/02/2
1',1235/56,'Toronto',2),
-> insert into employee values (2,'Alison','Mathews','1976/03/21','2086/02/2
1',1235/56,'Vancouver',2),
-> \c
mysql> insert into employee values (2,'Alison','Mathews','1976/03/21','1986/02/2
1',6662.78,'Vancouver',2),
-> (3,'James','Smith','1978/12/12','1990/03/15',6545.78,'Vancouver',2);
Query OK, 2 rows affected (0.05 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into employee values (4,'Celia','Rice','1982/10/24','1999/04/21',2
345.78,'Vancouver',3),
-> (5,'Robert','Black','1984/01/12','1998/08/08',2335.78,'Vancouver',2);
Query OK, 2 rows affected (0.63 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into employee values (6,'Linda','Green','1987/07/30','1996/01/04',
4323.78,'New York',3),
-> (7,'David','Larry','1990/12/31','1998/02/12',7898.78,'New York',3);
Query OK, 2 rows affected (1.83 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into employee values (8,'James','Cat','1996/09/17','2002/04/15',12
33.78,'Vancouver',2),
-> (10,'Hercule','Poirot','1973/05/23','2001/08/09',4313.98,'Brussels',5);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into employee values (11,'Lincoln','Rhyme','1999/05/25','2011/07/1
3',3213.98,'New York',6),
-> (12,'Sherlock','Holmes','1923/08/12','1945/07/21',4124.98,'London',5);
Query OK, 2 rows affected (1.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select* from employee;
+----+------------+-----------+------------+------------+---------+-----------+-------+
| id | first_name | last_name | start_date | end_date | salary | city
|
job_id |
+----+------------+-----------+------------+------------+---------+-----------+-------+
| 1 | Jason
| Martin
| 1996-07-25 | 2006-07-25 | 1235.56 | Toronto |
1 |
| 10 | Hercule
| Poirot
| 1973-05-23 | 2001-08-09 | 4313.98 | Brussels |
5 |
| 11 | Lincoln
| Rhyme
| 1999-05-25 | 2011-07-13 | 3213.98 | New York |
6 |
| 12 | Sherlock | Holmes
| 1923-08-12 | 1945-07-21 | 4124.98 | London
|
5 |
| 2 | Alison
| Mathews | 1976-03-21 | 1986-02-21 | 6662.78 | Vancouver |
2 |
| 3 | James
| Smith
| 1978-12-12 | 1990-03-15 | 6545.78 | Vancouver |
2 |
| 4 | Celia
| Rice
| 1982-10-24 | 1999-04-21 | 2345.78 | Vancouver |
3 |
| 5 | Robert
| Black
| 1984-01-12 | 1998-08-08 | 2335.78 | Vancouver |
2 |
| 6 | Linda
| Green
| 1987-07-30 | 1996-01-04 | 4323.78 | New York |
3 |
| 7 | David
| Larry
| 1990-12-31 | 1998-02-12 | 7898.78 | New York |
3 |
| 8 | James
| Cat
| 1996-09-17 | 2002-04-15 | 1233.78 | Vancouver |
2 |
+----+------------+-----------+------------+------------+---------+-----------+-------+
11 rows in set (0.05 sec)
mysql> select* from employee order by employee;
ERROR 1054 (42S22): Unknown column 'employee' in 'order clause'
mysql> select* from employee order by id;
+----+------------+-----------+------------+------------+---------+-----------+-------+
| id | first_name | last_name | start_date | end_date | salary | city
|
job_id |
+----+------------+-----------+------------+------------+---------+-----------+-------+
| 1 | Jason
| Martin
| 1996-07-25 | 2006-07-25 | 1235.56 | Toronto |
1 |
| 10 | Hercule
| Poirot
| 1973-05-23 | 2001-08-09 | 4313.98 | Brussels |
5 |
| 11 | Lincoln
| Rhyme
| 1999-05-25 | 2011-07-13 | 3213.98 | New York |
6 |
| 12 | Sherlock | Holmes
| 1923-08-12 | 1945-07-21 | 4124.98 | London
|
5 |
| 2 | Alison
| Mathews | 1976-03-21 | 1986-02-21 | 6662.78 | Vancouver |
2 |
| 3 | James
| Smith
| 1978-12-12 | 1990-03-15 | 6545.78 | Vancouver |
2 |
| 4 | Celia
| Rice
| 1982-10-24 | 1999-04-21 | 2345.78 | Vancouver |
3 |
| 5 | Robert
| Black
| 1984-01-12 | 1998-08-08 | 2335.78 | Vancouver |
2 |
| 6 | Linda
| Green
| 1987-07-30 | 1996-01-04 | 4323.78 | New York |
3 |
| 7 | David
| Larry
| 1990-12-31 | 1998-02-12 | 7898.78 | New York |
3 |
| 8 | James
| Cat
| 1996-09-17 | 2002-04-15 | 1233.78 | Vancouver |
2 |
+----+------------+-----------+------------+------------+---------+-----------+-------+
11 rows in set (0.00 sec)
mysql> decs emlployee;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version
for the right syntax to use near 'decs emlployee' at line 1
mysql> decs employee;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version
for the right syntax to use near 'decs employee' at line 1
mysql> desc employee;
+------------+----------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| id
| char(3) | NO | PRI |
|
|
| first_name | char(10) | YES |
| NULL
|
|
| last_name | char(20) | YES |
| NULL
|
|
| start_date | date
| YES |
| NULL
|
|
| end_date | date
| YES |
| NULL
|
|
| salary
| float
| YES |
| NULL
|
|
| city
| char(30) | YES |
| NULL
|
|
| job_id
| int(3) | YES | MUL | NULL
|
|
+------------+----------+------+-----+---------+-------+
8 rows in set (0.79 sec)
mysql> alter table employee modify id int;
Query OK, 11 rows affected (1.01 sec)
Records: 11 Duplicates: 0 Warnings: 0
mysql> desc employee;
+------------+----------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| id
| int(11) | NO | PRI | 0
|
|
| first_name | char(10) | YES |
| NULL
|
|
| last_name | char(20) | YES |
| NULL
|
|
| start_date | date
| YES |
| NULL
|
|
| end_date | date
| YES |
| NULL
|
|
| salary
| float
| YES |
| NULL
|
|
| city
| char(30) | YES |
| NULL
|
|
| job_id
| int(3) | YES | MUL | NULL
|
|
+------------+----------+------+-----+---------+-------+
8 rows in set (0.01 sec)
mysql> select* from employee;
+----+------------+-----------+------------+------------+---------+-----------+-------+
| id | first_name | last_name | start_date | end_date | salary | city
|
job_id |
+----+------------+-----------+------------+------------+---------+-----------+-------+
| 1 | Jason
| Martin
| 1996-07-25 | 2006-07-25 | 1235.56 | Toronto |
1 |
| 2 | Alison
| Mathews | 1976-03-21 | 1986-02-21 | 6662.78 | Vancouver |
2 |
| 3 | James
| Smith
| 1978-12-12 | 1990-03-15 | 6545.78 | Vancouver |
2 |
| 4 | Celia
| Rice
| 1982-10-24 | 1999-04-21 | 2345.78 | Vancouver |
3 |
| 5 | Robert
| Black
| 1984-01-12 | 1998-08-08 | 2335.78 | Vancouver |
2 |
| 6 | Linda
| Green
| 1987-07-30 | 1996-01-04 | 4323.78 | New York |
3 |
| 7 | David
| Larry
| 1990-12-31 | 1998-02-12 | 7898.78 | New York |
3 |
| 8 | James
| Cat
| 1996-09-17 | 2002-04-15 | 1233.78 | Vancouver |
2 |
| 10 | Hercule
| Poirot
| 1973-05-23 | 2001-08-09 | 4313.98 | Brussels |
5 |
| 11 | Lincoln
| Rhyme
| 1999-05-25 | 2011-07-13 | 3213.98 | New York |
6 |
| 12 | Sherlock | Holmes
| 1923-08-12 | 1945-07-21 | 4124.98 | London
|
5 |
+----+------------+-----------+------------+------------+---------+-----------+-------+
11 rows in set (0.00 sec)
mysql> DELIMITER //
mysql> CREATE TRIGGER before_insert BEFORE INSERT ON employee
-> FOR EACH ROW
-> BEGIN
-> IF NEW.salary IS NULL OR NEW.salary=0 THEN
-> SET NEW.salary=1000;
-> else
-> SET NEW.salary= NEW.salary+100;
-> END IF;
-> END //
Query OK, 0 rows affected (0.33 sec)
mysql> DELIMITER ;
mysql> insert into employee values (14,'Lincoln','Rhyme','1999/05/25','2011/07/1
3',null,'New York',6);
Query OK, 1 row affected (1.85 sec)
mysql> select* from employee;
+----+------------+-----------+------------+------------+---------+-----------+-------+
| id | first_name | last_name | start_date | end_date | salary | city
|
job_id |
+----+------------+-----------+------------+------------+---------+-----------+-------+
| 1 | Jason
| Martin
| 1996-07-25 | 2006-07-25 | 1235.56 | Toronto |
1 |
| 2 | Alison
| Mathews | 1976-03-21 | 1986-02-21 | 6662.78 | Vancouver |
2 |
| 3 | James
| Smith
| 1978-12-12 | 1990-03-15 | 6545.78 | Vancouver |
2 |
| 4 | Celia
| Rice
| 1982-10-24 | 1999-04-21 | 2345.78 | Vancouver |
3 |
| 5 | Robert
| Black
| 1984-01-12 | 1998-08-08 | 2335.78 | Vancouver |
2 |
| 6 | Linda
| Green
| 1987-07-30 | 1996-01-04 | 4323.78 | New York |
3 |
| 7 | David
| Larry
| 1990-12-31 | 1998-02-12 | 7898.78 | New York |
3 |
| 8 | James
| Cat
| 1996-09-17 | 2002-04-15 | 1233.78 | Vancouver |
2 |
| 10 | Hercule
| Poirot
| 1973-05-23 | 2001-08-09 | 4313.98 | Brussels |
5 |
| 11 | Lincoln
| Rhyme
| 1999-05-25 | 2011-07-13 | 3213.98 | New York |
6 |
| 12 | Sherlock | Holmes
| 1923-08-12 | 1945-07-21 | 4124.98 | London
|
5 |
| 14 | Lincoln
| Rhyme
| 1999-05-25 | 2011-07-13 |
1000 | New York |
6 |
+----+------------+-----------+------------+------------+---------+-----------+-------+
12 rows in set (0.00 sec)
mysql> create table trans_log(
-> user_id varchar(15),
-> description varchar(50));
Query OK, 0 rows affected (1.85 sec)
mysql> DELIMITER $$
mysql> CREATE TRIGGER log_salary AFTER UPDATE
-> ON employee
-> for EACH ROW
-> BEGIN
->
insert into trans_log
-> values (user(),CONCAT(' merubah akun ',NEW.id,' dari ',OLD.salary,' to ',
New.salary));
-> end $$;
Query OK, 0 rows affected (0.01 sec)
-> DELIMITER ;
-> \C
ERROR:
Usage: \C char_setname | charset charset_name
-> \c
mysql> DELIMITER $$
mysql> CREATE TRIGGER log_salary AFTER UPDATE
-> ON employee
-> for EACH ROW
-> BEGIN
->
insert into trans_log
-> values (user(),CONCAT(' merubah akun ',NEW.id,' dari ',OLD.salary,' to ',
New.salary));
-> end $$;
ERROR 1235 (42000): This version of MySQL doesn't yet support 'multiple triggers
with the same action time and event for
one table'
-> delimiter;
-> DELIMITER ;
-> DELOMITER;
-> DELIMITER;
-> DELIMITER ;
-> DELIMITER ;
-> DELIMITER&&;
-> \C
ERROR:
Usage: \C char_setname | charset charset_name
-> \c
mysql> update emlpoyee SET salary=salary+1000;
-> \C
ERROR:
Usage: \C char_setname | charset charset_name
-> \c]
-> \c
mysql> DELIMITER ;
mysql> update emlpoyee SET salary=salary+1000;
ERROR 1146 (42S02): Table 'posyandu2.emlpoyee' doesn't exist
mysql> update employee SET salary=salary+1000;
Query OK, 12 rows affected (1.85 sec)
Rows matched: 12 Changed: 12 Warnings: 0
mysql> select*FROM trans_log;
+----------------+------------------------------------------+
| user_id
| description
|
+----------------+------------------------------------------+
| root@localhost | merubah akun 1 dari 1235.56 to 2235.56 |
| root@localhost | merubah akun 2 dari 6662.78 to 7662.78 |
| root@localhost | merubah akun 3 dari 6545.78 to 7545.78 |
mysql> delimiter ;
mysql> delete from employee where id=14;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from employee where id=13;
Query OK, 0 rows affected (0.00 sec)
mysql> select*from employee_bak;
+----+------------+-----------+------------+----------+--------+------+--------+
| id | first_name | last_name | start_date | end_date | salary | city | job_id |
+----+------------+-----------+------------+----------+--------+------+--------+
| 0 | NULL
| NULL
| NULL
| NULL
| NULL | NULL | NULL |
+----+------------+-----------+------------+----------+--------+------+--------+
1 row in set (0.00 sec)
mysql> select*from employee;
+----+------------+-----------+------------+------------+---------+-----------+-------+
| id | first_name | last_name | start_date | end_date | salary | city
|
job_id |
+----+------------+-----------+------------+------------+---------+-----------+-------+
| 1 | Jason
| Martin
| 1996-07-25 | 2006-07-25 | 2235.56 | Toronto |
1 |
| 2 | Alison
| Mathews | 1976-03-21 | 1986-02-21 | 7662.78 | Vancouver |
2 |
| 3 | James
| Smith
| 1978-12-12 | 1990-03-15 | 7545.78 | Vancouver |
2 |
| 4 | Celia
| Rice
| 1982-10-24 | 1999-04-21 | 3345.78 | Vancouver |
3 |
| 5 | Robert
| Black
| 1984-01-12 | 1998-08-08 | 3335.78 | Vancouver |
2 |
| 6 | Linda
| Green
| 1987-07-30 | 1996-01-04 | 5323.78 | New York |
3 |
| 7 | David
| Larry
| 1990-12-31 | 1998-02-12 | 8898.78 | New York |
3 |
| 8 | James
| Cat
| 1996-09-17 | 2002-04-15 | 2233.78 | Vancouver |
2 |
| 10 | Hercule
| Poirot
| 1973-05-23 | 2001-08-09 | 5313.98 | Brussels |
5 |
| 11 | Lincoln
| Rhyme
| 1999-05-25 | 2011-07-13 | 4213.98 | New York |
6 |
| 12 | Sherlock | Holmes
| 1923-08-12 | 1945-07-21 | 5124.98 | London
|
5 |
+----+------------+-----------+------------+------------+---------+-----------+-------+
11 rows in set (0.00 sec)
mysql> delete from employee where id=12;
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql>
mysql>mysql> DELIMITER //
mysql> CREATE TRIGGER hapus_data after DELETE
-> ON employee
-> FOR EACH ROW
-> BEGIN
-> insert into employee_bak values(OLD.id,OLD.first_name,OLD.last_name,
-> OLD.start_date,OLD.end_date,OLD.salary,OLD.city,OLD.job_id);
-> END //
Query OK, 0 rows affected (0.01 sec)
mysql> DELIMITER ;
mysql> delete from employee where id=10;
Query OK, 1 row affected (1.07 sec)
mysql> select*from employee_bak;
+----+------------+-----------+------------+------------+---------+----------+-------+
| id | first_name | last_name | start_date | end_date | salary | city
| j
ob_id |
+----+------------+-----------+------------+------------+---------+----------+-------+
| 0 | NULL
| NULL
| NULL
| NULL
|
NULL | NULL
|
NULL |
| 10 | Hercule
| Poirot
| 1973-05-23 | 2001-08-09 | 5313.98 | Brussels |
5 |
+----+------------+-----------+------------+------------+---------+----------+-------+
2 rows in set (0.00 sec)
mysql> delete from employee where id=11;
Query OK, 1 row affected (0.19 sec)
mysql> select*from employee_bak;
+----+------------+-----------+------------+------------+---------+----------+-------+
| id | first_name | last_name | start_date | end_date | salary | city
| j
ob_id |
+----+------------+-----------+------------+------------+---------+----------+-------+
| 0 | NULL
| NULL
| NULL
| NULL
|
NULL | NULL
|
NULL |
| 10 | Hercule
| Poirot
| 1973-05-23 | 2001-08-09 | 5313.98 | Brussels |
5 |
| 11 | Lincoln
| Rhyme
| 1999-05-25 | 2011-07-13 | 4213.98 | New York |
6 |
+----+------------+-----------+------------+------------+---------+----------+-------+
3 rows in set (0.00 sec)
mysql> select*from employee;
+----+------------+-----------+------------+------------+---------+-----------+-------+
| id | first_name | last_name | start_date | end_date | salary | city
|
job_id |
+----+------------+-----------+------------+------------+---------+-----------+-------+
| 1 | Jason
| Martin
| 1996-07-25 | 2006-07-25 | 2235.56 | Toronto |
1 |
| 2 | Alison
| Mathews | 1976-03-21 | 1986-02-21 | 7662.78 | Vancouver |
2 |
| 3 | James
| Smith
| 1978-12-12 | 1990-03-15 | 7545.78 | Vancouver |
2 |
| 4 | Celia
| Rice
| 1982-10-24 | 1999-04-21 | 3345.78 | Vancouver |
3 |
| 5 | Robert
| Black
| 1984-01-12 | 1998-08-08 | 3335.78 | Vancouver |
2 |
| 6 | Linda
| Green
| 1987-07-30 | 1996-01-04 | 5323.78 | New York |
3 |
| 7 | David
| Larry
| 1990-12-31 | 1998-02-12 | 8898.78 | New York |
3 |
| 8 | James
| Cat
| 1996-09-17 | 2002-04-15 | 2233.78 | Vancouver |
2 |
| 12 | Sherlock | Holmes
| 1923-08-12 | 1945-07-21 | 5124.98 | London
|
5 |
+----+------------+-----------+------------+------------+---------+-----------+-------+
9 rows in set (0.00 sec)
mysql> create table history_job (tglUpdate date,User char(20),id_job int(7),Nama
_job char(30));
Query OK, 0 rows affected (1.87 sec)
mysql> select *from history_job;
Empty set (0.00 sec)
mysql> delimiter //
mysql> CREATE TRIGGER historyjob after UPDATE
-> ON job
-> FOR EACH ROW
-> BEGIN
-> INSERT INTO HISTORY_JOB VALUES (DATE(NOW()),user(),OLD.job_id,OLD.title
);
-> end //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> update job set title="Forensik" where job_id=6;
Query OK, 1 row affected (1.08 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select*from history_job;
+------------+----------------+--------+-----------+
| tglUpdate | User
| id_job | Nama_job |
+------------+----------------+--------+-----------+
| 2014-02-15 | root@localhost |
6 | Forensics |
+------------+----------------+--------+-----------+
1 row in set (0.00 sec)
mysql>
mysql> update job set title="Forensics" where job_id=6;
Query OK, 1 row affected (1.79 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select*from history_job;
+------------+----------------+--------+-----------+
| tglUpdate | User
| id_job | Nama_job |
+------------+----------------+--------+-----------+
| 2014-02-15 | root@localhost |
6 | Forensics |
| 2014-02-15 | root@localhost |
6 | Forensik |
+------------+----------------+--------+-----------+
2 rows in set (0.00 sec)
-> end //
Query OK, 0 rows affected (0.01 sec)
mysql> delimiter ;