Breaking News
Loading...
09/10/2013

1 câu hỏi về Truncate table

Truncate We have created following table:
CREATE TABLE dbo.T_EMPLOYEE
( EmpNo VARCHAR(20) NOT NULL PRIMARY KEY, 
  EmpName VARCHAR(50), 
  EmpContact VARCHAR(20), 
  EmpManager VARCHAR(20)
 FOREIGN KEY REFERENCES dbo.T_EMPLOYEE(EmpNo));
Here is the data populated:

INSERT INTO dbo.T_EMPLOYEE SELECT 'E1001', 'Steve Smith', '+1-723-2311', NULL
INSERT INTO dbo.T_EMPLOYEE SELECT 'E1002', 'Raj Shekhar', '+1-723-2145', 'E1001'
INSERT INTO dbo.T_EMPLOYEE SELECT 'E1003', 'Kelly Brook', '+1-723-1648', 'E1001'
INSERT INTO dbo.T_EMPLOYEE SELECT 'E1004', 'Sam Samson', '+1-724-2386', 'E1002'
INSERT INTO dbo.T_EMPLOYEE SELECT 'E1005', 'Keith Hunt', '+1-724-5689', 'E1003'
Now I try the following command:

TRUNCATE TABLE dbo.T_EMPLOYEE
What will be the result? Choose your answer: Command(s) completed successfully. Cannot truncate table 'dbo.T_EMPLOYEE' because it is being referenced by a FOREIGN KEY constraint. Such table cannot be created as self reference to a table is not allowed. Correct answer: Command(s) completed successfully. Explanation: You cannot use TRUNCATE TABLE on tables that are referenced by a FOREIGN KEY constraint UNLESS that table has a foreign key that references itself. Check the BOL link: http://technet.microsoft.com/en-us/library/ms177570.aspx

0 comments:

Post a Comment

 
Toggle Footer