sql 語句之插入新字段

2021-04-18 21:55:13 字數 731 閱讀 4793

1.    如何用sql語句給表增加字段?

alter   table   表名   add   列名   varchar(20)   null

注意只能新增允許為空的字段,新增不為空的會出錯

怎麼樣增加預設值為null,屬性為varchar,長度為20的字段?

alter   table   表名   add   列名   varchar(20)   default   null

分割槽檢視 

create   table   [2023年資料]   (編號   int,年   int   check(年=2002)   default   2002,資料   int,primary   key(編號,年))     

create   table   [2023年資料]   (編號   int,年   int   check(年=2003)   default   2003,資料   int,primary   key(編號,年)) 

create   view   所有資料   as 

select   *   from   [2023年資料]   

union   all 

select   *   from   [2023年資料]    go

2.    order by 的使用

search = search & " order by zlx_name desc , tlx_name asc , orderid asc "

更新欄位的sql

update pro traininfo t set t.totalmoney select a.price t.totaltime from gen makepriceinfo a where a.studentcode t.studentcode and a.examcode t.examcod...

資料插入之前更新字段值

在乙個表報警資訊中插入記錄,但是沒有x,y值資訊,其中的x,y值要根據記錄中的現場警力編號到gps警員表中查取xy值,然後付給當前記錄,再進行插入。create or replace trigger getxy before insert on sdga.報警資訊 for each row decl...

通過sql批量更新字段內容

1.也許現在大家都不需要寫sql了,鑑於我技術比較落後,加上開發的系統還有在使用,所以還是有業務需要用到。2.伺服器搬家,導致資料庫裡,伺服器的路徑發生改變,所以要批量替換。設定網域名稱就不用管這個坑 檢索出要替換的內容條數 select count from shop item where pho...