篇一 :简单SQL语句总结

简单SQL语句总结

1.在查询结果中显示列名:

a.用as关键字:select name as '姓名' from students order by age

b.直接表示:select name '姓名' from students order by age

2.精确查找:

a.用in限定范围:select * from students where native in ('湖南', '四川')

b.between...and:select * from students where age between 20 and 30

c.“=”:select * from students where name = '李山'

d.like:select * from students where name like '李%' (注意查询条件中有“%”,则说明是部分匹配,而且还有先后信息在里面,即查找以“李”开头的匹配项。所以若查询有“李”的所有对象,应该命令:'%李%';若是第二个字为李,则应为'_李%'或'_李'或'_李_'。)

e.[]匹配检查符:select * from courses where cno like '[AC]%' (表示或的关系,与"in(...)"类似,而且"[]"可以表示范围,如:select * from courses where cno like '[A-C]%')

3.对于时间类型变量的处理

a.smalldatetime:直接按照字符串处理的方式进行处理,例如:

select * from students where birth > = '1980-1-1' and birth <= '1980-12-31'

4.集函数

a.count()求和,如:select count(*) from students (求学生总人数)

…… …… 余下全文

篇二 :[数据库]简单SQL语句总结

[数据库] 简单SQL语句总结

全篇以学生成绩的管理为例描述。

1.在查询结果中显示列名:

a.用as关键字:select name as '姓名' from students order by age

b.直接表示:select name '姓名' from students order by age

2.精确查找:

a.用in限定范围:select * from students where native in ('湖南', '四川')

b.between...and:select * from students where age between 20 and 30

c.“=”:select * from students where name = '李山'

d.like:select * from students where name like '李%' (注意查询条件中有“%”,则说明是部分匹配,而且还有先后信息在里面,即查找以“李”开头的匹配项。所以若查询有“李”的所有对象,应该命令:'%李%';若是第二个字为李,则应为'_李%'或'_李'或'_李_'。)

e.[]匹配检查符:select * from courses where cno like '[AC]%' (表示或的关系,与"in(...)"类似,而且"[]"可以表示范围,如:select * from courses where cno like '[A-C]%')

3.对于时间类型变量的处理

a.smalldatetime:直接按照字符串处理的方式进行处理,例如:

select * from students where birth > = '1980-1-1' and birth <= '1980-12-31'

…… …… 余下全文

篇三 :SQL语句总结

Create 用法:(建库,建表,建视图,建索引)

1、建 库:Create database 数据库名

2、建 表:Create table 表名

3、建视图:Create view 视图名 AS 查询语句

4、建索引:Create index 索引名 on 表名(列名)

Drop 用法:(删数据库,删表,删视图,删索引)

1、删除数据库:Drop database 数据库名

2、删除表: Drop table 表名

3、删除视图: Dorp view 视图名

4、删除索引: Drop index 表名.索引名

Alter 用法:

1、表中数据结构:Alter table 表名 alter column 列名varchar(8)

2、添加字段列: Alter table 表名 add 列名 varchar(4)

3、删除字段列: Alter table 表名 drop column 列名

4、修改视图: Alter view 视图名

Update 用法:

1、表中的资料: Update 表名 set 列名= 表达式 where 条件

Delete 用法:

1、删除表中资料:Delete from 表名 where 条件表达式

Insert into 用法 :

1、Insert into 表名 values (表达式)

2、Insert into 表名 (列名,列名) values (表达式)

3、Insert 视图名 values (表达式)

select 查询语句:

1、查询表中所有资料:Select *from 表名

2、查询视图所有资料:Select *from 视图名

3、查询部分列: Select 列名,列名 from 表名

…… …… 余下全文

篇四 :SQL语句总结

SQL语句总结

一. 模式的定义和删除

1. 定义模式:

create scheme <模式名> authorization <用户名>

Eg:定义一个学生-课程模式S-T

create scheme “S-T” authorization Wang (为学生wang定义了一个模式

S-T,如果没有指定模式名,则模式名默认为用户名wang)

2. 删除模式:

Drop schema <模式名> <cascade/restrict>(cascade:级联删除)

二.创建库:

Create database qiao;

二. 基本表的定义,删除和修改:

1. 表的定义:建立一个“课程”表Caurse

create table Courae

(Cname char(40),

Cpno char(4))

2. 表的删除:

drop table <表名> cascade/restrinct

3. 表的修改:

Alter table <表名>

add<新表名><数据类型>完整性约束(用于增加新列和新的完整性约

束条件)

drop<完整性约束名>(用于删除指定的完整性约束)

alter column<列名><数据类型>(用于修改原有的列定义,包括修改

列名和数据类型)

Eg:向Student表增加“入学时间”列,其中数据类型为时期型: alter table Student

add S_entrance DATE;

Eg:将年龄的数据类型由字符型改为整数:

alter table Student

alter molumn Sage INT;

Eg:增加课程名称必须取唯一值的约束条件:

…… …… 余下全文

篇五 :SQL语句总结

SQL数据库语句

一、对表操作

1.新建数据库

