SQL语句1——单表查询

create database aaa
drop database aaa
--结构drop
--内容delete

--列名 数据类型 [完整性约束]
--1、列名,命名规则
--2、数据类型:text char(8000) nchar varchar nvarcha
     int bigint smallint tinyint
    money float,numeric(20,3) ,decimal(10,5)
     datetime smalldatetime
     binary(20),bit,imag 
   
--3\约束:实体:primary key
          参照:foreingn key
           自己定义:not null
                    unique
                    check
                    default
create table emp
(eno char(10) primary key,
 ename varchar(30) not null unique,
 eage tinyint check(eage<100),
 eworktime datetime 
)

DDL:create drop
DML:insert
--1、insert into
insert into 表名(列名1,列名2,..)
values(值1,值2。。)

select * from stu
select * from sc
insert into 
stu
values('006','puppy',21,'m','wlx')

insert into sc
values('002','c01',70)

--2 select:表、行、列
select 列
from  表
where 条件(行)
一、select后列的操作
1、所有列
select *
from  stu
2、部分列
select sname,sno,ssex
from stu
3、重新命名列
select sname as name,sno,ssex
from stu
select sname as 姓名,sno 学号
from stu
4 、列的计算
 一、字符类型的列的连接 +
 select sno+sname as xuehaoxingming
 from  stu
select Rtrim(sno)+sname as xuehaoxingming
from stu
--字符串的操作
select '2009'+sno newsno
from stu
--常量列
select '2009'
from stu
二、数值类型的计算 + —— * /
select 2012-sage as birthyear
from stu
三、日期时间类型的计算,getdate(),year(),month,day()
select year(getdate())-sage birthyear
from stu
4、消除重复列
select distinct sdept
from stu

--where后的筛选条件,and or not
select *
from stu
where sname like '%j__'
1、比较>,<,>=,<=,<>,!=
2、闭区间 between and 的等价关系
      not between and 
3、模糊比较 like
 作用范围:用于字符类型和日期时间类型,
 凡是加引号的
 %:代表任意多个字符
 _:代表任意单个字符
4、空值的比较 is null / is not null
select * 
from stu
where sdept is not null  and sage>20
and sname like '_i%'

--from 后表的连接
--查询所有学生的姓名和成绩
select stu.sno
from (stu inner join sc on stu.sno=sc.sno)
     

select *
from stu,sc
where stu.sno=sc.sno

select  列
from  表
where 条件








     

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值