如何通过删除其中一列的尾随空格来更新数据库表?
我正在尝试编写一些 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 语句才能更新整个数据库呢?
I am trying to write some SQL statement so I can update my entire database table by removing all the spaces from one of its columns.
Here is the database design:
<!-- 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
I have lots of spaces in the [doc_path] column specifically. I know I can easily use LTRIM() function to remove the spaced; however, how can I write a SQL statement so I can update the entire database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该像这样更改列类型:
并且可以选择对文档标题和编号进行相同的更改。
You should change your column type like this:
And optionally the same for doc title and number.