-- 1、查詢沒有主鍵的表、沒有索引的表
select so.name as '沒有主鍵的表'
from sysobjects so
where so.xtype = 'u'
and objectproperty(so.id , 'tablehasprimarykey' ) = 0
order by name
select so.name as '沒有索引的表'
from sysobjects so
where so.xtype = 'u'
and objectproperty(so.id , 'tablehasindex' ) = 0
order by name
--2、檢視資料庫使用者表使用了哪些資料型別
select d.* , b.[name] as '資料型別' from ( select distinct a.xusertype from syscolumns as a where a.id in
(select id from sysobjects where xtype='u' and status>0 ) )as d left join systypes as b
on d.xusertype=b.xusertype
--3、看使用nvarchar型別的使用者表名和欄位名稱 xusertype 具體數值看當前資料庫中系統表systypes中的記錄
select sc.name as '欄位名稱' , so.name as '表名' from syscolumns sc inner join
sysobjects so on sc.id=so.id where sc.id in
( select id from sysobjects where xtype='u' and status>0 )
and sc.xusertype=231 order by so.name ,sc.colid
--4、檢視資料庫中使用外來鍵和被引用的表
select so1.name as '外來鍵表', so2.name as '引用表', sc1.name as '外來鍵字段',
sc2.name as '引用字段'
from sysforeignkeys sf inner join
sysobjects so1 on sf.fkeyid = so1.id inner join
sysobjects so2 on sf.rkeyid = so2.id inner join
syscolumns sc1 on sf.fkeyid = sc1.id and sf.fkey = sc1.colid inner join
syscolumns sc2 on sf.rkeyid = sc2.id and sf.rkey = sc2.colid
列出沒有主鍵或唯一索引的表
以下指令碼可以用於列出資料庫中沒有主鍵的表,已排除了系統schema select owner,table name from dba tables where 1 1 and owner not in sys system sysman exfsys wmsys olapsys outln dbs...
Sql Server 刪除表中沒有主鍵的重複資料
資料庫中的資料在很多情況下是從excel中匯入的,這就難免有些重複的資料,然而這些資料又沒有主鍵,那麼該如何去重呢?有一張資料如下的表 嘗試了很多方法,覺得有一種比較實用,步驟比較簡單 用distinct關鍵字查詢出不重複的資料後,將資料寫入虛擬表中,刪除原表,讀取虛擬表資料,寫回原表,請看 sel...
EF插入遇到的問題 表沒有主鍵時
解決方法一 看表是否有主鍵,一般就是表缺主鍵 解決方法二 若專案表都沒主鍵,把 edmx檔案裡面 包含 的語句刪除即可 很費時 當使用沒有主鍵的表完成ef對映時,會將其視為檢視。由於檢視是邏輯實體,因此無法更新。因此,要麼將丟失的主鍵新增到表中,要麼將它們視為檢視,並且不對它們執行任何更新操作。如果...