怎么使用sql語句添加列
alter table 表名 add 列名 數據類型。
結構化查詢語言(Structured Query Language)簡稱SQL,結構化查詢語言是一種數據庫查詢和程序設計語言,用于存取數據以及查詢、更新和管理關系數據庫系統;sql 語句就是對數據庫進行操作的一種語言。
語句
數據庫
CREATE DATABASE database-name
刪除數據
drop database dbname
創建表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
刪除新表
drop table tabname
增加
Alter table tabname add column col type
設主鍵
Alter table tabname add primary key(col)
刪除主鍵
Alter table tabname drop primary key(col)
創建索引
create [unique] index idxname on tabname(col….)
刪除索引
drop index idxname
創建視圖
create view viewname as select statement
刪除視圖
drop view viewname
sql語句
更新:update table1 set field1=value1 where 范圍
查找:select * from table1 where field1 like '%value1%' (所有包含'value1'這個模式的字符串)
排序:select * from table1 order by field1,field2 [desc]
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1[separator]
sql 語句添加列
select *ELD_CITY,
sum(case when *eld_ball = 0 then 1 else 0 end) 高爾夫球,
sum(case when *eld_ball = 1 then 1 else 0 end) 羽毛球,
sum(case when *eld_ball = 3 then 1 else 0 end) 乒乓球,
sum(case when *eld_ball = 5 then 1 else 0 end) 保齡球,
sum(case when *eld_ball = 2 then 1 else 0 end) 臺球,
sum(case when *eld_ball = 4 then 1 else 0 end) 網球,
sum(case when *eld_ball = 6 then 1 else 0 end) 籃球,
sum(case when *eld_ball = 7 then 1 else 0 end) 足球
from golffield g
where *ELD_CITY like '%唐山%' and *eld_delflag = 0
group by *ELD_CITY
--或者
select '唐山' GolfCity,
sum(case when *eld_ball = 0 then 1 else 0 end) 高爾夫球,
sum(case when *eld_ball = 1 then 1 else 0 end) 羽毛球,
sum(case when *eld_ball = 3 then 1 else 0 end) 乒乓球,
sum(case when *eld_ball = 5 then 1 else 0 end) 保齡球,
sum(case when *eld_ball = 2 then 1 else 0 end) 臺球,
sum(case when *eld_ball = 4 then 1 else 0 end) 網球,
sum(case when *eld_ball = 6 then 1 else 0 end) 籃球,
sum(case when *eld_ball = 7 then 1 else 0 end) 足球
from golffield g
where *ELD_CITY like '%唐山%' and *eld_delflag = 0
SQL語句如何增加列
向表結構中加入一列 SQL>alter table studen add(stuphoto varchar(9));
從表結構中刪除一列 SQL>alter table studen drop column stuphoto;
修改表一列的長度 SQL>alter table studen modify(stuno number(4));
隱藏將要刪除的一列 SQL>alter table studen set unused column stuphoto;
刪除隱藏的列 SQL>alter table studen drop unused columns;
向表中加入約束 SQL>alter table studen add constraint pk primary key(stuno);
刪除約束 SQL>alter table studen drop constraint pk;
SQL向表中添加一列用什么命令
使用SQL語句為數據表增加一個字段,使用alter table子句。 語法:alter table 表格名 add 字段名 。數據類型 -alter table table_name add col_name char(5)。
延展知識:
1. 含義:sql 語句是對數據庫進行操作的一種語言。結構化查詢語言(Structured Query Language)簡稱SQL,結構化查詢語言是一種數據庫查詢和程序設計語言,用于存取數據以及查詢、更新和管理關系數據庫系統。
2. 簡單基本的sql語句 :
更新:update table1 set field1=value1 where
范圍 查找:select * from table1 where field1 like '%value1%' (所有包含'value1'這個模式的字符串)
排序:select * from table1 order by field1,field2 [desc] 求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1[separator]