SHARE
TWEET

Untitled

SQLSoldier Jul 18th, 2015 211 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE DATABASE TestUC;
  2. GO
  3.  
  4. USE TestUC;
  5. GO
  6.  
  7. SELECT * INTO dbo.AllDBs1
  8. FROM sys.DATABASES;
  9.  
  10. SELECT * INTO dbo.AllDBs2
  11. FROM sys.DATABASES;
  12. GO
  13.  
  14. CREATE UNIQUE INDEX UQ_AllDBs1 ON dbo.AllDBs1(database_id);
  15.  
  16. ALTER TABLE dbo.AllDBs2 ADD CONSTRAINT UQ_AllDBs2 UNIQUE (database_id);
  17. GO
  18.  
  19. SELECT Name, is_unique_constraint
  20. FROM sys.indexes
  21. WHERE object_id IN (object_id(N'dbo.AllDBs1'), object_id(N'dbo.AllDBs2'))
  22. AND is_unique = 1;
  23.  
  24. SELECT *
  25. FROM sys.key_constraints
  26. WHERE parent_object_id IN (object_id(N'dbo.AllDBs1'), object_id(N'dbo.AllDBs2'));
RAW Paste Data
Top