当前位置 : 主页 > 手机开发 > ROM >

select

来源:互联网 收集:自由互联 发布时间:2021-06-10
--use School --insert 往表里插入数据 --insert table_name(colum1 int, colum2) values(value1 1,2,3,value2) --declare @i int--定义变量的关键字,在同一个作用域是不能重复的 /*select * from student insert student(stu_

--use School
--insert 往表里插入数据
--insert table_name(colum1 int, colum2) values(value1 1,2,3,value2)
--declare @i int--定义变量的关键字,在同一个作用域是不能重复的
/*select * from student
insert student(stu_no,stu_name,class_id,sex,liking)values(3,‘王五‘,1,‘男‘,‘篮球‘)
--加字段
alter table student
add liking varchar(8) constraint uq_liking unique(liking) */
declare @i int
select @i=6
--go--标识 go 上下属于不同代码区 把上下的代码分开
--变量 是临时保存数据用的 是在本代码块通过declare来定义,通过select来赋值的。
--insert student select @i,‘赵六‘,1,‘女‘,‘羽毛球‘
insert student values (@i,‘田七‘,1,‘男‘,‘‘)
--select
--select 用来对变量来赋值
--是查询数据关键
--select 的语法
--select colum1,column2 from table_name where tiaojian1 and/or tiaojian2
select * from student where liking =null or stu_no=2--null不能用等号判断,要用 is
select * from student where liking is null or stu_no=2
--liking 字段 如何是null 或者是‘‘
select * from student where isnull(liking,‘‘)=‘‘ --isnull(参数1,参数2),判断参数1是否为NULL,如果是,返回参数2,否则返回参数1。
select stu_no,liking, cast(‘‘ as varchar(200))as decration into liking1 from student--新建一个liking1的表,要用的student表中的的字段和数据,‘‘表示liking1中新增的列的数据内容,并且以为括号外的as后的decration命名字段名。
select * from liking
select stu_no,liking, cast(‘12‘ as varchar(200))as decration into liking4 from student
cast() 函数用法
Cast(字段名 as 转换的类型 ),如 select *,cast(stu_no as date) as stu_no from student 是查询时希望把stu_no转换为date类型
其中类型可以为:
CHAR[(N)] 字符型
DATE 日期型
DATETIME 日期和时间型
DECIMAL float型
SIGNED int
TIME 时间型

select *,cast(stu_no as date) as stu_no from studentselect * from liking4

网友评论