/****** Object:  Table [dbo].[ADMIN_RIGHTS]    Script Date: 04.03.2006 15:50:29 ******/
CREATE TABLE [dbo].[ADMIN_RIGHTS] (
	[GroupName] [varchar] (260) NULL ,
	[Type] [int] NULL ,
	[CatID] [int] NULL ,
	[RightCreate] [int] NULL ,
	[RightDelete] [int] NULL ,
	[RightEdit] [int] NULL ,
	[RightPreview] [int] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[ATTRIBS]    Script Date: 04.03.2006 15:50:30 ******/
CREATE TABLE [dbo].[ATTRIBS] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Name] [varchar] (260) NOT NULL ,
	[Type] [int] NOT NULL ,
	[RadioID] [int] NOT NULL ,
	[DDB_Owner] [varchar] (64) NULL ,
	[DDB_ID] [int] NOT NULL ,
	[ModifyDate] [datetime] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[AUTO_MOVE]    Script Date: 04.03.2006 15:50:30 ******/
CREATE TABLE [dbo].[AUTO_MOVE] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[SrcCatID] [int] NOT NULL ,
	[SrcArchive] [int] NOT NULL ,
	[DstCatID] [int] NOT NULL ,
	[DstArchive] [int] NOT NULL ,
	[DstDelete] [int] NOT NULL ,
	[KeepTime] [bigint] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[CAT_JNGL_BTNS]    Script Date: 04.03.2006 15:50:31 ******/
CREATE TABLE [dbo].[CAT_JNGL_BTNS] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[CatID] [int] NOT NULL ,
	[ParentID] [int] NOT NULL ,
	[Pos] [int] NULL ,
	[Deleted] [int] NULL ,
	[ModifyDate] [datetime] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[DB_IMPORT_FILTERS]    Script Date: 04.03.2006 15:50:31 ******/
CREATE TABLE [dbo].[DB_IMPORT_FILTERS] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Type] [int] NOT NULL ,
	[Name] [varchar] (3000) NOT NULL ,
	[Value] [varchar] (3000) NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[MAG_DB_PARAMS]    Script Date: 04.03.2006 15:50:31 ******/
CREATE TABLE [dbo].[MAG_DB_PARAMS] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Type] [int] NOT NULL ,
	[Name] [varchar] (3000) NOT NULL ,
	[Value] [varchar] (3000) NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[MAG_WORK]    Script Date: 04.03.2006 15:50:31 ******/
CREATE TABLE [dbo].[MAG_WORK] (
	[WorkDate] [datetime] NOT NULL ,
	[ph_id] [int] NOT NULL ,
	[sch_order] [int] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PARAMETERS]    Script Date: 04.03.2006 15:50:31 ******/
CREATE TABLE [dbo].[PARAMETERS] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Type] [int] NOT NULL ,
	[Name] [varchar] (3000) NOT NULL ,
	[Value] [varchar] (3000) NOT NULL ,
	[ModifyDate] [datetime] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PH]    Script Date: 04.03.2006 15:50:31 ******/
CREATE TABLE [dbo].[PH] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Name] [varchar] (260) NOT NULL ,
	[FileName] [varchar] (260) NOT NULL ,
	[Duration] [int] NOT NULL ,
	[Type] [int] NOT NULL ,
	[Intro] [int] NOT NULL ,
	[Outro] [int] NOT NULL ,
	[FadeIn] [int] NOT NULL ,
	[FadeOut] [int] NOT NULL ,
	[StartNext] [int] NOT NULL ,
	[Ph_Start] [int] NOT NULL ,
	[Ph_Stop] [int] NOT NULL ,
	[Cmd] [int] NOT NULL ,
	[Freq] [int] NOT NULL ,
	[SmplSize] [int] NOT NULL ,
	[RadioID] [int] NOT NULL ,
	[RemoteCmd] [int] NOT NULL ,
	[AddDate] [datetime] NOT NULL ,
	[LastPlayTime] [datetime] NOT NULL ,
	[ModifyDate] [datetime] NOT NULL ,
	[Deleted] [int] NOT NULL ,
	[JM_pos] [int] NOT NULL ,
	[SubjText] [text] NULL ,
	[ID_Number] [varchar] (32) NULL ,
	[EndCode] [varchar] (10) NULL ,
	[FirstReportLine] [varchar] (260) NULL ,
	[LastReportLine] [varchar] (260) NULL ,
	[MaxLvl] [real] NOT NULL ,
	[MaxLvlOk] [int] NOT NULL ,
	[Gain] [real] NOT NULL ,
	[CDId] [varchar] (10) NULL ,
	[CDTrackId] [int] NOT NULL ,
	[Album] [varchar] (260) NULL ,
	[SongYear] [int] NULL ,
	[ModifyFT] [bigint] NULL ,
	[RmtList] [varchar] (2048) NULL ,
	[DDB_Owner] [varchar] (64) NULL ,
	[Version] [int] NULL ,
	[DDB_ID] [int] NOT NULL ,
	[CRC32] [int] NOT NULL ,
	[SCH_UsedCount] [int] NULL ,
	[Intro2] [int] NULL ,
	[Intro3] [int] NULL ,
	[Comment] [varchar] (3000) NULL ,
	[FadeInType] [int] NULL ,
	[FadeOutType] [int] NULL ,
	[Mood] [int] NOT NULL ,
	[ActivateDate] [datetime] NOT NULL ,
	[ENERGY] [int] NULL ,
	[TEMPO] [int] NULL ,
	[TEXTURE] [int] NULL ,
	[TEMPO_END] [int] NOT NULL ,
	[TEXTURE_END] [int] NOT NULL ,
	[StartThis] [int] NOT NULL ,
	[Archive] [int] NOT NULL ,
	[NextPlayTime] [datetime] NULL ,
	[UserModifyTime] [datetime] NOT NULL ,
	[DayRestrictions] [binary] (168) NULL ,
	[ReadyOnAir] [int] NOT NULL ,
	[Headline] [varchar] (256) NULL ,
	[CasseteStartFPS] [int] NULL ,
	[CasseteLengthFPS] [int] NULL ,
	[BackupTapeName] [varchar] (32) NULL ,
	[BackupTimeCode] [int] NULL ,
	[KeyFrame] [int] NULL ,
	[KeyIcon] [image] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PLIST_BLOCKS]    Script Date: 04.03.2006 15:50:33 ******/
