怎樣將資料庫裡欄位中的某個字元去掉

2021-10-05 03:03:19 字數 1351 閱讀 1475

1樓:匿名使用者

有兩種基本方法可以試試:

第1種:

create table my_table

(id   int      not null,

name char(10) not null,

address varchar(64)  null,

constraint pk_my_table primary key clustered (id, name)

)解釋:my_table是表名,pk_my_table是主鍵名,constraint約束,primary key 建主鍵關鍵字,clustered 是聚集關鍵字。

第2種:

是在表先create建立之後,再追加主鍵:

alter table my_table add constraint pk_my_table primary key nonclustered (id,name)

在語法中,括號中的主鍵列可以多個。不過聯合主鍵最好限制使用,會影響索引的效率。

2樓:隨緣_莫隨緣

update tablename set columnname=replace(columnname,'市','')

或者保險一點兒:

update tablename set columnname=replace(columnname,'北京市','北京')。。。

如何替換資料庫中某個欄位中的資料

3樓:波光視野

不同的資料庫,替換欄位值的命令格式是不同的,現以myslq 為例說明:

在資料庫中修改一些內容,就需要用到下列語句:

sql語句為:update `table_name` set `field_name` = replace (`field_name`,』from_str』,'to_str』) where ……

**說明: table_name —— 表的名字 field_name —— 欄位名 from_str —— 需要替換的字串 to_str —— 替換成的字串 目的是為了直接用sql運算元據庫修改欄位中的某些字串,也可以使用下列方法有條件的替換,比較麻煩,需要三步,先select出來符合的記錄,然後進行字串替換,再update。

假如我要替換的內容是:把』家 樂 福』字元替換成』jia le fu』 要替換的內容在:資料表 cdb_posts中的message 欄位。那我們就應該這樣寫:

update dede_addonarticle set body=replace(body, 『家樂福』, 『jia le fu』);

如果是在自編的程式中替換,用迴圈加賦值語句就行,當然,也可以直接使用用sql命令來實現,就看你個人喜好了。

在mysql資料庫中如何讓某個欄位有重複的只取一條

保留 bai相du 同zhia值的 dao最小 專屬id行 select from table a a where not exists select 1 from table a bwhere b.a a.a and b.id a.id select top 1 id,name,age from ...

EXCEL中怎麼提取單元格中的某個字元,並顯示為特定字元。如圖所示。高分求助

提取工號好辦,用 left a1,6 這樣的公式就行,但和工號對應的姓名得有列表才行。假設上表為sheet1表,下表為sheet2表在sheet1表的b2輸入 lookup 1,0 find sheet2 a 2 a 32,a2 sheet2 b 2 b 32 下拉填充 對 vlookup 加工一下...

sql中,按照某個欄位的內容進行分組,並在組內加序號

sqlserver2005及以上版本 select row number over partition by 種類 order by 種類 as 序號,from 表 oracle select row number over partition by table.種類 order by table....