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

How to release logarithm constraint when loading data in SQLserver

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

SQLserver in how to load data when lifting logarithmic constraints, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

When loading data into a table, you sometimes have to unconstrain the table. Assuming that the table has been deleted or corrupted, it is more likely that the table contains referential integrity constraints such as external keywords, and the database will not allow data that does not have a related relationship in other tables to be inserted into the table. if the reference column does not exist in other tables, you may have to unconstrain the table when the data is initially loaded. Of course, when the load is successful, these constraints should be restored.

INPUT

SQL > SET ECHO OFF

SQL > SET FEEDBACK OFF

SQL > SET HEADING OFF

SQL > SPOOL DISABLE.SQL

SQL > SELECT 'ALTER TABLE' | | TABLE_NAME | |

2 'DISABLE CONSTRAINT' | | CONSTRAINT_NAME | |';'

3 FROM SYS.DBA_CONSTRAINTS

4 WHERE OWNER = 'RYAN'

5 /

OUTPUT

ALTER TABLE ACCT_PAY DISABLE CONSTRAINT FK_ACCT_ID

ALTER TABLE ACCT_REC DISABLE CONSTRAINT FK_ACCT_ID

ALTER TABLE CUSTOMERS DISABLE CONSTRAINT FK_CUSTOMER_ID

ALTER TABLE HISTORY DISABLE CONSTRAINT FK_ACCT_ID

ALTER TABLE INVOICES DISABLE CONSTRAINT FK_ACCT_ID

ALTER TABLE ORDERS DISABLE CONSTRAINT FK_ACCT_ID

This object has generated a series of ALTER TABLE statements to undo all tables owned by RYAN, and the semicolon at the end of the concatenator is to ensure the integrity of each statement.

INPUT/OUTPUT

SQL > SPOOL OFF

SQL > SET ECHO OFF

SQL > SET FEEDBACK ON

SQL > START DISABLE.SQL

Constraint Disabled.

Constraint Disabled.

Constraint Disabled.

Constraint Disabled.

Constraint Disabled.

Constraint Disabled.

Notice here that ECHO is set to OFF, which means that you will not see the corresponding statement when executing, but because FEEDBACK is set to ON, you can see the result Constraint Disabled. If both ECHO and FEEDBACK are set to OFF, nothing will be displayed during execution, but after a period of pause, you will return to the prompt of SQL >, and now you can safely load your data without worrying about errors caused by constraints. Constraints are good, but they create obstacles when data is loaded, and you can use the same idea to restore constraints on tables.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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