CREATE TABLE [dbo].[PLIST_BLOCKS] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[FileID] [int] NOT NULL ,
	[Date] [datetime] NOT NULL ,
	[PListName] [varchar] (260) NULL ,
	[Type] [int] NULL ,
	[Name] [varchar] (260) NULL ,
	[Time] [int] NULL ,
	[Size1000] [int] NULL ,
	[NumEl] [int] NULL ,
	[CurID] [int] NULL ,
	[Flags] [int] NULL ,
	[RmtList] [varchar] (2048) NULL ,
	[JnglBtn] [int] NULL ,
	[ModifyDate] [datetime] NOT NULL ,
	[DDB_FileID] [int] NULL ,
	[DDB_Owner] [varchar] (64) NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PLIST_ELEMS]    Script Date: 04.03.2006 15:50:33 ******/
CREATE TABLE [dbo].[PLIST_ELEMS] (
	[BlockID] [int] NOT NULL ,
	[Num] [int] NULL ,
	[Type] [int] NULL ,
	[PhonoType] [int] NULL ,
	[Name] [varchar] (260) NULL ,
	[Comment] [varchar] (2000) NULL ,
	[Category] [varchar] (512) NULL ,
	[Artist] [varchar] (512) NULL ,
	[Author] [varchar] (512) NULL ,
	[dbID] [int] NULL ,
	[ID_Number] [varchar] (32) NULL ,
	[Version] [int] NULL ,
	[RadioID] [int] NULL ,
	[DbName] [varchar] (260) NULL ,
	[FileName] [varchar] (260) NULL ,
	[RollIn] [int] NULL ,
	[RollOut] [int] NULL ,
	[FadeIn] [int] NULL ,
	[FadeOut] [int] NULL ,
	[Intro] [int] NULL ,
	[Outro] [int] NULL ,
	[StartNext] [int] NULL ,
	[Size1000] [int] NULL ,
	[Freq] [int] NULL ,
	[SmplRealSize] [int] NULL ,
	[MaxLvlOk] [int] NULL ,
	[MaxLvl] [real] NULL ,
	[Gain] [real] NULL ,
	[Album] [varchar] (260) NULL ,
	[Genre] [varchar] (260) NULL ,
	[Year] [int] NULL ,
	[CDId] [varchar] (10) NULL ,
	[CDTrackId] [int] NULL ,
	[Cmd] [int] NULL ,
	[RemoteCmd] [int] NULL ,
	[EndCode] [varchar] (10) NULL ,
	[StartTime] [int] NULL ,
	[JnglBtn] [int] NULL ,
	[ImpLastFileName] [varchar] (260) NULL ,
	[FirstReportLine] [varchar] (260) NULL ,
	[LastReportLine] [varchar] (260) NULL ,
	[RmtList] [varchar] (2048) NULL ,
	[GainList] [text] NULL ,
	[DDB_ID] [int] NULL ,
	[DDB_Owner] [varchar] (64) NULL ,
	[IdInBlock] [int] NULL ,
	[Intro2] [int] NULL ,
	[Intro3] [int] NULL ,
	[FadeInType] [int] NULL ,
	[FadeOutType] [int] NULL ,
	[MOOD] [int] NOT NULL ,
	[ENERGY] [int] NOT NULL ,
	[TEMPO] [int] NOT NULL ,
	[TEXTURE] [int] NOT NULL ,
	[TEMPO_END] [int] NOT NULL ,
	[TEXTURE_END] [int] NOT NULL ,
	[StartThis] [int] NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PLIST_MARKERS]    Script Date: 04.03.2006 15:50:34 ******/
CREATE TABLE [dbo].[PLIST_MARKERS] (
	[PListName] [varchar] (260) NULL ,
	[Marker] [int] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PLIST_TASKS]    Script Date: 04.03.2006 15:50:34 ******/
CREATE TABLE [dbo].[PLIST_TASKS] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[ID_First] [int] NOT NULL ,
	[ID_Last] [int] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[RADIOSTATION]    Script Date: 04.03.2006 15:50:34 ******/
CREATE TABLE [dbo].[RADIOSTATION] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (60) NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[SETTINGS]    Script Date: 04.03.2006 15:50:34 ******/
CREATE TABLE [dbo].[SETTINGS] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Name] [varchar] (260) NOT NULL ,
	[ValStr] [varchar] (260) NOT NULL ,
	[ValInt] [int] NOT NULL ,
	[ValInt2] [int] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[TRACT]    Script Date: 04.03.2006 15:50:34 ******/
CREATE TABLE [dbo].[TRACT] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Version] [int] NOT NULL ,
	[critical] [int] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[USERS_WORK]    Script Date: 04.03.2006 15:50:34 ******/
