SQL Server正在删除varchar列

时间:2016-03-09 17:42:05

标签: sql-server

我尝试将数据插入到varchar(50)的列中,但随机SQL Server会删除前导零。

我插入了" 1471"手动,像这样:

insert into X (ds_code_product) values ('001471')

但SQL做了' 1471'

截图:

Screenshot

这是Create语句:

CREATE TABLE [dbo].[PRODUCT](
    [CD_PRODUCT] [int] IDENTITY(1,1) NOT NULL,
    [DS_CODE_PRODUCT] [varchar](50) NOT NULL,
    [NM_PRODUCT] [varchar](200) NOT NULL,
    [DS_CODE_SUPPLIER] [varchar](50) NOT NULL,
    [CD_COMPANY_UNIT] [smallint] NOT NULL,
    [VL_STATUS] [smallint] NOT NULL,
    [DT_READ] [datetime] NULL,
    [DT_CREATE] [datetime] NOT NULL,
    [TP_PRODUCT] [varchar](1) NULL DEFAULT ('1'),
 CONSTRAINT [PK_PRODUCT] PRIMARY KEY CLUSTERED 
(
    [CD_PRODUCT] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Identificador do Produto' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'CD_PRODUCT'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Código do Produto ERP' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'DS_CODE_PRODUCT'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Descrição do Produto' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'NM_PRODUCT'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Código do Fornecedor ERP' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'DS_CODE_SUPPLIER'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Código da Filial' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'CD_COMPANY_UNIT'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Status de importação:
(1) importado pelo ERP com sucesso.
(2) importado pelo ERP inconsistência.
(3)Lido com sucesso pela automação.
(4)lido automação com inconsistência.
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'VL_STATUS'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Data da Leitura' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'DT_READ'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Data da Importação' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'DT_CREATE'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Tipo de Produto:
1 - Geral (Valor Padrão)
2-  Matéria-Prima
3 - Produto Final 
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT', @level2type=N'COLUMN',@level2name=N'TP_PRODUCT'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Tabela de Produtos' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'PRODUCT'
GO

完整插入:

INSERT INTO PRODUCT (DS_CODE_PRODUCT, NM_PRODUCT, DS_CODE_SUPPLIER, CD_COMPANY_UNIT, VL_STATUS, DT_CREATE, TP_PRODUCT)
VALUES ('001441','TORTA DE ALGODAO GRANEL','-1',22,1,'2016/03/09','2')

0 个答案:

没有答案