Basic User Privilege Management Example On Oracle Database
In case we will create user schemes namely MI123, Tamu1 and Tamu2. User MI123 have two tables namely T1 and T2. Here are some examples for managing user objects for those user schemes.
ID Nama KODE NILAI ID
------------------- ----------------------------------
1 Satu N1 70 1
2 Dua N2 80 1
3 Tiga N3 70 2
------------------- N4 90 3
-------------------------------
CREATE TABLE T1(
ID NUMBER PRIMARY KEY,
NAMA VARCHAR2(24)
);
INSERT INTO T1(id, nama) VALUES(1, ‘Satu’);
INSERT INTO T1(id, nama) VALUES(2, ‘Dua’);
INSERT INTO T1(id, nama) VALUES(3, ‘Tiga’);
COMMIT;
CREATE TABLE T2(
KODE VARCHAR2(4),
NILAI NUMBER,
ID NUMBER,
CONSTRAINT fk1 FOREIGN KEY(ID) REFERENCES T1(ID)
);
INSERT INTO T2 VALUES(‘N1’, 70, 1);
INSERT INTO T2 VALUES(‘N2’, 80, 1);
INSERT INTO T2 VALUES(‘N3’, 70, 2);
INSERT INTO T2 VALUES(‘N4’, 90, 3);
COMMIT;
Connected.
SQL> select * from mi123.t2;
KODE NILAI ID
---- ---------- ------
N1 70 1
N2 80 1
N3 70 2
N4 90 3
- Create new user scheme (MI123)
- Grant user privileges to user for login and create user!
- Create 2 database objects (table T1 & table T2)
ID Nama KODE NILAI ID
------------------- ----------------------------------
1 Satu N1 70 1
2 Dua N2 80 1
3 Tiga N3 70 2
------------------- N4 90 3
-------------------------------
CREATE TABLE T1(
ID NUMBER PRIMARY KEY,
NAMA VARCHAR2(24)
);
INSERT INTO T1(id, nama) VALUES(1, ‘Satu’);
INSERT INTO T1(id, nama) VALUES(2, ‘Dua’);
INSERT INTO T1(id, nama) VALUES(3, ‘Tiga’);
COMMIT;
CREATE TABLE T2(
KODE VARCHAR2(4),
NILAI NUMBER,
ID NUMBER,
CONSTRAINT fk1 FOREIGN KEY(ID) REFERENCES T1(ID)
);
INSERT INTO T2 VALUES(‘N1’, 70, 1);
INSERT INTO T2 VALUES(‘N2’, 80, 1);
INSERT INTO T2 VALUES(‘N3’, 70, 2);
INSERT INTO T2 VALUES(‘N4’, 90, 3);
COMMIT;
- Create new user namely Tamu1 and Tamu2!
- Create privilege to Tamu1 user for viewing T1 table!
- Create privilege for inputing data (INSERT) on Tabel T1 to Tamu2 user!
- Show data on T1 Table while login with Tamu1 user! Is it works?
- Show data on T1 Table while login with Tamu2 user! Is it works?
- Login as Tamu1 user, type this sentence:
- Login as Tamu2 user, show the data of T2 table!
Connected.
SQL> select * from mi123.t2;
KODE NILAI ID
---- ---------- ------
N1 70 1
N2 80 1
N3 70 2
N4 90 3
Leave a Comment