Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

基本SQL语句 sql SQLServer SQL语句 SQL语句学习

$
0
0

基本SQL语句。

创建数据库

CREATE DATABASE database-name

删除数据库

DROP database dbname

创建新表

create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)

根据已有的表创建新表

create table a as select * from b(使用旧表创建新表)

删除新表

DROP table tabname

添加字段的语法:

alter table tablename add (column datatype [default value][null/not null],….);

修改字段的语法:

alter table tablename modify (column datatype [default value][null/not null],….);

删除字段的语法:

alter table tablename drop (column);

几个简单的基本的sql语句

插入:

1. insert into table1(field1,field2) values(value1,value2)

2. insert into table1(table1.field1,table1.field2)select table2.field3 field1,table2.field4 field2 from table2 where 范围

删除:delete from table1 where 范围

更新:

1. update table1 set field1=value1 where 范围

2. update table1 set (table1 .field1)=(select table12.field1 from table2 where 范围) where 范围

查找:select * from table1 where field1 like ’%value1%’

排序:select * from table1 order by field1,field2 [desc]

总数:select count as totalcount from table1

求和: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


Viewing all articles
Browse latest Browse all 3160

Trending Articles