程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 檢查數據庫數據字段命名規范與合法性的腳本

檢查數據庫數據字段命名規范與合法性的腳本

編輯:關於SqlServer

--檢查不符合數據庫命名規范的字段名

Select TABLE_NAME,COLUMN_NAME,DATA_TYPE
From user_tab_columns
Where column_name In --(Select keyword From v$reserved_words)
('ACCESS','ADD','ALL','ALTER','AND','ANY','AS','ASC','AUDIT',
'BETWEEN','BY','CHAR','CHECK','CLUSTER',
'COLUMN','COMMENT','COMPRESS','CONNECT','CREATE','CURRENT',
'DATE','DECIMAL','DEFAULT','DELETE',
'DESC','DISTINCT','DROP','ELSE','EXCLUSIVE','EXISTS','FILE',
'FLOAT','FOR','FROM','GRANT','GROUP',
'HAVING','IDENTIFIED','IMMEDIATE','IN','INCREMENT','INDEX',
'INITIAL','INSERT','INTEGER','INTERSECT',
'INTO','IS','LEVEL','LIKE','LOCK','LONG','MAXEXTENTS','MINUS',
'MLSLABEL','MODE','MODIFY','NOAUDIT',
'NOCOMPRESS','NOT','NOWAIT','NULL','NUMBER','OF','OFFLINE','ON',
'ONLINE','OPTION','OR','ORDER',
'PCTFREE','PRIOR','PRIVILEGES','PUBLIC','RAW','RENAME','RESOURCE',
'REVOKE','ROW','ROWID','ROWNUM',
'ROWS','SELECT','SESSION','SET','SHARE','SIZE','SMALLINT','START',
'SUCCESSFUL','SYNONYM','SYSDATE',
'TABLE','THEN','TO','TRIGGER','UID','UNION','UNIQUE','UPDATE',
'USER','VALIDATE','valueS','VARCHAR',
'VARCHAR2','VIEW','WHENEVER','WHERE','WITH')
Or column_name Like '% %'

--檢查數據庫中相同名字不同類型的字段名

select a.column_name,a.data_type,b.data_type From
(select distinct column_name,data_type from
all_tab_columns Where TABLE_NAME Like 'T%') a,
(select distinct column_name,data_type from
all_tab_columns Where TABLE_NAME Like 'T%') b
where a.column_name=b.column_name and a.data_type<>b.data_type

--檢查數據庫中相同名字相同類型不同長度的字段名

select a.column_name,a.data_type,b.data_type,
a.data_length,b.data_length From
(select distinct column_name,data_type,
data_length from all_tab_columns Where TABLE_NAME Like 'T%') a,
(select distinct column_name,data_type,
data_length from all_tab_columns Where TABLE_NAME Like 'T%') b
where a.column_name=b.column_name and a.data_type=b.data_type And A.DATA_LENGTH<>B.DATA_LENGTH

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved