易截截图软件、单文件、免安装、纯绿色、仅160KB

动态sql语句基本语法

1 :普通SQL语句可以用Exec执行
      例:      Select * from tableName
                Exec('select * from tableName')
                Exec sp_executesql N'select * from tableName'    -- 请注意字符串前一定要加N
 
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
 
    错误:        declare @fname varchar(20)
                set @fname = 'FiledName'
                Select @fname from tableName              -- 错误,不会提示错误,但结果为固定值FiledName,并非所要。
    正确:      Exec('select ' + @fname + ' from tableName')     -- 请注意加号前后的单引号的边上加空格
 
    当然将字符串改成变量的形式也可
                declare @fname varchar(20)
                set @fname = 'FiledName' --设置字段名
 
                declare @s varchar(1000)
                set @s = 'select ' + @fname + ' from tableName'
                Exec(@s)                -- 成功
     


相关文档:

[收拢] 用sqlite 执行标准 sql 语法

http://www.umgr.com/blog/PostView.aspx?bpId=36294
 1. 执行sql语句
int sqlite3_exec(sqlite3*, const char *sql, sqlite3_callbacksql 语法
, void *,  char **errmsg );
这就是执行一条 sql 语句的函数。
第1个参数不再说了,是前面open函数得到的指针。说了是关键数据结构。
第2个参数const char ......

SQL SERVER 2005 数据库状态为“可疑”的解决方法

--MyDB为修复的数据名
USE MASTER
GO
SP_CONFIGURE 'ALLOW UPDATES',1 RECONFIGURE WITH OVERRIDE
GO
ALTER DATABASE MyDB SET EMERGENCY
GO
sp_dboption 'MyDB', 'single user', 'true'
GO
DBCC CHECKDB('MyDB','REPAIR_ALLOW_DATA_LOSS')
GO
ALTER DATABASE MyDB SET ONLINE
GO
sp_configure 'allow updates ......

SQL Table

Table-Naming Standards
Table-naming standards, as well as any standard within a business, are critical to
maintaining control. After studying the tables and data in the previous sections, you
probably noticed that each table’s suffix is _TBL. This is a naming standard selected
for use, suc ......

大数据量下快速获取 SQL Server 数据库表记录数的方法

在数据库应用的设计中,我们往往会需要获取某些表的记录总数,用于判断表的记录总数是否过大,是否需要备份数据等。我们通常的做法是:select count(*) as c from tableA 。然而对于记录数巨大的表,上述做法将会非常耗时。在DELL 4400 服务器上做试验,MS Sqlserver 2000 数据库对于100万记录的简单数据表执行上述语句,时 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号