怎么使用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語句如何增加列
向表結構中加入一列 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 語句添加列
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語句怎么加列
ALTER TABLE 語句 ALTER TABLE 語句用于在已有的表中添加、修改或刪除列。
ALTER TABLE 語法 如需在表中添加列,請使用下列語法: ALTER TABLE table_name ADD column_name datatype 在表 "Persons" 中添加一個名為 "Birthday" 的新列。 ALTER TABLE Persons ADD Birthday date 新列 "Birthday" 的類型是 date,可以存放日期。
數據類型規定列中可以存放的數據的類型。 擴展資料: 基本語句 1、數據記錄篩選: sql="select * from 數據表 where字段名 = 字段值 order by 字段名[desc]"(按某個字段值降序排列,默認升序ASC)。
sql="select * from 數據表 where 字段名 like '%字段值%' order by 字段名 [desc]" sql="select top 10 * from 數據表 where字段名=字段值 order by 字段名 [desc]" sql="select * from 數據表 where字段名 in ('值1','值2','值3')" sql="select * from 數據表 where 字段名 between 值1 and 值2" sql="select 列名1,列名2 from 數據表 where 字段名=字段值 group by 列名1,列名2 " (group by 用來分組,并且只有出現自group by 中的列名,才允許出現在select 語句中)。 2、更新數據記錄: sql="update 數據表 set字段名=字段值 where 條件表達式" sql="update 數據表 set 字段1=值1,字段2=值2 …… 字段n=值n where 條件表達式" 3、刪除數據記錄: sql="delete from 數據表 where 條件表達式" sql="delete from 數據表" (將數據表所有記錄刪除) 參考資料來源:百度百科-SQL語句大全。