All infos - Создание расширеных свойств на таблице sql server

Создание расширеных свойств на таблице sql server

Пример создания расширенных свойств для таблицы на sql server.

USE [DB_NAME];
GO
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO

CREATE TABLE [dbo].[ProductFragmentationHistory]
        ([Id]                  [INT] IDENTITY(1, 1) NOT NULL, 
         [ProductFragmentationId] [INT] NOT NULL, 
         [ProductId]              INT NOT NULL, 
         [ParentId]            INT NOT NULL, 
         [Created]             DATETIME NOT NULL, 
         [UserId]              INT NULL, 
         [Archived]            [DATETIME] NOT NULL, 
         CONSTRAINT [PK_ProductFragmentationHISTORY] PRIMARY KEY CLUSTERED([Id] ASC)
        )

GO

IF NOT EXISTS
(
    SELECT NULL
    FROM sys.objects
    WHERE object_id = OBJECT_ID(N'[dbo].[ProductFragmentationHistory]')
          AND type IN(N'U')
)
    BEGIN
        CREATE TABLE [dbo].[ProductFragmentationHistory]
        ([Id]                  [INT] IDENTITY(1, 1) NOT NULL, 
         [ProductFragmentationId] [INT] NOT NULL, 
         [ProductId]              INT NOT NULL, 
         [ParentId]            INT NOT NULL, 
         [Created]             DATETIME NOT NULL, 
         [UserId]              INT NULL, 
         [Archived]            [DATETIME] NOT NULL, 
         CONSTRAINT [PK_ProductFragmentationHISTORY] PRIMARY KEY CLUSTERED([Id] ASC)
        )
END;
GO
IF NOT EXISTS
(
    SELECT NULL
    FROM sys.all_columns c
         JOIN sys.tables t ON t.object_id = c.object_id
         JOIN sys.schemas s ON s.schema_id = t.schema_id
         JOIN sys.default_constraints d ON c.default_object_id = d.object_id
    WHERE t.name = 'ProductFragmentationHistory'
          AND c.name = 'Archived'
          AND s.name = 'dbo'
)
    BEGIN
        ALTER TABLE [dbo].[ProductFragmentationHistory]
        ADD CONSTRAINT [DF_ProductFRAGMENTATIONHISTORY_ARCHIVED] DEFAULT(GETDATE()) FOR [Archived];
