Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Constraint Operation of Dameng Database

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Constraint Operation of Dameng Database

The common constraints of Dameng database are primary key constraints, foreign key constraints, unique constraints, and some less commonly used check constraints, non-empty constraints, and so on. Next, we use test1 users to create operations.

1. Create a primary key constraint

Let's first create a tab1 table to test with the test1 user and create an id at the same time

Create table tab1 (id int primary key, name char)

Inserting a piece of data is normal.

Insert into tab1 values (2,'a')

Inserting again will indicate that the insert failed, indicating a violation of the table [TAB1] uniqueness constraint.

Insert into tab1 values (2,'b')

2. Create a foreign key constraint

Create table tab2 (id int unique, name char)

Create table tab3 (id int references tab2 (id), name date)

Inserting data into two tables is normal.

Insert into tab2 values (1,'a')

Insert into tab2 values (2,'b')

Insert into tab3 values (2019-11-28')

Insert into tab3 values (2019-11-28')

Inserting again will prompt the insert to fail, indicating a violation of the reference constraint [CONS134218851].

Insert into tab3 values (3 recorder 2019-11-28')

3. Create a unique constraint

Create table tab4 (id int unique, name char)

Insert data is normal

Insert into tab4 values (1,'a')

Inserting again will prompt the insert to fail, violating the table [tab4] uniqueness constraint.

Insert into tab4 values (1,'b')

4. Add or delete constraints after creating the table

Add constraints after creating the table

Create table tab5 (id int, name char (10))

Alter table tab5 add constraint con_id primary key (id)

Delete constraint

Alter table tab5 drop constraint con_id

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report