首页 > 数据库技术 > 详细

数据库

时间:2015-10-20 01:14:39      阅读:247      评论:0      收藏:0      [点我收藏+]

命名习惯 数据库名.MyDB           表名.StuInfo

 

数据类型

int 整形

datetime 日期    getdate()

float 浮点

bit 布尔值

nvarchar(50) 变长  文本型

nvarchar(MAX) 备注

 

创建数据库

create database Library

 

创建表

create table Users

(

UID int primary key,

userName nvarchar(20) not null,

userPwd nvarchar(20) not null

)

 

查询语句

select * from StuInfo

select Sex,Age from StuInfo

 

select * from StuInfo where Sex=‘男‘ and (Age = 21 or Age=22)

select * from StuInfo where Sex=‘男‘ and Age in(21,22)

 

select * from StuInfo where Age>=10 and Age<=30

select * from StuInfo where Age between 20 and 25

 

select top 3 StuId,Sex from StuInfo where Sex=‘男‘ order by Age desc  //desc倒序

 

select * from StuInfo where StuId like ‘%a%‘

 

select COUNT(*) as UserCount from StuInfo where Sex=‘男‘  //count()统计

 

select MIN(Age) as MinAge from StuInfo

 

select MAX(Age) as MaxAge from StuInfo

 

select Avg(Age) as AvgAge from StuInfo  //avg平均值

 

select * from StuInfo where Age>

(

select Avg(Age) as AvgAge from StuInfo

)

select COUNT(*) as AgeCount,Age from StuInfo Group by Age  //分组

having COUNT(*)=1 order by Age

 

添加语句

insert into StuInfo values(‘11‘,‘吧‘,‘女‘,20,‘2005-7-30‘,‘‘,‘true‘,‘eqwe‘)

 

insert into StuInfo(StuId,Age) values(‘qq‘,11)

 

删除语句

delete StuInfo where StuId=‘qq‘

 

更新语句

update StuInfo set Sex=‘女‘ where ParenetId=1

 

联合查询

Left join      right join

技术分享

数据库

原文:http://www.cnblogs.com/relstart/p/4893465.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!