How to create new users, table spaces, and database table structures under Dameng Database DM8

This article assumes that you have installed Dameng database DM8.

Case requirements description

Three new tables are created in the database and stored in the TBS table space. The information is managed by the TEST user with the password Dameng123. For data security, human resources user HR can only modify: each employee's number (EMPLOYEEID), position (TITLE) and salary (SALARY) information in the EMPLOYEES table. The HR password is set to Dameng23.

The EMPLOYEES table user stores the information of all employees. The table structure is as follows:

The DEPARTMENTS table is used to store all department information. The table structure is as follows:

The PERSON table stores the name information of all employees, suppliers, and customers of the company. The table structure is as follows:

Implementation steps

1. Connect to the database

Call the manager graphical tool:

Log in with the SYSDBA username. Pay attention to the consistency of the port number when creating the database. The default value is 5236:

 

After successfully connecting to the database, the display is as follows:

2. Create table space TBS

Open the table space menu, right-click the mouse and select the "New Table Space" menu:

 

Enter the dialog box for creating a new table space, enter the table space name: TBS, add two table space data files, and set related storage path/size and other parameters.

 

3. Create user TEST

After establishing TBS, right-click on "Manage Users" to create a new user.

 

In the "New User" dialog box, enter the relevant information to create the TEST user. Note that the table space is selected as TBS

 

 

4. Create data table EMPLOYEES

Switch the connection database user to TEST. Under the TEST user, 1. Create the database tableEMPLOYEES. 2. Set pointer PERSON.PERSONID 's foreign key.

create table EMPLOYEES

(

         EMPLOYEEID INT not null, //非空 主键,自增列

         NATIONALNO VARCHAR(18) not null, //non-empty a> personal identification number

         PERSONID INT not null, //非空 指向 PERSON.PERSONID 的外键

         LOGINID VARCHAR(256) not null, //非空 用户登录 ID

         TITLE VARCHAR(50) not null,// 非空 职位

         MANAGERID INT, //

         BIRTHDATE DATE not null, //非空 出生日期

         MARITALSTATUS CHAR(1) not null,// 非空 S=未婚 M=已婚

         PHOTO IMAGE,// Empty Photograph

         HAIRDATE DATE not null, //Non-empty Entry time

         SALARY DEC(19,4) not null,// 非空 薪资(元)

         primary key("EMPLOYEEID")

);

 

 

The task execution error is as follows:

The above error occurs because TEST does not have permission to create tables. Return to the SYSDBA account to assign permissions.

 

Return to the TEST user and execute the SQL statement:

 

5. Create data table DEPARTMENTS

create table DEPARTMENT

(

DEPARTENTID INT not null, //non-empty main key, self-increase sequence

NAME VARCHAR(50) not null,//非空 部门名称

primary key("DEPARTENTID")

);

6. Create data table PERSON

create table PERSON

(

PERSONID INT not null, //Non-empty Main key, Self-increase sequence, Jushu index

NAME VARCHAR(50) not null,//非空 姓名

SEX CHAR(1) not null,//非空 M= F=

EMAIL VARCHAR(50) ,// empty electronic station site

PHONE VARCHAR(25),// 电话

primary key("PERSONID")

);

 

7. Set foreign keys

EMPLOYEES表中,EMPLOYEES.PERSONID指向 PERSON.PERSONID 的外键:

After completion, refresh and you can see the following results:

 

8. Establish user HR

HR can only modify the: each employee's number (EMPLOYEEID), position (TITLE) and salary (SALARY) information in the EMPLOYEES table. The HR password is set to Dameng23.

 

 

 

9. Test and verify HR account

Step 1: First insert some data under the Test account:

insert into PERSON (PERSONID,NAME,SEX)values ('88','maxiaoming','F');

insert into PERSON (PERSONID,NAME,SEX)values ('10','wuxueling','M');

insert into PERSON (PERSONID,NAME,SEX)values ('11','zhangsan','F');

insert into PERSON (PERSONID,NAME,SEX)values ('12','lisi','F');

insert into PERSON (PERSONID,NAME,SEX)values ('13','zhaoliu','F');

insert into PERSON (PERSONID,NAME,SEX)values ('14','Weiming','F');

 

insert into EMPLOYEES (EMPLOYEEID,NATIONALNO,PERSONID,LOGINID,TITLE,BIRTHDATE,MARITALSTATUS,HAIRDATE,SALARY) values ('1001','110112199709072789','88','1101','Master','1997-09-07','S','2008/5/30','12000');

insert into EMPLOYEES (EMPLOYEEID,NATIONALNO,PERSONID,LOGINID,TITLE,BIRTHDATE,MARITALSTATUS,HAIRDATE,SALARY) values ('1002','110112199809032789','10','1101','Master','1998-09-07','S','2008/5/30','15000');

insert into EMPLOYEES (EMPLOYEEID,NATIONALNO,PERSONID,LOGINID,TITLE,BIRTHDATE,MARITALSTATUS,HAIRDATE,SALARY) values ('1003','110112199909072789','11','1101','Master','1999-09-07','S','2008/5/30','18000');

insert into EMPLOYEES (EMPLOYEEID,NATIONALNO,PERSONID,LOGINID,TITLE,BIRTHDATE,MARITALSTATUS,HAIRDATE,SALARY) values ('1004','110112199609072789','12','1101','Master','1996-09-07','S','2008/5/30','19000');

insert into EMPLOYEES (EMPLOYEEID,NATIONALNO,PERSONID,LOGINID,TITLE,BIRTHDATE,MARITALSTATUS,HAIRDATE,SALARY) values ('1005','110112199509072789','13','1101','Master','1995-09-07','S','2008/5/30','20000');

insert into EMPLOYEES (EMPLOYEEID,NATIONALNO,PERSONID,LOGINID,TITLE,BIRTHDATE,MARITALSTATUS,HAIRDATE,SALARY) values ('1006','110112199409072789','14','1101','Master','1994-09-07','S','2008/5/30','22000');

 

Execute query statement:

 

select * from PERSON;

select * from EMPLOYEES;

 

The result is as shown below:

 

Step 2: Establish a new database connection, log in with the HR username and password Dameng123, as shown in the figure below:

 

Step 3: Update information:

update TEST.EMPLOYEES set EMPLOYEEID='100-1' ,TITLE = 'DBA',SALARY ='24000' where EMPLOYEEID='1001';

 

The above SQL fails to execute, prompting that there is no Select permission.

Go back to the SYSDBA user and set the permission Select. :

Re-execute the Update statement:

Finally perform the commit operation.

 

Go to the test user and perform the select operation. You can see that the data has been updated:

Guess you like

Origin blog.csdn.net/qq_27866305/article/details/107047773