php - 如何从 SQL 数据库中删除记录
问题描述
我有这两个变量:一个存储表中的内容,第二个存储数据库中的查询。我也在做一个比较,看看 2 变量与 $ diff 之间是否存在差异。这是我的代码:
public function destroy()
{
$indexes = DB::connection('sqlsrv2')->select("select * from indexes");
$dbIndexes = DB::connection('sqlsrv')->select
("
select
schema_name(t.[schema_id]) + '.' + t.[name] as table_view,
substring(column_names, 1, len(column_names)-1) as [columns],
case when i.is_primary_key = 1 then 'Primary_key'
when i.is_unique = 1 then 'Unique'
else 'Not_unique' end as [type],
i.[name] as index_name,
i.index_id
from sys.objects t
inner join sys.indexes i
on t.[object_id] = i.[object_id]
cross apply
(
select col.[name] + ', '
from sys.index_columns ic
inner join sys.columns col on ic.[object_id] = col.[object_id] and ic.column_id = col.column_id
where ic.[object_id] = t.[object_id]
and ic.index_id = i.index_id
order by col.column_id
for xml path ('')
) D (column_names)
where t.is_ms_shipped <> 1
and index_id > 0
");
$indexes = array_map('serialize', $indexes);
$dbIndexes = array_map('serialize', $dbIndexes);
$diff = array_merge(array_diff($indexes,$dbIndexes),array_diff($dbIndexes,$indexes));
dd($diff);
}
如何从 $indexes 中删除 diff 的结果?
解决方案
推荐阅读
- php - 从嵌套关联数组中获取单个值
- javascript - JavaScript Moment.js 试图获得 2 个日期时间之间的差异
- r - 如何计算 R quosure 中的变量数?
- python - 我的代码在运行时会打印它之前的输出。我希望它只打印该特定计数所需的内容
- html - 为什么 table-layout: fixed 会影响父元素的宽度?
- html - 通过调用css中的类来更改父级中子级的字体颜色和高度
- c++ - 如何将使用 ExternalProject_Add 安装的库添加到目标包括
- sql - 时区 Rails Postgres
- java - 带有 DBRef 的 Mongo 文档
- ruby - 如何从 BasicObject 中访问 Ruby 类型名称