[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/24/2006 at 09:32AM PST, ID: 22071612
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Writing script to modify database: column properties, view properties, etc...

Asked by tatton777 in MS SQL Server

Hello,

I have recently made changes to my template_db that I need to implement for all my old databases. I could import and then manually make changes but this would take SOOOO much time. Below I've made a CHANGE THIS into THIS report. I've also included a summary of changes at the bottom of this LONG request for help. Thanks!! I've included the Diagram info with the views, but I would just as soon delete the diagram info as part of the script instead of trying to update it.

It may help to check out the summary first, to find it quickly just do a search for this text "============================"

THANKS in advance!!

I need help writing a script that will do the following:

#1
CHANGE THIS TABLE:
----------------------------------------------------------------
USE [restore_ut_alp_americanhigh]
GO
/****** Object:  Table [dbo].[sFeeGroup]    Script Date: 11/24/2006 08:33:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[sFeeGroup](
      [sFeeGroup_Id] [int] IDENTITY(1,1) NOT NULL,
      [FeeGroup] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_sFeeGroup_FeeGroup]  DEFAULT (''),
      [IsCourseType] [tinyint] NULL CONSTRAINT [DF_sFeeGroup_IsCourseType]  DEFAULT ((0)),
 CONSTRAINT [PK_sFeeGroup] PRIMARY KEY CLUSTERED
(
      [sFeeGroup_Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
-----------------------------------------------------------------

INTO THIS TABLE:
-----------------------------------------------------------------
SE [msf_school]
GO
/****** Object:  Table [dbo].[sFeeGroup]    Script Date: 11/24/2006 08:35:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[sFeeGroup](
      [sFeeGroup_Id] [int] IDENTITY(1,1) NOT NULL,
      [FeeGroup] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_sFeeGroup_FeeGroup]  DEFAULT (''),
      [IsCourseType] [tinyint] NULL CONSTRAINT [DF_sFeeGroup_IsCourseType]  DEFAULT ((0)),
      [IsLunch] [tinyint] NULL CONSTRAINT [DF_sFeeGroup_IsLunch]  DEFAULT ((0)),
      [Available] [datetime] NULL CONSTRAINT [DF_sFeeGroup_Available]  DEFAULT (((1)/(1))/(1)),
      [Expires] [datetime] NULL CONSTRAINT [DF_sFeeGroup_Expires]  DEFAULT (((1)/(1))/(1)),
 CONSTRAINT [PK_sFeeGroup] PRIMARY KEY CLUSTERED
(
      [sFeeGroup_Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
--------------------------------------------------------------------------------------------------------

#2
CHANGE THIS TABLE
--------------------------------------------------------------------------------------------------------
USE [restore_ut_alp_americanhigh]
GO
/****** Object:  Table [dbo].[sPayItem]    Script Date: 11/24/2006 08:49:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[sPayItem](
      [sPayItemSysId] [int] IDENTITY(250000,1) NOT NULL,
      [sPayDetailSysId] [int] NULL CONSTRAINT [DF_sPayItem_sPayDetailSysId]  DEFAULT ((0)),
      [sSchool_Id] [int] NULL CONSTRAINT [DF_sPayItem_sSchFi_Id]  DEFAULT ((0)),
      [sMstFi_Id] [int] NULL CONSTRAINT [DF_sPayItem_sMstFi_Id]  DEFAULT ((0)),
      [MF_Id] [int] NULL CONSTRAINT [DF_sPayItem_MF_Id]  DEFAULT ((0)),
      [Bgl_Id] [int] NULL CONSTRAINT [DF_sPayItem_Bgl_Id]  DEFAULT ((0)),
      [SaleDateTime] [datetime] NULL CONSTRAINT [DF_sPayItem_SaleDateTime]  DEFAULT (((1)/(1))/(2006)),
      [SaleAmount] [decimal](18, 2) NULL CONSTRAINT [DF_sPayItem_SaleAmount]  DEFAULT ((0)),
      [Comment] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_sPayItem_Comment]  DEFAULT (''),
      [FeeGroup] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_sPayItem_FeeGroup]  DEFAULT (''),
      [Teacher] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_sPayItem_Teacher]  DEFAULT (''),
      [TesIt_Id] [int] NULL CONSTRAINT [DF_sPayItem_TesIt_Id]  DEFAULT ((0)),
      [AR_Id] [int] NULL CONSTRAINT [DF_sPayItem_AR_Id]  DEFAULT ((0)),
      [IsVoided] [tinyint] NULL CONSTRAINT [DF_sPayItem_IsVoided]  DEFAULT ((0)),
 CONSTRAINT [PK_sPayItem] PRIMARY KEY CLUSTERED
(
      [sPayItemSysId] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
------------------------------------------------------------------------------------------------------

INTO THIS TABLE
------------------------------------------------------------------------------------------------------
USE [msf_school]
GO
/****** Object:  Table [dbo].[sPayItem]    Script Date: 11/24/2006 08:51:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[sPayItem](
      [sPayItemSysId] [int] IDENTITY(250000,1) NOT NULL,
      [sPayDetailSysId] [int] NULL CONSTRAINT [DF_sPayItem_sPayDetailSysId]  DEFAULT ((0)),
      [sSchool_Id] [int] NULL CONSTRAINT [DF_sPayItem_sSchFi_Id]  DEFAULT ((0)),
      [sMstFi_Id] [int] NULL CONSTRAINT [DF_sPayItem_sMstFi_Id]  DEFAULT ((0)),
      [MF_Id] [int] NULL CONSTRAINT [DF_sPayItem_MF_Id]  DEFAULT ((0)),
      [Bgl_Id] [int] NULL CONSTRAINT [DF_sPayItem_Bgl_Id]  DEFAULT ((0)),
      [SaleDateTime] [datetime] NULL CONSTRAINT [DF_sPayItem_SaleDateTime]  DEFAULT (((1)/(1))/(2006)),
      [SaleAmount] [decimal](18, 2) NULL CONSTRAINT [DF_sPayItem_SaleAmount]  DEFAULT ((0)),
      [Comment] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_sPayItem_Comment]  DEFAULT (''),
      [FeeGroup] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_sPayItem_FeeGroup]  DEFAULT (''),
      [Teacher] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_sPayItem_Teacher]  DEFAULT (''),
      [TesIt_Id] [int] NULL CONSTRAINT [DF_sPayItem_TesIt_Id]  DEFAULT ((0)),
      [AR_Id] [int] NULL CONSTRAINT [DF_sPayItem_AR_Id]  DEFAULT ((0)),
      [IsVoided] [tinyint] NULL CONSTRAINT [DF_sPayItem_IsVoided]  DEFAULT ((0)),
 CONSTRAINT [PK_sPayItem] PRIMARY KEY CLUSTERED
(
      [sPayItemSysId] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
------------------------------------------------------------------------------------------------------------------


#3
CHANGE THIS VIEW
--------------------------------------------------------------------------------------------------------
USE [restore_ut_alp_americanhigh]
GO
/****** Object:  View [dbo].[FeeGroup_SecFeeDef]    Script Date: 11/24/2006 08:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FeeGroup_SecFeeDef]
AS
SELECT     dbo.sFeeGroup.sFeeGroup_Id, dbo.sFeeGroup.FeeGroup, dbo.sFeeGroup.IsCourseType, dbo.sSecFeeDef.Bgl_Id, dbo.sSecFeeDef.PrintOrder,
                      dbo.sSecFeeDef.Category, dbo.sSecFeeDef.Comment, dbo.sSecFeeDef.Teacher, dbo.sSecFeeDef.Price, dbo.sSecFeeDef.BglNumberName,
                      dbo.sSecFeeDef.IsGeneric, dbo.sSecFeeDef.sSecFeeDef_Id
FROM         dbo.sFeeGroup INNER JOIN
                      dbo.sSecFeeDef ON dbo.sFeeGroup.sFeeGroup_Id = dbo.sSecFeeDef.sFeeGroup_Id

GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
   Begin PaneConfigurations =
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane =
      Begin Origin =
         Top = 0
         Left = 0
      End
      Begin Tables =
         Begin Table = "sFeeGroup"
            Begin Extent =
               Top = 6
               Left = 38
               Bottom = 106
               Right = 190
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "sSecFeeDef"
            Begin Extent =
               Top = 6
               Left = 228
               Bottom = 121
               Right = 387
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane =
   End
   Begin DataPane =
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane =
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'FeeGroup_SecFeeDef'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'FeeGroup_SecFeeDef'
-------------------------------------------------------------------------------------------

INTO THIS VIEW
-------------------------------------------------------------------------------------------
USE [msf_school]
GO
/****** Object:  View [dbo].[FeeGroup_SecFeeDef]    Script Date: 11/24/2006 08:43:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[FeeGroup_SecFeeDef]
AS
SELECT     dbo.sFeeGroup.sFeeGroup_Id, dbo.sFeeGroup.FeeGroup, dbo.sFeeGroup.IsCourseType, dbo.sSecFeeDef.Bgl_Id, dbo.sSecFeeDef.PrintOrder,
                      dbo.sSecFeeDef.Category, dbo.sSecFeeDef.Comment, dbo.sSecFeeDef.Teacher, dbo.sSecFeeDef.Price, dbo.sSecFeeDef.BglNumberName,
                      dbo.sSecFeeDef.IsGeneric, dbo.sSecFeeDef.sSecFeeDef_Id, dbo.sFeeGroup.IsLunch, dbo.sFeeGroup.Available, dbo.sFeeGroup.Expires
FROM         dbo.sFeeGroup INNER JOIN
                      dbo.sSecFeeDef ON dbo.sFeeGroup.sFeeGroup_Id = dbo.sSecFeeDef.sFeeGroup_Id

GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
   Begin PaneConfigurations =
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[9] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane =
      Begin Origin =
         Top = 0
         Left = 0
      End
      Begin Tables =
         Begin Table = "sFeeGroup"
            Begin Extent =
               Top = 6
               Left = 38
               Bottom = 106
               Right = 190
            End
            DisplayFlags = 280
            TopColumn = 3
         End
         Begin Table = "sSecFeeDef"
            Begin Extent =
               Top = 6
               Left = 228
               Bottom = 121
               Right = 387
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane =
   End
   Begin DataPane =
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane =
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'FeeGroup_SecFeeDef'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'FeeGroup_SecFeeDef'
----------------------------------------------------------------------------------------------------------------------

#4
CHANGE THIS STORED PROCEDURE:
----------------------------------------------------------------------------------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InsertFeeGroup]
      (
      @FeeGroup varchar(30),
      @IsCourseType tinyint
      )

AS
      SET NOCOUNT ON
      SET QUOTED_IDENTIFIER ON
      
      INSERT INTO sFeeGroup
      VALUES (@FeeGroup, @IsCourseType)
             
      RETURN
-------------------------------------------------------------------------------------

INTO THIS STORED PROCEDURE:
-------------------------------------------------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InsertFeeGroup]
      (
      @FeeGroup varchar(30),
      @IsCourseType tinyint
      )

AS
      SET NOCOUNT ON
      SET QUOTED_IDENTIFIER ON
      
      INSERT INTO sFeeGroup (FeeGroup, IsCourseType)
      VALUES (@FeeGroup, @IsCourseType)
             
      RETURN
--------------------------------------------------------------------------------------------

============================
SUMMARY of what script should do:
============================

sFeeGroup Table
-----------------------
Modify field    FeeGroup varchar(100) instead of varchar(30) - default value of ''
Add field       IsLunch (tinyint) - default value of 0
Add field       Available (datetime) default value of 1/1/1
Add field       Expires (datetime) default value of 1/1/1/


sPayItem Table
-----------------------
Modify field    FeeGroup varchar(100) instead of varchar(50) - default value of ''
Modify field    Comment varchar(100) instead of varchar(50)- default value of ''


FeeGroup_SecFeeDef View
--------------------------------
Add field     IsLunch       from sFeeGroup Table
Add field     Available     from sFeeGroup Table
Add field     Expires       from sFeeGroup Table


InsertFeeGroup Stored Procedure
----------------------------------------
1. Delete Old InsertFeeGroup Stored Procedure
2. Replace with New InsertFeeGroup Stored Procedure:


NEW InsertFeeGroup (for reference)
-------------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InsertFeeGroup]
      (
      @FeeGroup varchar(30),
      @IsCourseType tinyint
      )

AS
      SET NOCOUNT ON
      SET QUOTED_IDENTIFIER ON
      
      INSERT INTO sFeeGroup (FeeGroup, IsCourseType)
      VALUES (@FeeGroup, @IsCourseType)
             
      RETURN


[+][-]11/24/06 11:01 PM, ID: 18010539

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/25/06 02:04 PM, ID: 18012633

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/25/06 02:29 PM, ID: 18012724

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Sign Up Now!
Solution Provided By: Nightman
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20090824-EE-VQP-74