INSERT语法使用技巧一例
Jun 07, 2016 pm 03:08 PM在SQL Server在线图书(SSBOL)中,请定位sp_dbcmptlevel,然后找出描述6.0、6.5和7.0之间版本兼容性的数据表 。你可以注意到INSERT SQL语句有如下所示的 语法 。 INSERT X SELECT select_list INTO Y 早期的SQL Server数据库(6.0或者6.5版本)可以正确地解
在SQL Server在线图书(SSBOL)中,请定位sp_dbcmptlevel,然后找出描述6.0、6.5和7.0之间版本兼容性的数据表
。你可以注意到INSERT SQL语句有如下所示的语法。
INSERT X
SELECT select_list INTO Y
早期的SQL Server数据库(6.0或者6.5版本)可以正确地解析这样的语句,但新的SQL Server数据库(7.0 或者8.0版本)就不能正确解析了。虽然语法中的Y 在任何兼容级设置下都不用做插入操作的接收者,但旧的数据库还允许这样的语法存在。这种语法在新的数据库中都因其更严格的语法检查而无法执行,然而,这种"严格要求"却让用户编写的代码更具稳固性。
以下是一个可以在SQL Server 7.0 或者2000上运行的简单脚本,该脚本说明了以上的语法如何通过旧数据库的测试但却不能通过新数据库的检查。
SET NOCOUNT OFF
GO
USE pubs
GO
IF EXISTS (SELECT * FROM sysobjects WHERE type =
'U' AND name = 'test')
BEGIN
DROP TABLE test
END
GO
CREATE TABLE test (col1 INT NULL, col2 INT NULL)
GO
EXEC sp_dbcmptlevel pubs, 65
GO
INSERT test
SELECT 1 ,1 INTO y
GO 862398.com
EXEC sp_dbcmptlevel pubs, 70
GO
INSERT test
SELECT 2 ,1 INTO y
GO

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is the difference between HQL and SQL in Hibernate framework?

Usage of division operation in Oracle SQL

What does the identity attribute in SQL mean?

Comparison and differences of SQL syntax between Oracle and DB2

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags

How to install, uninstall, and reset Windows server backup

Database technology competition: What are the differences between Oracle and SQL?