CREATE TABLE [dbo].[USERS_WORK] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[user_name] [varchar] (260) NULL ,
	[user_work] [int] NULL ,
	[date_work] [datetime] NULL ,
	[time_work] [datetime] NULL ,
	[temp1] [int] NULL ,
	[temp2] [int] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[ATTRIB_VALS]    Script Date: 04.03.2006 15:50:34 ******/
CREATE TABLE [dbo].[ATTRIB_VALS] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Name] [varchar] (260) NOT NULL ,
	[Type] [int] NOT NULL ,
	[attr_id] [int] NOT NULL ,
	[Deleted] [int] NOT NULL ,
	[ModifyDate] [datetime] NOT NULL ,
	[RadioID] [int] NOT NULL ,
	[FILE_PATH] [varchar] (260) NOT NULL ,
	[JM_pos] [int] NOT NULL ,
	[DDB_Owner] [varchar] (64) NULL ,
	[DDB_Allowed] [int] NOT NULL ,
	[DDB_ID] [int] NOT NULL ,
	[Color] [int] NOT NULL ,
	[ActivateDate] [datetime] NOT NULL ,
	[ForNewsBrowser] [int] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PLAY_HISTORY]    Script Date: 04.03.2006 15:50:35 ******/
CREATE TABLE [dbo].[PLAY_HISTORY] (
	[ph_id] [int] NOT NULL ,
	[Action] [int] NOT NULL ,
	[PlayDate] [datetime] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[SKELETON]    Script Date: 04.03.2006 15:50:35 ******/
CREATE TABLE [dbo].[SKELETON] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (40) NULL ,
	[date_sk] [datetime] NULL ,
	[day_month] [int] NULL ,
	[week] [int] NULL ,
	[odd] [int] NULL ,
	[working] [int] NULL ,
	[id_radio] [int] NULL ,
	[month] [int] NULL ,
	[month_month] [int] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[ACC_RIGHTS]    Script Date: 04.03.2006 15:50:35 ******/
CREATE TABLE [dbo].[ACC_RIGHTS] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Type] [int] NOT NULL ,
	[CatId] [int] NULL ,
	[CatType] [int] NOT NULL ,
	[Archive] [int] NOT NULL ,
	[UserName] [varchar] (260) NULL ,
	[Rights] [int] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[MODIFY_DATES]    Script Date: 04.03.2006 15:50:35 ******/
CREATE TABLE [dbo].[MODIFY_DATES] (
	[ph_id] [int] NULL ,
	[attrib_id] [int] NULL ,
	[attrval_id] [int] NULL ,
	[ModifyDate] [datetime] NOT NULL ,
	[cat_jngl_btns_id] [int] NULL ,
	[id] [int] IDENTITY (1, 1) NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PH_TO_ATTRVALS]    Script Date: 04.03.2006 15:50:35 ******/
CREATE TABLE [dbo].[PH_TO_ATTRVALS] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[ph_id] [int] NOT NULL ,
	[attrval_id] [int] NOT NULL ,
	[JM_pos] [int] NOT NULL ,
	[SCH_ORDER] [int] NULL ,
	[CreationTime] [datetime] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[SK_ELEM]    Script Date: 04.03.2006 15:50:36 ******/
CREATE TABLE [dbo].[SK_ELEM] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[name] [varchar] (40) NULL ,
	[duration] [datetime] NULL ,
	[type] [int] NULL ,
	[id_ph] [int] NULL ,
	[id_attr] [int] NULL ,
	[start_control] [int] NULL ,
	[text_control] [varchar] (260) NULL ,
	[short_name] [varchar] (2) NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[STORAGE]    Script Date: 04.03.2006 15:50:36 ******/
CREATE TABLE [dbo].[STORAGE] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Type] [int] NOT NULL ,
	[CatId] [int] NULL ,
	[Archive] [int] NOT NULL ,
	[Path] [varchar] (260) NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[SK_SK_ELEM]    Script Date: 04.03.2006 15:50:36 ******/
CREATE TABLE [dbo].[SK_SK_ELEM] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[id_sk] [int] NULL ,
	[id_sk_elem] [int] NULL ,
	[duration] [datetime] NULL ,
	[number] [int] NULL ,
	[fix_time] [int] NULL ,
	[noearl] [int] NULL ,
	[nolate] [int] NULL ,
	[splitblock] [int] NULL ,
	[splitphonogram] [int] NULL ,
	[pause] [int] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[ATTRIBS] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[AUTO_MOVE] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[DB_IMPORT_FILTERS] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MAG_DB_PARAMS] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PARAMETERS] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PH] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[RADIOSTATION] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[TRACT] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[USERS_WORK] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[ATTRIB_VALS] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SKELETON] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[ACC_RIGHTS] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MODIFY_DATES] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PH_TO_ATTRVALS] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SK_ELEM] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[STORAGE] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SK_SK_ELEM] WITH NOCHECK ADD 
	 PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[ATTRIBS] WITH NOCHECK ADD 
	CONSTRAINT [DF__ATTRIBS__Type__0EA330E9] DEFAULT (1) FOR [Type],
	CONSTRAINT [DF__ATTRIBS__RadioID__37A5467C] DEFAULT (0) FOR [RadioID],
	CONSTRAINT [DF__ATTRIBS__DDB_ID__440B1D61] DEFAULT (0) FOR [DDB_ID],
	CONSTRAINT [DF__ATTRIBS__ModifyD__46E78A0C] DEFAULT (getdate()) FOR [ModifyDate]
GO

ALTER TABLE [dbo].[CAT_JNGL_BTNS] WITH NOCHECK ADD 
	CONSTRAINT [DF__CAT_JNGL___Modif__534D60F1] DEFAULT (getdate()) FOR [ModifyDate]
GO

