SQL Server 2008 - Where子句AND OR

时间:2016-04-13 15:29:20

标签: sql-server-2008

(只读数据库)我有以下Where子句,这会减慢我的查询速度。是否有更有效的方式来写下我的内容? 另外,我如何仅在2016年撤回数据?使用OR语句?

<?php
//CREATE CONNECTION
$servername = "localhost";
$username = "root";
$password = "root";
$conn = new mysqli($servername, $username, $password);
// CHECK THE CONNECTION
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$dbname= "estate_agents";
$newConnection = new mysqli($servername, $username, $password,$dbname);
//CREATE PROPERTIES TABLE
$sql = "SELECT * FROM properties";
$resultSet = $conn->query($sql);
//to get the num rows, you have to mysqli_num_rows     
//you might want to create a function on your db class for num rows and return the count with return mysqli_num_rows($result);
 $rowcount=$conn->numRows($resultSet);
 // plz dont forget to create the function numRows on your class file

1 个答案:

答案 0 :(得分:0)

如果您无法更改架构以与ProcedureCode表具有多对多关系,则可以尝试在ProcedureCodexx表上创建索引:

CREATE NONCLUSTERED INDEX IX_B_ProcedureCode1
ON B (ProcedureCode1)
GO

CREATE NONCLUSTERED INDEX IX_B_ProcedureCode2
ON B (ProcedureCode1)
GO