SQL 系統型別及處理

2022-09-15 07:21:14 字數 2674 閱讀 2251

sys.all_objects 顯示所有架構範圍內的使用者定義物件和系統物件的 union。所有的系統物件都可以從這裡看到。

select * from sys.objects

select * from sys.all_objects

刪表:

if exitst (select * from sys.objects where name in ('test') and type='u' and type_desc='user_table')

drop table table_name

go刪儲存過程:

if exitst (select * from sys.objects where name in ('proc_name') and type='p' and type_desc='sql_stored_procedure')

drop table proc_name

gotype

type_desc

說明

afaggregate_function

聚合函式(clr)

c check_constraint

check 約束

d default_constraint

default(約束或獨立)

f foreign_key_constraint

外來鍵約束

fcclr_scalar_function

程式集 (clr) 標量函式

fnsql_scalar_function

sql 標量函式

ftclr_table_valued_function

程式集 (clr) 錶值函式

ifsql_inline_table_valued_function

sql 內聯錶值函式

itinternal_table

內部表 p 

sql_stored_procedure

sql 儲存過程

pcclr_stored_procedure

程式集 (clr) 儲存過程

pkprimary_key_constraint

主鍵約束

s system_table

系統基表

sqservice_queue

服務佇列

tfsql_table_valued_function

sql 錶值函式

trsql_trigger

sql 觸發器

u user_table

使用者表 uq

unique_constraint

unique 約束

v view

檢視 x 

extended_stored_procedure

擴充套件儲存過程

--判斷指定的資料庫是否存在,存在則刪除

if exists (select name from master..sysdatabases where name in ('db_name'))

drop database db_name

if exists (select * from sys.sysdatabases where name in ('db_name')

drop database db_name

--判斷指定的儲存過程是否存在,存在則刪除

if exists (select * from sysobjects where objectproperty(object_id('proc_name'), 'isprocedure')=1)

drop procedure proc_name

if exists (select * from sys.procedures where name in ('proc_name')

drop procedure proc_name

--判斷指定的表是否存在,存在則刪除

if exists (select * from sysobjects where objectproperty(object_id('table_name'),'istable')=1)

drop table table_name

if exists (select * from sys.tables where name like 'table_name')

drop table table_name

--判斷指定的自定義函式是否存在,存在則刪除

if exists (select * from sysobjects where objectproperty(object_id('dbo.func_name'), 'isansinullson')=1)

drop function dbo.func_name

--判斷指定的臨時表是否存在,存在則刪除

if exists (select * from tempdb..sysobjects where name like '#table_name%')

drop table #table_name

--判斷指定的檢視是否存在,存在則刪除

if exists (select * from sys.views where name like 'view_name')

drop view view_name

SQL 語句型別以及處理

1 dml 包含select delete insert replace update 2 ddl 包含create update delete 3 tcl 事務控制語句 包含start transaction commit rollback end transaction 4 dcl 包含crea...

js 錯誤型別及處理

error 其他錯誤型別都繼承自該型別,用於自定義錯誤 evalerror 在使用 eval 函式而發生異常時丟擲的錯誤 rangeerror 會在數值超出相應範圍時觸發 referenceerror 在訪問不存在的變數時,會發生這種錯誤 syntaxerror 將錯誤的 js 語法傳給 eval ...

資料型別及處理

資料型別包括內建型別和自定義型別。內建型別包含基本型別和復合型別。自定義型別包含使用者自定義型別和標準庫中定義的型別。基本型別包含算術型別和空型別。算術型別包含整值型別和浮點型。整值型別包含字元型別,布林型別和整數型別。復合型別包含指標,引用,陣列,陣列,列舉,結構體,共用體。算術型別 c 算術型別...