我正在尝试编写一些SQL语句,以便通过删除其中一列的所有空格来更新整个数据库表。
以下是数据库设计:
<!-- language: lang-sql -->
/****** Object: Table [dbo].[document_control] Script Date: 02/06/2012 21:02:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[document_control](
[id] [int] IDENTITY(1,1) NOT NULL,
[doc_number] [nchar](10) NOT NULL,
[doc_title] [nchar](256) NOT NULL,
[co_num] [int] NULL,
[co_date] [date] NULL,
[doc_path] [nchar](256) NULL,
[doc_revision] [int] NULL,
[doc_family] [nvarchar](5) NULL,
CONSTRAINT [PK_document_control] PRIMARY KEY CLUSTERED
(
[id] 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
我在 [doc_path] 专栏中有很多空格。我知道我可以轻松地使用 LTRIM()功能去除间隔;但是,如何编写SQL语句以便更新整个数据库?
答案 0 :(得分:1)
您应该像这样更改列类型:
ALTER TABLE [dbo].[document_control] MODIFY COLUMN [doc_path] [nvarchar](256)
GO
UPDATE [dbo].[document_control] SET
[doc_path] = RTRIM([doc_path])
GO
对于文档标题和编号,可选择相同。