/* Drop the STUDENT-TEAM database table. Due to referential integrity constraints, the tables should be dropped in a particular order. In a one-to-many relationship the "many" side is dropped first. NOTE: This is the reverse in which the tables must be created. In a one-to-many relationship the "one" table is created first so the foreign key constraint can be created in the "many" table. The SQL below is specifically for Transact-SQL. Note the use of square brackets around object names, such as the table name and the columns names. This code was generated by MSSMS. To get this code, use the context menu (right-click an table), and select SCRIPT TABLE AS ... DROP TO .... */ /* Drop any constraints and the table EVAL_ITEMS_SCORES. */ IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_eval_id]') AND parent_object_id = OBJECT_ID(N'[dbo].[eval_items_scores]')) ALTER TABLE [dbo].[eval_items_scores] DROP CONSTRAINT [fk_eval_id] GO IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_eval_item_id]') AND parent_object_id = OBJECT_ID(N'[dbo].[eval_items_scores]')) ALTER TABLE [dbo].[eval_items_scores] DROP CONSTRAINT [fk_eval_item_id] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[eval_items_scores]') AND type in (N'U')) DROP TABLE [dbo].[eval_items_scores] GO /* Drop any constraints and the table EVALUATIONS. */ IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_evaluateeID]') AND parent_object_id = OBJECT_ID(N'[dbo].[evaluations]')) ALTER TABLE [dbo].[evaluations] DROP CONSTRAINT [fk_evaluateeID] GO IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_evaluatorID]') AND parent_object_id = OBJECT_ID(N'[dbo].[evaluations]')) ALTER TABLE [dbo].[evaluations] DROP CONSTRAINT [fk_evaluatorID] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[evaluations]') AND type in (N'U')) DROP TABLE [dbo].[evaluations] GO /* Drop any constraints and the table EVAL_ITEMS. */ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[eval_items]') AND type in (N'U')) DROP TABLE [dbo].[eval_items] GO /* Drop any constraints and the table STUDENTS. */ IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_teamid]') AND parent_object_id = OBJECT_ID(N'[dbo].[students]')) ALTER TABLE [dbo].[students] DROP CONSTRAINT [fk_teamid] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[students]') AND type in (N'U')) DROP TABLE [dbo].[students] GO /* Drop any constraints and the table TEAMS. */ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[teams]') AND type in (N'U')) DROP TABLE [dbo].[teams] GO