create database 数据库名

2.新建表

create table 表名(字段1 数据类型 [限制条件], 字段2数据类型 [限制条件]);

限制条件:unique限制不能重复,not null规定不能为空,primary key表示主键,既限制不能为空又限制不能重复

3.查询

一般语法:select[distinct(不输出重复值)]字段1,字段2from 表名 where条件 select *from 表名(查询全体成员)

select 字段1,字段2….from 表名

select *from 表名 where 字段名 查询条件

select *from 表名 order by 成绩 desc(降序)/asc(升序)

4. 删除表/数据库

drop table/database 表名/数据库名

5.清空表

delete from 表名

6.每次打开数据库才能对表操作

use 数据库名

7.显示所有的数据库/表

show databases/tables

8.重命名表

alter table 原名 rename新名;

二、对字段操作

1.限制字段长度

create table ( username varchar(50) check(len(username) between 5

and 15), password varchar(10) check(len(password ) between 6 and

8)))

2.更改字段名

alter table 表名 change 原名 新名 类型 [限制条件];

3. 调整字段顺序

alter table 表名change 新(旧)字段名 新(旧)字段名 字段类型 after 字段名(跳到哪个字段之后);

…… …… 余下全文

篇六 :数据库 最全的sql语句总结大全

CREATE DATABASE edu ON(

NAME=edu_data,

FILENAME='c:/edu_data.mdf',

SIZE=10M,

MAXSIZE=1024M,

FILEGROWTH=1M)

LOG ON(

NAME=edu_log,

FILENAME='c:/edu_log.ldf',

SIZE=5M,

MAXSIZE=100M,

FILEGROWTH=10%)

create database st

use st

drop database st

create schema st

drop schema cascade

1 create table st.Student(....);

2 create schema st

create table Student(...);

3 set search_path to st;

create table Student(..);

create table Student

(Sno char(9) primary key,

Sname char(20) unique,

Ssex char(20) check(sex=''or sex='')

)

create table sc

(Sno char(9)

Cno char(4)

Grade smallint

primary key (Sno,Cno)

foreign key(Sno) references Student(Sno),

foreign key(Cno) references Course(Cno));

alter table Student add Scom datetime;

add unique(Cname);

alter column Sage smallint;

…… …… 余下全文

篇七 :SQL语句总结

SQL语句总结

一、插入记录

1. 插入固定的数值

语法:

INSERT  [INTO]  表名[(字段列表)]  VALUES(值列表)

示例1:

Insert into Students values('Mary’,24,’mary@163.com’)

若没有指定给Student表的哪些字段插入数据:<情况一>表示给该表的所有字段插入数据,根据数据的个数,可以得知Students表中一共有3个字段<情况二>表中有4个字段,其中一个字段是标识列。

示例2:

Insert into Students(Sname,Sage) values(‘Mary’,24)

指定给表中的Sname,Sage两个字段插入数据。

注意事项:

1) 该命令运行一次向表中插入1条记录。无法实现向已存在的某记录中插入一个数据

2) 如果不指定给哪些字段插入数值,则应注意值列表的值个数

3) 插入数据时,注意值的数据类型要与对应的字段数据类型匹配

4) 插入数据时,如果没有给值的字段必须保证允许其为空

5) 插入数据时,要注意字段中的一些约束

2. 插入的记录集为一个查询结果

语法:

INSERT  INTO  表名[(字段列表)]  SELECT 字段列表 FROM  表  WHERE  条件

示例1:

Insert  into  Teacher  select  Sname,Sage,Semail  from  Student

从Student表中查询三个字段的全部记录,插入Teacher表,没有指定Teacher表的具体字段,表示给Teacher表的全部字段插入数值

示例2:

Insert  into  Teacher  select  Sname,Sage,Semail  from  Student  where  Sage>25

…… …… 余下全文

篇八 :SQL语句总结之常用语

SQL语句总结之常用语

一些常用的SQL语句:

新建表:

create table [表名]

(

[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,

[字段1] nVarChar(50) default '默认值' null ,

[字段2] ntext null ,

[字段3] datetime,

[字段4] money null ,

[字段5] int default 0,

[字段6] Decimal (12,4) default 0,

[字段7] image null ,

)

新建表:

create table [表名]

(

[自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,

[字段1] nVarChar(50) default '默认值' null ,

[字段2] ntext null ,

[字段3] datetime,

[字段4] money null ,

[字段5] int default 0,

[字段6] Decimal (12,4) default 0,

[字段7] image null ,

)

删除表:

Drop table [表名]

插入数据:

INSERT INTO [表名] (字段1,字段2) VALUES (100,'51WINDOWS.NET')

删除数据:

DELETE FROM [表名] WHERE [字段名]>100

更新数据:

UPDATE [表名] SET [字段1] = 200,[字段2] = '51WINDOWS.NET' WHERE [字段三] = 'HAIWA' 新增字段:

ALTER TABLE [表名] ADD [字段名] NVARCHAR (50) NULL

删除字段:

ALTER TABLE [表名] DROP COLUMN [字段名]

…… …… 余下全文