我在SQL Server 2005中有以下测试表:
CREATE TABLE [dbo].[TestTable]
(
[ID] [int] NOT NULL,
[TestField] [varchar](100) NOT NULL
)
Run Code Online (Sandbox Code Playgroud)
填充:
INSERT INTO TestTable (ID, TestField) VALUES (1, 'A value'); -- Len = 7
INSERT INTO TestTable (ID, TestField) VALUES (2, 'Another value '); -- Len = 13 + 6 spaces
Run Code Online (Sandbox Code Playgroud)
当我尝试使用SQL Server LEN()函数找到TestField的长度时,它不计算尾随空格 - 例如:
-- Note: Also results the grid view of TestField do not show trailing spaces (SQL Server 2005).
SELECT
ID,
TestField,
LEN(TestField) As LenOfTestField, -- Does not include trailing …Run Code Online (Sandbox Code Playgroud) 我在访问SQL Server中的存储过程时遇到错误
Server Error in '/' Application.
Procedure or function 'ColumnSeek' expects parameter '@template', which was not supplied.
Run Code Online (Sandbox Code Playgroud)
当我通过.net的数据连接调用带有参数的存储过程时(System.data.SqlClient),即使我提供了参数,也会发生这种情况.这是我的代码.
SqlConnection sqlConn = new SqlConnection(connPath);
sqlConn.Open();
//METADATA RETRIEVAL
string sqlCommString = "QCApp.dbo.ColumnSeek";
SqlCommand metaDataComm = new SqlCommand(sqlCommString, sqlConn);
metaDataComm.CommandType = CommandType.StoredProcedure;
SqlParameter sp = metaDataComm.Parameters.Add("@template",SqlDbType.VarChar,50);
sp.Value = Template;
SqlDataReader metadr = metaDataComm.ExecuteReader();
Run Code Online (Sandbox Code Playgroud)
我的存储过程是:
USE [QCApp]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ColumnSeek]
@template varchar(50)
AS
EXEC('SELECT Column_Name, Data_Type
FROM [QCApp].[INFORMATION_SCHEMA].[COLUMNS]
WHERE TABLE_NAME = ' …Run Code Online (Sandbox Code Playgroud) SQL Server 2005在我经常使用的系统目录上有很棒的sys.XXX视图.
让我失望的是:为什么有一个"sys.procedures"视图来查看有关存储过程的信息,但是没有"sys.functions"视图来查看存储函数的相同信息?
没有人使用存储的功能吗?我发现它们对于例如计算列等非常方便!
是否有一个特定的原因缺少sys.functions,或者它只是被认为不足以放入sys目录视图的东西?它在SQL Server 2008中可用吗?
干杯,马克
我正在SQL Server 2008中设计一个表,用于存储用户列表和Google Maps坐标(经度和纬度).
我需要两个字段,还是可以用1完成?
用于存储此类数据的最佳(或最常见)数据类型是什么?
如何强制我的数据库脱机,而不考虑已经使用的是什么或谁?
我试过了:
ALTER DATABASE database-name SET OFFLINE;
Run Code Online (Sandbox Code Playgroud)
但它在7分钟后仍然悬挂.
我想要这个,因为我需要测试场景.
如果可能的话?
我正在使用一个查询,其中包含"WHERE"子句中的"CASE"语句.但SQL Server 2008在执行时会出现一些错误.任何人都可以帮我正确的查询?这是查询:
SELECT
tl.storenum 'Store #',
co.ccnum 'FuelFirst Card #',
co.dtentered 'Date Entered',
CASE st.reasonid
WHEN 1 THEN 'Active'
WHEN 2 THEN 'Not Active'
WHEN 0 THEN st.ccstatustypename
ELSE 'Unknown'
END 'Status',
CASE st.ccstatustypename
WHEN 'Active' THEN ' '
WHEN 'Not Active' THEN ' '
ELSE st.ccstatustypename
END 'Reason',
UPPER(REPLACE(REPLACE(co.personentered,'RT\\\\',''),'RACETRAC\\\\','')) 'Person Entered',
co.comments 'Comments or Notes'
FROM
comments co
INNER JOIN cards cc ON co.ccnum=cc.ccnum
INNER JOIN customerinfo ci ON cc.customerinfoid=ci.customerinfoid
INNER JOIN ccstatustype st ON st.ccstatustypeid=cc.ccstatustypeid
INNER JOIN …Run Code Online (Sandbox Code Playgroud) 我想在表中插入新记录时获取新创建的ID.
我读到这个:http://msdn.microsoft.com/en-us/library/ms177564.aspx但它需要创建临时表.
我想在执行INSERT语句后返回ID(假设只执行一次INSERT).
例:
1 Joe Joe
2 Michael Mike
3 Zoe Zoe
Run Code Online (Sandbox Code Playgroud)
执行INSERT语句时,我想返回创建的ID,表示4.
可以告诉我如何使用SQL语句或不可能吗?
我重命名了几个实体及其导航属性,并在EF 5中生成了一个新的迁移.通常在EF迁移中重命名,默认情况下它会删除对象并重新创建它们.这不是我想要的,所以我几乎不得不从头开始构建迁移文件.
public override void Up()
{
DropForeignKey("dbo.ReportSectionGroups", "Report_Id", "dbo.Reports");
DropForeignKey("dbo.ReportSections", "Group_Id", "dbo.ReportSectionGroups");
DropForeignKey("dbo.Editables", "Section_Id", "dbo.ReportSections");
DropIndex("dbo.ReportSectionGroups", new[] { "Report_Id" });
DropIndex("dbo.ReportSections", new[] { "Group_Id" });
DropIndex("dbo.Editables", new[] { "Section_Id" });
RenameTable("dbo.ReportSections", "dbo.ReportPages");
RenameTable("dbo.ReportSectionGroups", "dbo.ReportSections");
RenameColumn("dbo.ReportPages", "Group_Id", "Section_Id");
AddForeignKey("dbo.ReportSections", "Report_Id", "dbo.Reports", "Id");
AddForeignKey("dbo.ReportPages", "Section_Id", "dbo.ReportSections", "Id");
AddForeignKey("dbo.Editables", "Page_Id", "dbo.ReportPages", "Id");
CreateIndex("dbo.ReportSections", "Report_Id");
CreateIndex("dbo.ReportPages", "Section_Id");
CreateIndex("dbo.Editables", "Page_Id");
}
public override void Down()
{
DropIndex("dbo.Editables", "Page_Id");
DropIndex("dbo.ReportPages", "Section_Id");
DropIndex("dbo.ReportSections", "Report_Id");
DropForeignKey("dbo.Editables", "Page_Id", "dbo.ReportPages");
DropForeignKey("dbo.ReportPages", "Section_Id", "dbo.ReportSections");
DropForeignKey("dbo.ReportSections", "Report_Id", "dbo.Reports");
RenameColumn("dbo.ReportPages", "Section_Id", "Group_Id"); …Run Code Online (Sandbox Code Playgroud) c# sql-server entity-framework ef-migrations entity-framework-5