ALTER TABLE [dbo].[PARAMETERS] WITH NOCHECK ADD 
	CONSTRAINT [DF__PARAMETER__Modif__00200768] DEFAULT (getdate()) FOR [ModifyDate]
GO

ALTER TABLE [dbo].[PH] WITH NOCHECK ADD 
	CONSTRAINT [DF__PH__Name__7A9C383C] DEFAULT ('Noname') FOR [Name],
	CONSTRAINT [DF__PH__Duration__7B905C75] DEFAULT (0) FOR [Duration],
	CONSTRAINT [DF__PH__Type__7C8480AE] DEFAULT (1) FOR [Type],
	CONSTRAINT [DF__PH__Intro__7D78A4E7] DEFAULT (0) FOR [Intro],
	CONSTRAINT [DF__PH__Outro__7E6CC920] DEFAULT (0) FOR [Outro],
	CONSTRAINT [DF__PH__FadeIn__7F60ED59] DEFAULT (0) FOR [FadeIn],
	CONSTRAINT [DF__PH__FadeOut__00551192] DEFAULT (0) FOR [FadeOut],
	CONSTRAINT [DF__PH__StartNext__014935CB] DEFAULT (0) FOR [StartNext],
	CONSTRAINT [DF__PH__Ph_Start__023D5A04] DEFAULT (0) FOR [Ph_Start],
	CONSTRAINT [DF__PH__Ph_Stop__03317E3D] DEFAULT (0) FOR [Ph_Stop],
	CONSTRAINT [DF__PH__Cmd__0425A276] DEFAULT (0) FOR [Cmd],
	CONSTRAINT [DF__PH__Freq__0519C6AF] DEFAULT (0) FOR [Freq],
	CONSTRAINT [DF__PH__SmplSize__060DEAE8] DEFAULT (0) FOR [SmplSize],
	CONSTRAINT [DF__PH__RadioID__07020F21] DEFAULT (0) FOR [RadioID],
	CONSTRAINT [DF__PH__RemoteCmd__07F6335A] DEFAULT (0) FOR [RemoteCmd],
	CONSTRAINT [DF__PH__AddDate__08EA5793] DEFAULT (getdate()) FOR [AddDate],
	CONSTRAINT [DF__PH__LastPlayTime__09DE7BCC] DEFAULT (getdate()) FOR [LastPlayTime],
	CONSTRAINT [DF__PH__ModifyDate__0AD2A005] DEFAULT (getdate()) FOR [ModifyDate],
	CONSTRAINT [DF__PH__Deleted__0BC6C43E] DEFAULT (0) FOR [Deleted],
	CONSTRAINT [DF__PH__JM_pos__36B12243] DEFAULT ((-1)) FOR [JM_pos],
	CONSTRAINT [DF__PH__MaxLvl__3F466844] DEFAULT (0) FOR [MaxLvl],
	CONSTRAINT [DF__PH__MaxLvlOk__403A8C7D] DEFAULT (0) FOR [MaxLvlOk],
	CONSTRAINT [DF__PH__Gain__412EB0B6] DEFAULT (0) FOR [Gain],
	CONSTRAINT [DF__PH__CDTrackId__4222D4EF] DEFAULT (0) FOR [CDTrackId],
	CONSTRAINT [DF__PH__DDB_ID__45F365D3] DEFAULT (0) FOR [DDB_ID],
	CONSTRAINT [DF__PH__CRC32__4AB81AF0] DEFAULT (0) FOR [CRC32],
	CONSTRAINT [DF__PH__Mood__59FA5E80] DEFAULT (3) FOR [Mood],
	CONSTRAINT [DF__PH__ActivateDate__5AEE82B9] DEFAULT (getdate()) FOR [ActivateDate],
	CONSTRAINT [DF__PH__ENERGY] DEFAULT (3) FOR [ENERGY],
	CONSTRAINT [DF__PH__TEMPO] DEFAULT (3) FOR [TEMPO],
	CONSTRAINT [DF__PH__TEXTURE] DEFAULT (3) FOR [TEXTURE],
	CONSTRAINT [DF__PH__TEMPO_END__5FB337D6] DEFAULT (3) FOR [TEMPO_END],
	CONSTRAINT [DF__PH__TEXTURE_END__60A75C0F] DEFAULT (3) FOR [TEXTURE_END],
	CONSTRAINT [DF__PH__StartThis__6754599E] DEFAULT (0) FOR [StartThis],
	CONSTRAINT [DF__PH__Archive__6A30C649] DEFAULT (0) FOR [Archive],
	CONSTRAINT [DF__PH__UserModifyTi__6B24EA82] DEFAULT (getdate()) FOR [UserModifyTime],
	CONSTRAINT [DF__PH__ReadyOnAir__76969D2E] DEFAULT (0) FOR [ReadyOnAir]
GO

ALTER TABLE [dbo].[PLIST_ELEMS] WITH NOCHECK ADD 
	CONSTRAINT [DF__PLIST_ELEM__MOOD__619B8048] DEFAULT (3) FOR [MOOD],
	CONSTRAINT [DF__PLIST_ELE__ENERG__628FA481] DEFAULT (3) FOR [ENERGY],
	CONSTRAINT [DF__PLIST_ELE__TEMPO__6383C8BA] DEFAULT (3) FOR [TEMPO],
	CONSTRAINT [DF__PLIST_ELE__TEXTU__6477ECF3] DEFAULT (3) FOR [TEXTURE],
	CONSTRAINT [DF__PLIST_ELE__TEMPO__656C112C] DEFAULT (3) FOR [TEMPO_END],
	CONSTRAINT [DF__PLIST_ELE__TEXTU__66603565] DEFAULT (3) FOR [TEXTURE_END],
	CONSTRAINT [DF__PLIST_ELE__Start__68487DD7] DEFAULT (0) FOR [StartThis]
