开发者

Adding constraints is DDL or DML

Adding constraints in sql server comes under which category 开发者_如何转开发DML or DDL?


DDL, as you're defining the relationships between tables, not modifying the data stored in them.


DDL, since they alter the structure rather than the data.

For example: Referential integrity statements


Constraints must be DDL statements.Let's prove it. Create two tables A and B as follows:

create table A ( id int primary key );

create table B ( id int, foreign key id references A(id) );

Now, let's try to insert some data in table A, and then table B.

INSERT into A values (1);

INSERT into B values (1);

Now, try to run TRUNCATE A; It will give Foreign Key Constraint Fail error. It means that Constraints are applied on schema of tables, hence DDL statements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