END;
GO
IF NOT EXISTS
(
    SELECT NULL
    FROM SYS.EXTENDED_PROPERTIES
    WHERE [major_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
          AND [name] = N'MS_Description'
          AND [minor_id] =
    (
        SELECT [column_id]
        FROM SYS.COLUMNS
        WHERE [name] = 'Id'
              AND [object_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
    )
)
    EXECUTE sys.sp_addextendedproperty 
            @name = N'MS_Description', 
            @value = N'Уникальный идентификатор', 
            @level0type = N'SCHEMA', 
            @level0name = 'dbo', 
            @level1type = N'TABLE', 
            @level1name = 'ProductFragmentationHistory', 
            @level2type = N'COLUMN', 
            @level2name = N'Id';
GO
IF NOT EXISTS
(
    SELECT NULL
    FROM SYS.EXTENDED_PROPERTIES
    WHERE [major_id] = OBJECT_ID('ProductFragmentationHistory')
          AND [name] = N'MS_Description'
          AND [minor_id] =
    (
        SELECT [column_id]
        FROM SYS.COLUMNS
        WHERE [name] = 'ProductFragmentationId'
              AND [object_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
    )
)
    EXECUTE sys.sp_addextendedproperty 
            @name = N'MS_Description', 
            @value = N'Уникальный идентификатор связи фрагментированного Product ', 
            @level0type = N'SCHEMA', 
            @level0name = 'dbo', 
            @level1type = N'TABLE', 
            @level1name = 'ProductFragmentationHistory', 
            @level2type = N'COLUMN', 
            @level2name = N'ProductFragmentationId';
GO
IF NOT EXISTS
(
    SELECT NULL
    FROM SYS.EXTENDED_PROPERTIES
    WHERE [major_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
          AND [name] = N'MS_Description'
          AND [minor_id] =
    (
        SELECT [column_id]
        FROM SYS.COLUMNS
        WHERE [name] = 'ProductId'
              AND [object_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
    )
)
    EXECUTE sys.sp_addextendedproperty 
            @name = N'MS_Description', 
            @value = N'Идентификатор фрагментированного Product', 
            @level0type = N'SCHEMA', 
            @level0name = 'dbo', 
            @level1type = N'TABLE', 
            @level1name = 'ProductFragmentationHistory', 
            @level2type = N'COLUMN', 
            @level2name = N'ProductId';
GO
IF NOT EXISTS
(
    SELECT NULL
    FROM SYS.EXTENDED_PROPERTIES
    WHERE [major_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
          AND [name] = N'MS_Description'
          AND [minor_id] =
    (
        SELECT [column_id]
        FROM SYS.COLUMNS
        WHERE [name] = 'ParentID'
              AND [object_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
    )
)
    EXECUTE sys.sp_addextendedproperty 
            @name = N'MS_Description', 
            @value = N'Идентификатор родителя фрагментированного Product', 
            @level0type = N'SCHEMA', 
            @level0name = 'dbo', 
            @level1type = N'TABLE', 
            @level1name = 'ProductFragmentationHistory', 
            @level2type = N'COLUMN', 
            @level2name = N'ParentId';
GO
IF NOT EXISTS
(
    SELECT NULL
    FROM SYS.EXTENDED_PROPERTIES
    WHERE [major_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
          AND [name] = N'MS_Description'
          AND [minor_id] =
    (
        SELECT [column_id]
        FROM SYS.COLUMNS
        WHERE [name] = 'Created'
              AND [object_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
    )
)
    EXECUTE sys.sp_addextendedproperty 
            @name = N'MS_Description', 
            @value = N'Дата создания фрагментированного Product', 
            @level0type = N'SCHEMA', 
            @level0name = 'dbo', 
            @level1type = N'TABLE', 
            @level1name = 'ProductFragmentationHistory', 
            @level2type = N'COLUMN', 
            @level2name = N'Created';
GO
IF NOT EXISTS
(
    SELECT NULL
    FROM SYS.EXTENDED_PROPERTIES
    WHERE [major_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
          AND [name] = N'MS_Description'
          AND [minor_id] =
    (
        SELECT [column_id]
        FROM SYS.COLUMNS
        WHERE [name] = 'UserId'
              AND [object_id] = OBJECT_ID('dbo.ProductFragmentationHistory')
    )
)
    EXECUTE sys.sp_addextendedproperty 
            @name = N'MS_Description', 
            @value = N'Идентификатор пользователя создавшего фрагментацию Product', 
            @level0type = N'SCHEMA', 
            @level0name = 'dbo', 
            @level1type = N'TABLE', 
            @level1name = 'ProductFragmentationHistory', 
            @level2type = N'COLUMN', 
            @level2name = N'UserID';
GO
IF NOT EXISTS
(
    SELECT NULL
    FROM SYS.EXTENDED_PROPERTIES
    WHERE [major_id] = OBJECT_ID('ProductFragmentationHistory')
          AND [name] = N'MS_Description'
          AND [minor_id] = 0
)
    EXEC sys.sp_addextendedproperty 
         @name = N'MS_Description', 
         @value = N'Таблица связей фрагментированных Product', 
         @level0type = N'SCHEMA', 
         @level0name = N'dbo', 
         @level1type = N'TABLE', 
         @level1name = N'ProductFragmentationHistory';
GO

Share this post

82 комментарии

  • bluray
    написал bluray Комментировать

    Thanks for ones marvelous posting! I genuinely enjoyed reading it, you will be a great author. Dayna Gardiner Natalee

    Четверг, 21 января 2021 23:06
  • free porn
    написал free porn Комментировать

    Wonderful article! We will be linking to this great post on our website. Keep up the great writing. Perrine Meredith Triley

    Четверг, 21 января 2021 20:58
  • sex porn
    написал sex porn Комментировать

    Hello friends, good article and pleasant urging commented here, I am really enjoying by these. Jillana Woodman Warde

    Четверг, 21 января 2021 20:48
  • celebrities
    написал celebrities Комментировать

    Hiya very nice web site!! Man .. Beautiful .. Wonderful .. Libbey Galven Ehud

    Четверг, 21 января 2021 19:57
  • anime
    написал anime Комментировать

    Thanks for all your efforts that you have put in this. very interesting information. Kore Robinet Sorel

    Четверг, 21 января 2021 19:47
  • yabanci dizi
    написал yabanci dizi Комментировать

    There is noticeably a package to find out about this. I think you made sure wonderful points in attributes additionally. Aggi Haslett Balliol

    Четверг, 21 января 2021 18:28
  • free porn
    написал free porn Комментировать

    Definitely believe that which you stated. Your favorite reason appeared to be on the internet the easiest thing to be aware of. Adore Benedetto Urbani

    Четверг, 21 января 2021 18:18
  • faketaxi
    написал faketaxi Комментировать

    Well I really enjoyed reading it. This post provided by you is very constructive for accurate planning. Berrie Lowrance Sy

    Четверг, 21 января 2021 17:31
  • 720p
    написал 720p Комментировать

    Hi there, all the time i used to check webpage posts here early in the morning, since i love to learn more and more. Dorena George Gaige

    Четверг, 21 января 2021 17:21
  • celebrities
    написал celebrities Комментировать

    Hello very cool site!! Man .. Excellent .. Amazing .. Christabel Durante Billmyre

    Четверг, 21 января 2021 16:47

Оставить комментарий

Убедитесь, что Вы ввели всю требуемую информацию, в поля, помеченные звёздочкой (*). HTML код не допустим.

Оцените материал
(0 голосов)
Прочитано 556 раз
Другие материалы в этой категории: « Конвертация строки в число