GO

ALTER TABLE [dbo].[SETTINGS] WITH NOCHECK ADD 
	CONSTRAINT [DF__SETTINGS__ValStr__3B75D760] DEFAULT ('') FOR [ValStr],
	CONSTRAINT [DF__SETTINGS__ValInt__3C69FB99] DEFAULT (0) FOR [ValInt],
	CONSTRAINT [DF__SETTINGS__ValInt__3D5E1FD2] DEFAULT (0) FOR [ValInt2]
GO

ALTER TABLE [dbo].[TRACT] WITH NOCHECK ADD 
	CONSTRAINT [DF__TRACT__Version__77BFCB91] DEFAULT (0) FOR [Version],
	CONSTRAINT [DF__TRACT__critical__06CD04F7] DEFAULT (0) FOR [critical]
GO

ALTER TABLE [dbo].[ATTRIB_VALS] WITH NOCHECK ADD 
	CONSTRAINT [DF__ATTRIB_VAL__Type__117F9D94] DEFAULT (1) FOR [Type],
	CONSTRAINT [DF__ATTRIB_VA__Delet__1273C1CD] DEFAULT (0) FOR [Deleted],
	CONSTRAINT [DF__ATTRIB_VA__Modif__1367E606] DEFAULT (getdate()) FOR [ModifyDate],
	CONSTRAINT [DF__ATTRIB_VA__Radio__38996AB5] DEFAULT (0) FOR [RadioID],
	CONSTRAINT [DF__ATTRIB_VA__FILE___398D8EEE] DEFAULT ('') FOR [FILE_PATH],
	CONSTRAINT [DF__ATTRIB_VA__JM_po__3E52440B] DEFAULT ((-1)) FOR [JM_pos],
	CONSTRAINT [DF__ATTRIB_VA__DDB_A__4316F928] DEFAULT (0) FOR [DDB_Allowed],
	CONSTRAINT [DF__ATTRIB_VA__DDB_I__44FF419A] DEFAULT (0) FOR [DDB_ID],
	CONSTRAINT [DF__ATTRIB_VA__Color__571DF1D5] DEFAULT (0xffffff) FOR [Color],
	CONSTRAINT [DF__ATTRIB_VA__Activ__5BE2A6F2] DEFAULT (getdate()) FOR [ActivateDate]
GO

ALTER TABLE [dbo].[SKELETON] WITH NOCHECK ADD 
	CONSTRAINT [DF__SKELETON__date_s__1A14E395] DEFAULT ('1990-01-01') FOR [date_sk],
	CONSTRAINT [DF__SKELETON__day_mo__1B0907CE] DEFAULT (0) FOR [day_month],
	CONSTRAINT [DF__SKELETON__week__1BFD2C07] DEFAULT (0) FOR [week],
	CONSTRAINT [DF__SKELETON__odd__1CF15040] DEFAULT (0) FOR [odd],
	CONSTRAINT [DF__SKELETON__workin__1DE57479] DEFAULT (0) FOR [working],
	CONSTRAINT [DF__SKELETON__id_rad__1ED998B2] DEFAULT (0) FOR [id_radio],
	CONSTRAINT [DF__SKELETON__month___1FCDBCEB] DEFAULT (0) FOR [month_month]
GO

ALTER TABLE [dbo].[MODIFY_DATES] WITH NOCHECK ADD 
	CONSTRAINT [DF__MODIFY_DA__Modif__02FC7413] DEFAULT (getdate()) FOR [ModifyDate]
GO

ALTER TABLE [dbo].[PH_TO_ATTRVALS] WITH NOCHECK ADD 
	CONSTRAINT [DF__PH_TO_ATT__JM_po__5812160E] DEFAULT ((-2)) FOR [JM_pos],
	CONSTRAINT [DF__PH_TO_ATT__Creat__7D439ABD] DEFAULT (getdate()) FOR [CreationTime]
GO

ALTER TABLE [dbo].[SK_ELEM] WITH NOCHECK ADD 
	CONSTRAINT [DF__SK_ELEM__type__22AA2996] DEFAULT (0) FOR [type]
GO

ALTER TABLE [dbo].[SK_SK_ELEM] WITH NOCHECK ADD 
	CONSTRAINT [DF__SK_SK_ELE__id_sk__25869641] DEFAULT (0) FOR [id_sk],
	CONSTRAINT [DF__SK_SK_ELE__id_sk__267ABA7A] DEFAULT (0) FOR [id_sk_elem],
	CONSTRAINT [DF__SK_SK_ELE__numbe__276EDEB3] DEFAULT (0) FOR [number],
	CONSTRAINT [DF__SK_SK_ELE__pause__286302EC] DEFAULT (0) FOR [pause]
GO

 CREATE  INDEX [id] ON [dbo].[ATTRIBS]([id]) ON [PRIMARY]
GO

 CREATE  INDEX [indx_WorkDate] ON [dbo].[MAG_WORK]([WorkDate]) ON [PRIMARY]
GO

 CREATE  INDEX [id] ON [dbo].[PH]([id]) ON [PRIMARY]
GO

 CREATE  INDEX [id] ON [dbo].[ATTRIB_VALS]([id]) ON [PRIMARY]
GO

 CREATE  INDEX [id] ON [dbo].[PH_TO_ATTRVALS]([id]) ON [PRIMARY]
GO

 CREATE  INDEX [ph_id] ON [dbo].[PH_TO_ATTRVALS]([ph_id]) ON [PRIMARY]
