今天看啥  ›  专栏  ›  小蚊子数据分析

【收藏】数据分析常用的SQL语句

小蚊子数据分析  · 公众号  ·  · 2019-12-18 08:01
1.创建新表create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..) 2.根据已有的表创建新表 A:create table tab_new like tab_old (使用旧表创建新表)B:create table tab_new as select col1,col2… from tab_old definition only3.增加一个列Alter table tabname add column col type注:列增加后将不能删除。DB2中列加上后数据类型也不能改变,唯一能改变的是增加varchar类型的长度。4.添加主键: Alter table tabname add primary key(col) 说明:删除主键: Alter table tabname drop primary key(col) 5.创建索引:create [unique] index idxname on tabname(col….) 删除索引:drop index idxname注:索引是不可更改的,想更改必须删除重新建。6.几个简单的基本的sql语句选择(这个功能是最最常用的)select * from table1 where 范围SELECT * FROM Persons ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照