t-sql语言go的作用的简单介绍( 二 )


GO
SELECT @@VERSION;
-- Yields an error: Must be EXEC sp_who if not first statement in
-- batch.
sp_who
GO
SQL Server applications can send multiple Transact-SQL statements to SQL Server for execution as a batch. The statements in the batch are then piled into a single execution plan. Programmers executing ad hoc statements in the SQL Server utilities, or building scripts of Transact-SQL statements to run through the SQL Server utilities, use GO to signal the end of a batch.
Applications based on the DB-Library, ODBC, or OLE DB APIs receive a syntax error if they attempt to execute a GO mand. The SQL Server utilities never send a GO mand to the server.
Permissions
GO is a utility mand that requires no permissions. It can be executed by any user.
Examples
This example creates o batches. The first batch contains only a USE pubs statement to set the database context. The remaining statements use a local variable, so all local variable declarations must be grouped in a single batch. This is done by not having a GO mand until after the last statement that references the variable.
USE pubs
GO
DECLARE @NmbrAuthors int
SELECT @NmbrAuthors = COUNT(*)
FROM authors
PRINT 'The number of authors as of ' +
CAST(GETDATE() AS char(20)) + ' is ' +
CAST(@NmbrAuthors AS char (10))
GO
sql 语句中(+)有什么作用
对于数值型别可以做加法运算,对于字元型资料用来做连线
sql语句中as的作用?
as 一般用在两个地方,一个是query的时候,用来重新指定返回的column 名字
如:一个table 有个column叫 id,我们的query是
select id from table1. 但是如果你不想叫id了,就可以重新命名 , 如叫 systemID 就可以这样写
select id as systemId from table1;
还有一个用法就是在create table 或 procedure 的时候,as 是个关键字 。
例如
create table test as select * from table1
这时候就会create 一个table test,t-sql语言go的作用他是完全copy table table1里的全部资料 。
create procdure name as (is)
begin
end;
具体可以参考 如何建立procedure 。这个时候 as 和is可以互换 。
那是别名 比如 name as 姓名这样的话,查询出来的列就是 写 姓名
sql语句中having的作用是?
1,对由sum或其它集合函式运算结果的输出进行限制 。
2,我们就需要使用HAVING从句 。语法格式为:
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithematic function condition)
(GROUP BY从句可选) ,
3,由此,我们可以使用如下命令实现上述查询目的:
SELECT store_name, SUM(sales)
FROM Store_Information
GROUP BY store_name
HAVING SUM(sales)1500
4,查询结果显示为:
store_name SUM(Sales)
Los Angeles $1800
having 用法与WHERE用法类似,但有三点不同
1、HAVING只用于GROUP BY(分组统计语句),
2、WHERE 是用于在初始表中筛选查询,HAVING用于在WHERE和GROUP BY 结果中查询 。
3、HAVING可以使用聚合函式,面WHERE 不能 。
下面的语句统计使用者表中姓名为“李”(WHERE子句定义),出现多于一次(having 用聚合函式COUNT(1)定义)的人的使用者
SELECT USERCODE,username=max(username),次数=count(1) from usertable where username like '李%' group by usercode having count(1)1
4,这个是用在聚合函式的用法 。当我们在用聚合函式的时候 , 一般都要用到GROUP BY 先进行分组,然后再进行聚合函式的运算 。运算完后就要用到HAVING 的用法了,就是进行判断了 。
SQL语句中INT FOREIGN KEY REFERENCES作用是什么
外来键
oracle sql语句中的 # 有什么用

推荐阅读