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 комментарии

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

    Im grateful for the post. Really thank you! Want more. Gwyn Darwin Thorvald

    Среда, 27 января 2021 14:10
  • torrent
    написал torrent Комментировать

    Glad to be one of several visitors on this awe inspiring internet site : D. Ardella Herold Gibbons

    Среда, 27 января 2021 13:14
  • download
    написал download Комментировать

    We ask you to keep your comments relevant and respectful. Milzie Rosco Roarke

    Среда, 27 января 2021 13:04
  • dizi izle
    написал dizi izle Комментировать

    Card can be found and a bit more complicated than that. Carin Felicio Mahalia

    Вторник, 26 января 2021 20:54
  • yabanci dizi
    написал yabanci dizi Комментировать

    Some genuinely nice and useful info on this web site, as well I think the design holds excellent features. Ertha Delaney Amargo

    Вторник, 26 января 2021 20:44
  • torrent
    написал torrent Комментировать

    You got a very good website, Gladiola I noticed it through yahoo. Opal Clyve Rimma

    Вторник, 26 января 2021 13:44
  • bedava
    написал bedava Комментировать

    Please keep us up to date like this. Thank you for sharing. Jacquelin Hayden Burnside

    Вторник, 26 января 2021 13:33
  • sex porn
    написал sex porn Комментировать

    Hi mates, nice post and fastidious urging commented here, I am in fact enjoying by these. Hertha Berkeley Vins

    Вторник, 26 января 2021 03:01
  • bedava
    написал bedava Комментировать

    You made some fine points there. I did a search on the topic and found nearly all folks will go along with with your blog. Marybeth Pieter Marceau

    Вторник, 26 января 2021 02:50
  • erotik
    написал erotik Комментировать

    Good article! We are linking to this particularly great article on our website. Marybelle Tadd Wilser

    Вторник, 26 января 2021 00:00

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

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

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