索引仅在LIKE运算中使用的varchar列是一个好主意吗?从我从查询分析中可以读到的内容我得到以下查询:
SELECT * FROM ClientUsers WHERE Email LIKE '%niels@bosmainter%'
Run Code Online (Sandbox Code Playgroud)
我得到的"估计子树成本"为0.38,没有任何索引,0.14有索引.如果使用索引优化了查询,这是一个用于anlayzing的好指标吗?
我试图制作一个方法,从我的字典中随机返回一个名片.
我的词典:第一个定义卡的名称是字符串,第二个是该卡的值,即int.
public static Dictionary<string, int> _dict = new Dictionary<string, int>()
{
{"7", 7 },
{"8", 8 },
{"9", 9 },
{"10", 10 },
{"J", 1 },
{"Q", 1 },
{"K", 2 },
{"A", 11 }
};
Run Code Online (Sandbox Code Playgroud)
方法:随机随机生成int.
public string getCard(int random)
{
return Karta._dict(random);
}
Run Code Online (Sandbox Code Playgroud)
所以问题是:
public static Dictionary<string, int> _dict = new Dictionary<string, int>()
{
{"7", 7 },
{"8", 8 },
{"9", 9 },
{"10", 10 },
{"J", 1 },
{"Q", 1 },
{"K", 2 },
{"A", 11 …Run Code Online (Sandbox Code Playgroud) 我的表中有一个bigint(ProductSerial)类型的列.我需要使用like运算符通过Product serial过滤表.但我发现,像运算符一样不能用于整数类型.
有没有其他方法(我不想使用=运算符).
我已经看到很多关于在Sql查询和"喜欢"中使用参数的问题,但是我已经尝试过各种方式来编写代码并且仍然无法获得我的查询来给出结果.如果我在查询本身中放置一个值,它运行正常.当我运行列出的第一个查询时,我得到错误"必须声明标量变量"@Search"但我认为我使用cmd.Parameters.AddWithValue语句做了.有人能看到我可能做错了吗?任何帮助表示赞赏.
//Declare the connection object
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;
//Connect to the db
Conn.Open();
//Define query
//This query doesn't work
string sql = "SELECT CustomerID, LastName, FirstName, Email, Password, Address1, Address2, City, State, Zip, Phone, Fax FROM Customer WHERE (State LIKE '%' + @Search + '%')";
//This query doesn't work either
string sql = "SELECT CustomerID, LastName, FirstName, Email, Password, Address1, Address2, City, State, Zip, Phone, Fax FROM Customer WHERE State LIKE @Search";
//This query works …Run Code Online (Sandbox Code Playgroud)