❶ 分析如下T-SQL语句,说出查询结果是什么。
--sql中[]通配符
--[]与特定范围(例如,[a-f])或特定集(例如,[abcdef])中的任意单字符匹配。
--你上面的句子相当于
select*fromproctwhereProctNamelike'草鱼'orProctNamelike'鲶鱼'
❷ 3、阅读下述T-SQL函数编程,写出正确的程序运行结果
搞脑子的事,但不难
-----------------------
3.1429
R201SREVRESLQS
20年
❸ 如何用T-SQL判断SQL语法是否正确
T-SQL是sqlserver的标准语法,一般在SQL Server Management Studio中执行T-SQL语句时,如果不正确,会直接报错。
如以下代码(求1到100累加的和):
DECLARE@iINT,@sumINTSET@i=1SET@sum=0WHILE@i<=100BEGINSET@sum=@sum+@iSET@i=@i+1ENDPRINT@sum
此代码是正确的,最后的输出结果如下:
❹ T-SQL查询结果
我修改过了
top 和distinct写反了
select distinct top 1 f.Fid as '编号', c.fcontent as '栏目名称',
f.fqyid as '发帖人公司id', e.FNickName as 发帖人,
f.ftitle as '帖子主题', f.fcontent as '帖子内容', f.fdate as '发帖时间',
f.fbrowse as '帖子点击数', f.freply as '帖子回帖数',
fr.fqyid as '回帖人公司id', e1.FNickName as 回帖人,
fr.ftitle as '回复标题', fr.fcontent as '回帖内容', fr.fdate as '回帖时间'
from Bill_Forum f
left outer join Bill_Column c
on f.fcolumnid = c.fid
left outer join Bill_ForumReply fr
on f.fcolumnid = fr.fforumid
left outer join Bill_Employee e
on f.Fcardid = e.Fcardid
left outer join Bill_Employee e1
on fr.Fcardid = e1.Fcardid
order by fr.frdate desc
❺ 关于t-sql编程问题:如何用游标查询数据后排序,然后下一行的读数为上一行读数加上11,为何程序运行老是有
CREATE TABLE tiji (
id INT IDENTITY(1, 1) PRIMARY KEY,
dttm datetime,
v700 INT
);
go
-- 我只造5条的测试数据.
INSERT INTO tiji
SELECT '2011-4-1 00:00:00' , 612627 UNION ALL
SELECT '2011-4-2 00:00:00' , 612627 UNION ALL
SELECT '2011-4-3 00:00:00' , 612627 UNION ALL
SELECT '2011-4-4 00:00:00' , 612627 UNION ALL
SELECT '2011-4-5 00:00:00' , 612627;
go
BEGIN
declare cur cursor for
select dttm,v700
from tiji
where dttm>'2011-4-1 00:00:00'
and dttm <'2011-4-20 18:00:00' order by dttm
FOR UPDATE OF v700;
declare @v700 int;
set @v700 =612627
open cur
fetch next from cur
while @@fetch_status = 0
begin
update tiji
set v700=@v700+11
where current of cur;
set @v700= @v700+11
fetch next from cur
end
close cur
deallocate cur
END
go
执行结果与 核对数据
dttm v700
----------------------- -----------
2011-04-02 00:00:00.000 612627
(1 行受影响)
dttm v700
----------------------- -----------
2011-04-03 00:00:00.000 612627
(1 行受影响)
dttm v700
----------------------- -----------
2011-04-04 00:00:00.000 612627
(1 行受影响)
dttm v700
----------------------- -----------
2011-04-05 00:00:00.000 612627
(1 行受影响)
dttm v700
----------------------- -----------
(0 行受影响)
1> select * from tiji;
2> go
id dttm v700
----------- ----------------------- -----------
1 2011-04-01 00:00:00.000 612627
2 2011-04-02 00:00:00.000 612638
3 2011-04-03 00:00:00.000 612649
4 2011-04-04 00:00:00.000 612660
5 2011-04-05 00:00:00.000 612671
(5 行受影响)
❻ t-sql 语句分析:select DIFFERENCE('nmyth','smyth'),执行结果为3,不知道这个difference的用法
DIFFERENCE
以整数返回两个字符表达式的 SOUNDEX 值之差。
语法
DIFFERENCE ( character_expression , character_expression )
参数
character_expression
是类型 char 或 varchar 的表达式。
返回类型
int
注释
返回的整数是 SOUNDEX 值中相同字符的个数。返回的值从 0 到 4 不等,4 表示 SOUNDEX 值相同。
示例
在下例的第一部分,比较两个相差很小的字符串的 SOUNDEX 值,DIFFERENCE 返回的值是 4。在下例的第二部分,比较两个相差很大的字符串的 SOUNDEX 值,DIFFERENCE 返回的值是 0。
USE pubs
GO
-- Returns a DIFFERENCE value of 4, the least possible difference.
SELECT SOUNDEX('Green'),
SOUNDEX('Greene'), DIFFERENCE('Green','Greene')
GO
-- Returns a DIFFERENCE value of 0, the highest possible difference.
SELECT SOUNDEX('Blotchet-Halls'),
SOUNDEX('Greene'), DIFFERENCE('Blotchet-Halls', 'Greene')
GO
下面是结果集:
----- ----- -----------
G650 G650 4
(1 row(s) affected)
----- ----- -----------
B432 G650 0
(1 row(s) affected)
SOUNDEX
返回由四个字符组成的代码 (SOUNDEX) 以评估两个字符串的相似性。
语法
SOUNDEX ( character_expression )
参数
character_expression
是字符数据的字母数字表达式。character_expression 可以是常数、变量或列。
返回类型
char
注释
SOUNDEX 将 alpha 字符串转换成由四个字符组成的代码,以查找相似的词或名称。代码的第一个字符是 character_expression 的第一个字符,代码的第二个字符到第四个字符是数字。将忽略 character_expression 中的元音,除非它们是字符串的第一个字母。可以嵌套字符串函数。
示例
下例显示 SOUNDEX 函数及相关的 DIFFERENCE 函数。在第一个示例中,返回所有辅音字母的标准 SOUNDEX 值。为 Smith 和 Smythe 返回的 SOUNDEX 结果相同,因为不包括所有元音、字母 y、连写字母和字母 h。
-- Using SOUNDEX
SELECT SOUNDEX ('Smith'), SOUNDEX ('Smythe')
下面是结果集:
----- -----
S530 S530
(1 row(s) affected)
DIFFERENCE 函数比较 SOUNDEX 模式结果的差。第一个示例显示两个仅元音不同的字符串。返回的差是 4(可能的最小差)。
-- Using DIFFERENCE
SELECT DIFFERENCE('Smithers', 'Smythers')
GO
下面是结果集:
-----------
4
(1 row(s) affected)
在下例中,字符串的辅音不同,所以返回的差是 2(较高的差)。
SELECT DIFFERENCE('Anothers', 'Brothers')
GO
下面是结果集:
-----------
2
(1 row(s) affected)
字符串函数
❼ 数据库实验要SQL语言编写的
-- Create table
create table Student
(
S_No varchar2(20),
S_Name varchar2(20) not null,
S_Sex varchar2(2) default '男',
S_Birthday date
)
;
-- Add comments to the table
comment on table Student
is '学生';
-- Create/Recreate primary, unique and foreign key constraints
alter table Student
add constraint Pri_S_No primary key (S_NO);
-- Create table
create table Course
(
C_No varchar2(20),
C_Name varchar2(40),
Grade number(4,1)
)
;
-- Add comments to the table
comment on table Course
is '课程';
-- Add comments to the columns
comment on column Course.Grade
is '分数';
-- Create/Recreate primary, unique and foreign key constraints
alter table Course
add constraint Pri_C_No primary key (C_NO);
-- Create table
create table T_Course
(
S_no varchar2(20),
C_no varchar2(20),
Grade number(4,1)
)
;
-- Add comments to the table
comment on table T_Course
is 'take the course选课信息';
-- Add comments to the columns
comment on column T_Course.Grade
is '成绩';
-- Create/Recreate primary, unique and foreign key constraints
alter table MEA.T_Course
add constraint For_S_No foreign key (S_NO)
references Student (S_No);
alter table MEA.T_Course
add constraint For_C_No foreign key (C_NO)
references Course (C_No);
3:
-- Add/modify columns
alter table Student add S_Tel varchar2(20);
-- Add comments to the columns
comment on column Student .S_Tel
is '电话';
4:
-- Add/modify columns
alter table Course modify C_Name CVARCHAR2(20);
5:
INSERT INTO Student (S_No, S_Name,S_Sex, S_Birthday ) VALUES ('A001','日月哥','女',to_date('20110515','yyyyMMdd'))
其他你自己来
6:
update Course set Grade =Grade +1
7:
-- Create/Recreate indexes
create unique index PK_oo on Student(S_Birthday order by desc);
8:
select s.S_No, avg(tc.Grade) from Student s,T_Course tc where s.S_No=tc.S_No group by s.S_No
9:
delete T_Course tc where tc.S_No='A000';
delete Student s where s.S_No='A000';
思考题自己来,我用的orcal,这都不给分的话,爆你菊花啦
❽ 数据库 T-SQL编程
SELECTName
,CASE
WHENincome-outcome<3000THEN'收入不高于3000'
ELSECAST(income-outcomeASVarChar(20))
ENDAS收入
FROMEmployeesE,SalaryS
WHEREE.Employeeid=S.Employeeid
ANDE.name='王林'
❾ ”T—sql语句运行结果为影响的行数为一行“啥意思
指的就是语句在set nocount off时,语句执行后影响的行数。
不管是使用select 还是update,还是insert,对于结果只有一条记录时,就是影响了一行记录,有时称受影响或是影响结果的行数为一行。一般在执行后都会出现这个消息(SQL中默认会显示语句执行后受影响的行数),如果是关闭后,则不会收到这样的消息。
❿ 高分求解T-SQL编程——在线等
DECLARE @Count int /*定义一个记数*/
SET @Count= (SELECT 图书数量 FROM 表) /*取初始记录数*/
WHILE @Count<=300
BEGIN
PRINT '修改之前, 共'+CONVERT(nvarchar(20), @Count) +'个记录'
IF @Count>200
BEGIN
UPDATE 表 SET 图书数量=图书数量+30
SET @Count=@Count+30
END
ELSE IF @Count>100
BEGIN
UPDATE 表 SET 图书数量=图书数量+50
SET @Count=@Count+50
END
ELSE IF @Count>0
BEGIN
UPDATE 表 SET 图书数量=图书数量+100
SET @Count=@Count+100
END
PRINT '修改之后, 共'+CONVERT(nvarchar(20), @Count) +'个记录'
END