GO

 CREATE  INDEX [attrval_id] ON [dbo].[PH_TO_ATTRVALS]([attrval_id]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[ATTRIB_VALS] ADD 
	 FOREIGN KEY 
	(
		[attr_id]
	) REFERENCES [dbo].[ATTRIBS] (
		[id]
	) ON DELETE CASCADE 
GO

ALTER TABLE [dbo].[PLAY_HISTORY] ADD 
	 FOREIGN KEY 
	(
		[ph_id]
	) REFERENCES [dbo].[PH] (
		[id]
	) ON DELETE CASCADE 
GO

ALTER TABLE [dbo].[SKELETON] ADD 
	 FOREIGN KEY 
	(
		[id_radio]
	) REFERENCES [dbo].[RADIOSTATION] (
		[id]
	) ON DELETE CASCADE 
GO

ALTER TABLE [dbo].[ACC_RIGHTS] ADD 
	 FOREIGN KEY 
	(
		[CatId]
	) REFERENCES [dbo].[ATTRIB_VALS] (
		[id]
	) ON DELETE CASCADE 
GO

ALTER TABLE [dbo].[MODIFY_DATES] ADD 
	 FOREIGN KEY 
	(
		[attrval_id]
	) REFERENCES [dbo].[ATTRIB_VALS] (
		[id]
	) ON DELETE CASCADE ,
	 FOREIGN KEY 
	(
		[ph_id]
	) REFERENCES [dbo].[PH] (
		[id]
	) ON DELETE CASCADE 
GO

ALTER TABLE [dbo].[PH_TO_ATTRVALS] ADD 
	 FOREIGN KEY 
	(
		[attrval_id]
	) REFERENCES [dbo].[ATTRIB_VALS] (
		[id]
	) ON DELETE CASCADE ,
	 FOREIGN KEY 
	(
		[ph_id]
	) REFERENCES [dbo].[PH] (
		[id]
	) ON DELETE CASCADE 
GO

ALTER TABLE [dbo].[SK_ELEM] ADD 
	 FOREIGN KEY 
	(
		[id_attr]
	) REFERENCES [dbo].[ATTRIB_VALS] (
		[id]
	) ON DELETE CASCADE 
GO

ALTER TABLE [dbo].[STORAGE] ADD 
	 FOREIGN KEY 
	(
		[CatId]
	) REFERENCES [dbo].[ATTRIB_VALS] (
		[id]
	) ON DELETE CASCADE 
GO

ALTER TABLE [dbo].[SK_SK_ELEM] ADD 
	 FOREIGN KEY 
	(
		[id_sk_elem]
	) REFERENCES [dbo].[SK_ELEM] (
		[id]
	) ON DELETE CASCADE ,
	 FOREIGN KEY 
	(
		[id_sk]
	) REFERENCES [dbo].[SKELETON] (
		[id]
	) ON DELETE CASCADE 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Stored Procedure dbo.TEST_NEW_2    Script Date: 04.03.2006 15:50:37 ******/
CREATE PROCEDURE TEST_NEW_2 @p_id int AS
SELECT 5 as RECID, MAX(ID) FROM Modify_Dates 

IF (@p_id>=0)
BEGIN
SELECT 
	4 as RECID,
	CatID,
	ParentID,
	Pos,
	Deleted,
	ModifyDate 
FROM CAT_JNGL_BTNS
WHERE CAT_JNGL_BTNS.id IN (
	SELECT cat_jngl_btns_id FROM Modify_Dates  
	where cat_jngl_btns_id is not null and id > @p_id)
SELECT 	
	1 as RECID,
	ID, 
	Name, 
	Type, 
	ModifyDate, 
	DDB_Owner,
	DDB_ID,
	0 AS NoneCount
FROM ATTRIBS
WHERE ATTRIBS.id IN (
	SELECT attrib_id FROM Modify_Dates  
	where attrib_id is not null and id > @p_id)
SELECT
	2 as RECID,
	ATTRIB_VALS.ID,
	ATTRIB_VALS.Name,
	ATTRIB_VALS.Attr_ID,
	ATTRIB_VALS.Type,
	(SELECT COUNT(PH_TO_ATTRVALS.ID) FROM PH_TO_ATTRVALS 
	 LEFT OUTER JOIN PH ON PH.ID=PH_TO_ATTRVALS.Ph_ID 
	 WHERE PH_TO_ATTRVALS.AttrVal_ID=ATTRIB_VALS.ID AND 
			PH.Archive=0 AND PH.Deleted=0) AS NonArcCnt,
	ATTRIB_VALS.ModifyDate, 
	ATTRIB_VALS.FILE_PATH, 
	ATTRIB_VALS.Deleted, 
	ATTRIB_VALS.DDB_Allowed,
	ATTRIB_VALS.DDB_Owner, 
	ATTRIB_VALS.DDB_ID, 
	(SELECT COUNT(PH_TO_ATTRVALS.ID) FROM PH_TO_ATTRVALS 	
	 LEFT OUTER JOIN PH ON PH.ID=PH_TO_ATTRVALS.Ph_ID 
	 WHERE  PH_TO_ATTRVALS.AttrVal_ID=ATTRIB_VALS.ID AND 
			 PH.Archive=1 AND PH.Deleted=0) AS ArcCnt,
	ATTRIB_VALS.Color,
	ATTRIB_VALS.ForNewsBrowser 
	FROM ATTRIB_VALS
	WHERE ATTRIB_VALS.id IN (
		SELECT attrval_id FROM Modify_Dates  
		where attrval_id is not null and id > @p_id)
SELECT
	3 as RECID, 
	ph.ID,
	ph.Name, 			
	ph.Type, 			
	ph.Duration, 		
	ph.FileName, 		
	ph.FadeIN, 			
	ph.FadeOUT, 		
	ph.Intro, 			
	ph.Outro, 			
	ph.StartNext, 		
	ph.Ph_Start, 		
	ph.Ph_Stop, 		
	ph.AddDate, 		
	ph.Cmd, 			
	ph.Freq, 			
	ph.SmplSize, 		
	ph.RadioID, 		
	ph.RemoteCmd, 		
	ph.LastPlayTime, 	
	ph.Deleted, 		
	ph.ModifyDate, 		
	ATTRIBS.ID AS ATTRIBS_ID, 				
	ATTRIB_VALS.ID AS ATTRIB_VALS_ID, 		
	ATTRIB_VALS.Name AS ATTRIB_VALS_Name, 	
	ph.EndCode, 			
	ph.FirstReportLine, 	
	ph.LastReportLine, 		
	ph.MaxLvl, 				
	ph.MaxLvlOk, 			
	ph.Gain, 				
	ph.CDId, 				
	ph.CDTrackId, 			
	ph.Album, 				
	ph.ID_Number, 			
	ph.SongYear, 			
	ph.ModifyFT, 			
	ph.RmtList, 			
	ph.Version, 			
	ph.DDB_Owner, 			
	ph.DDB_ID, 				
	ph.CRC32, 				
	ph.LastPlayTime, 		
	ph.Intro2, 				
	ph.Intro3, 				
	ph.Comment, 			
	PH_TO_ATTRVALS.JM_pos AS PH_TO_ATTRVALS_JM_pos, 
	ph.FadeInType, 			
	ph.FadeOutType, 		
	ph.ActivateDate, 		
	ph.Mood, 				
	ph.Energy, 				
	ph.Tempo, 				
	ph.Tempo_End, 			
	ph.Texture, 			
	ph.Texture_End, 		
	ph.StartThis, 			
	ATTRIBS.Name AS ATTRIBS_Name, 		
	ph.NextPlayTime, 		
	ph.UserModifyTime, 		
	ph.Archive, 			
	ph.DayRestrictions, 	
	PH_TO_ATTRVALS.sch_order AS PH_TO_ATTRVALS_sch_order, 
	ph.ReadyOnAir, 			
	ph.Headline, 			
	ph.CasseteStartFPS, 	
	ph.CasseteLengthFPS, 	
	ph.BackupTapeName, 		
	ph.BackupTimeCode, 		
	ph.KeyFrame, 			
	NULL AS KeyIcon 				
FROM PH 
	LEFT OUTER JOIN PH_TO_ATTRVALS on PH_TO_ATTRVALS.ph_id=ph.ID
	LEFT OUTER JOIN ATTRIB_VALS on ATTRIB_VALS.ID=PH_TO_ATTRVALS.AttrVal_ID
	LEFT OUTER JOIN ATTRIBS on ATTRIBS.ID=ATTRIB_VALS.attr_ID
WHERE ph.id IN (
	SELECT ph_id FROM Modify_Dates 
	where ph_id is not null and id > @p_id)
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  User Defined Function dbo.FN_GetCategoryItemsIDs    Script Date: 04.03.2006 15:50:37 ******/
create function [dbo].[FN_GetCategoryItemsIDs] (@av_id int, @attr_id int, @start_pos int, @count int) returns varbinary(8000) as BEGIN declare @str_ids varbinary(8000) SELECT @str_ids=0x if @attr_id=1 BEGIN declare @ph_id int declare @sch_order int declare get_cursor cursor scroll for select ph_id, coalesce(sch_order,0) from ph_to_attrvals where attrval_id=@av_id order by sch_order asc open get_cursor FETCH ABSOLUTE @start_pos FROM get_cursor INTO @ph_id, @sch_order WHILE (@@FETCH_STATUS=0 AND @count>0) BEGIN SELECT @str_ids=@str_ids+CAST(@ph_id as binary(4))+cast(@sch_order as binary(4)) SELECT @count=@count-1 FETCH NEXT FROM get_cursor INTO @ph_id, @sch_order END IF (@count>0) SELECT @str_ids=@str_ids+CAST(0 as binary(4)) close get_cursor DEALLOCATE get_cursor END return @str_ids END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.ModifyAttribs    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER ModifyAttribs ON ATTRIBS AFTER INSERT, UPDATE AS 
BEGIN 
	UPDATE ATTRIBS SET ModifyDate=CURRENT_TIMESTAMP 
	WHERE ID IN (SELECT ID FROM INSERTED) 
	INSERT MODIFY_DATES (attrib_id) 
	SELECT id from INSERTED 
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.OnModifyCatJnglBtns    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER OnModifyCatJnglBtns ON CAT_JNGL_BTNS AFTER INSERT, UPDATE AS 
BEGIN
	UPDATE CAT_JNGL_BTNS SET ModifyDate=CURRENT_TIMESTAMP 
	WHERE ID IN (SELECT ID FROM INSERTED)
	INSERT MODIFY_DATES (cat_jngl_btns_id) 
	SELECT id from INSERTED 
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.OnUpdateParameters    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER OnUpdateParameters ON [dbo].[PARAMETERS] AFTER UPDATE AS UPDATE [dbo].[PARAMETERS] SET ModifyDate=CURRENT_TIMESTAMP WHERE ID IN (SELECT INS.ID FROM INSERTED INS)
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.InsertPH    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER InsertPH ON PH AFTER INSERT AS 
BEGIN 
	INSERT INTO MODIFY_DATES (ph_id) SELECT id FROM INSERTED 
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.ModifyPH    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER ModifyPH ON PH AFTER UPDATE AS 
if (substring(columns_updated(),3,1)&power(2,3)=0 AND 
substring(columns_updated(),3,1)&power(2,2)=0) 
BEGIN 
	UPDATE PH SET ModifyDate=CURRENT_TIMESTAMP WHERE ID IN (SELECT ID FROM INSERTED) 
	INSERT INTO MODIFY_DATES (ph_id) SELECT id FROM INSERTED 
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.ModifyPH_Arc    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER ModifyPH_Arc ON PH AFTER UPDATE AS 
if (substring(columns_updated(),7, 1) & power(2,6)<>0) 
BEGIN 
	INSERT INTO MODIFY_DATES (attrval_id) 
	SELECT PH_TO_ATTRVALS.attrval_id
	FROM INSERTED WITH(NOLOCK) LEFT OUTER JOIN PH_TO_ATTRVALS 
	ON INSERTED.ID=PH_TO_ATTRVALS.ph_id 
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.ModifyAttrVal    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER ModifyAttrVal ON ATTRIB_VALS AFTER INSERT, UPDATE AS 
BEGIN 
	UPDATE ATTRIB_VALS SET ModifyDate=CURRENT_TIMESTAMP 
	WHERE ID IN (SELECT ID FROM INSERTED) 
	INSERT INTO MODIFY_DATES (attrval_id) 
	SELECT id from INSERTED 
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.OnDeleteAttrVal_AdminRights    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER OnDeleteAttrVal_AdminRights ON [dbo].[ATTRIB_VALS] AFTER UPDATE AS IF EXISTS (SELECT INS.ID FROM INSERTED INS WHERE Deleted=1) BEGIN DELETE FROM [dbo].[ADMIN_RIGHTS] WHERE CatID IN (SELECT INS.ID FROM INSERTED INS WHERE Deleted=1) END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.OnDeleteJnglCategory    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER OnDeleteJnglCategory ON [dbo].[ATTRIB_VALS] AFTER UPDATE AS UPDATE [dbo].[CAT_JNGL_BTNS] SET Deleted=1 WHERE CatID    IN (SELECT INS.ID FROM INSERTED INS WHERE Deleted=1) OR ParentID IN (SELECT INS.ID FROM INSERTED INS WHERE Deleted=1)
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.OnDeleteCatForAutoMove    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER OnDeleteCatForAutoMove ON [dbo].[ATTRIB_VALS] AFTER UPDATE AS DELETE FROM [dbo].[AUTO_MOVE] WHERE SrcCatID IN (SELECT INS.ID FROM INSERTED INS WHERE Deleted=1) OR DstCatID IN (SELECT INS.ID FROM INSERTED INS WHERE Deleted=1)
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.OnInsertPhToAttrVals    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER OnInsertPhToAttrVals ON PH_TO_ATTRVALS AFTER INSERT,UPDATE AS 
BEGIN 
	INSERT MODIFY_DATES (ph_id)      SELECT ph_id      FROM INSERTED 
	INSERT MODIFY_DATES (attrval_id) SELECT attrval_id FROM INSERTED 
END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/****** Object:  Trigger dbo.OnDeletePhToAttrVals    Script Date: 04.03.2006 15:50:37 ******/
CREATE TRIGGER OnDeletePhToAttrVals ON PH_TO_ATTRVALS AFTER DELETE AS 
BEGIN 
	INSERT MODIFY_DATES (ph_id)      SELECT ph_id      FROM DELETED 
	INSERT MODIFY_DATES (attrval_id) SELECT attrval_id FROM DELETED 
END
GO

INSERT INTO [dbo].[ATTRIBS] (Name,Type) VALUES ('Categories',	0)
INSERT INTO [dbo].[ATTRIBS] (Name,Type) VALUES ('Artists',	0)
INSERT INTO [dbo].[ATTRIBS] (Name,Type) VALUES ('Authors',	0)
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

INSERT INTO [dbo].[TRACT] (Version) VALUES(1000)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1100)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1200)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1210)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1220)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1300)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1310)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1320)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1400)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1410)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1420)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1430)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1500)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1510)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1520)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1600)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1610)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1620)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1630)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1640)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1650)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1660)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1670)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1680)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1700)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1710)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1720)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1730)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1740)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1750)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1760)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1770)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1780)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1781)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1782)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1783)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1790)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1800)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1810)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1820)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1830)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1840)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1850)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1860)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1870)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1880)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1890)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1900)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1910)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1920)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1930)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1940)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1950)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1960)
INSERT INTO [dbo].[TRACT] (Version) VALUES(1970)
GO

declare @ver int
declare @ver_str varchar(128)
set @ver_str = convert(varchar(128),SERVERPROPERTY('ProductVersion'))
set @ver = cast( left(@ver_str, charindex('.', @ver_str)-1) as int )

declare @dbcc_query varchar(256)

if (@ver >= 9)
BEGIN
	set @dbcc_query='ALTER DATABASE ['+DB_NAME()+'] SET SINGLE_USER WITH ROLLBACK AFTER 10'
	EXEC (@dbcc_query)
	set @dbcc_query='ALTER DATABASE ['+DB_NAME()+'] SET READ_COMMITTED_SNAPSHOT ON'
	EXEC (@dbcc_query)
	set @dbcc_query='ALTER DATABASE ['+DB_NAME()+'] SET MULTI_USER'
	EXEC (@dbcc_query)
END
	
if (@ver >= 10)
BEGIN
	set @dbcc_query='ALTER DATABASE ['+DB_NAME()+'] SET RECOVERY SIMPLE'
	EXEC (@dbcc_query)
END
GO
