Dameng Database (Part II)

Source: Internet
Author: User

1. Dream Database Creation Table

Dream Data After the installation is complete, open DM Management tool, you can do the relevant operations of the database. You can create a new table file under the table path under table space main by creating a new query, entering an SQL statement in the SQL command window, making a table, and after the SQL input is completed and selecting SQL for execution, such as:

2. Establish a primary key

CREATE table when creating a primary key with primary key

Example:create table person (ID int primary key, name varchar (), address varchar (60))

or by an ALTER statement

such as:create table person33 (ID int,name varchar (), address varchar (60));

Alter table person33 add constraint pk_id primary key (ID)

The table that created the primary key will be thrown incorrectly when inserting a record with a null primary key, and the insertion fails.

For example : INSERT INTO Person33 values(null, ' hfjh ', ' JKASJFKSJDF ') will insert failure.

3. Building an Index

Create [or replace] [Cluster| not parial] [unique| Bitmap| Spatial] index index_name on table_name (< index column definition >)

such as:create index index_id on person33 (ID);

4. Create a foreign key

the ID of the--b table as a foreign key for table a

Create Table B (Id int primary key identity, names varchar (20));

Create Table A (id int primary key identity, names varchar (),foreign key(ID) References B (ID))

5. Building a View

Create View View_person as select id,name,address from Person33 where name = ' Hfjh ';

Select * from View_person

6. Establishing constraints

Create table person55 (ID int,name varchar (), age int,address varchar (60));

6.1. Add primary KEY constraint (ID as primary key)

Alter table person55 add constraint pkID primary key(ID)

6.2. Add a unique constraint (name unique)

Alter table person55 add constraint uq_name unique(name)

6.3. Add a DEFAULT constraint (the default is "address unknown" if the address is not filled in)

Alter table person55 add constraint address default(' addresses unknown ') for Address

6.4. Add a Check constraint (age-limited)

Alter table person55 add constraint ck_age check (age between and 40)

6.5. Add a FOREIGN KEY constraint

7. All field types supported by the database

7.1char,varchar,varchar2

7.2numeric,decimal,dec,number,integer,int,bigint,tinyint,byte,smallint,binary,varbinary

7.3float,double,real,double Precision

7.4bit

7.5date,time,timestamp

7.6 Time interval and time zone type

7.8text,longvarchar,image,blob,clob

8. Create a Trigger

create [or replace] trigger trigger name [with encryption] Before|after|instead of delete|insert|update [of column name] on table name [for each row [When conditions]]

Begin

PL/SQL statements

End;

Such as:

CREATE TRIGGER Inserttrigger

After INSERT on Person55

for  each ROW

BEGIN

Update person55 set id = id + 1;

END;

Insert into Person55 values(" Zhang San ", " Xian City, Shaanxi province ");

Select * from Person55;

Create Trigger update_trg11 after update of name on Person55

for  each Statement

Begin

Update person55 set id = id + 1;

End

Update person55 set name = ' 33 one ' where name = ' 33 1 '

Dameng Database (Part II)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.