2011-02-13 3 views

답변

12
SHOW INDEXES FROM TABLE WHERE Key_name = 'PRIMARY' 
+0

는 IF에서 이것을 사용하는 방법이 있나요? 그 인덱스가 존재하는 경우 나는 인덱스를 생성하기 위해 alter를 실행하지 않는다. – realtebo

2
SELECT EXISTS(
    SELECT 1 
    FROM information_schema.columns 
    WHERE table_schema = 'db' 
    and table_name='table name' 
    and column_key = 'PRI' 
) As HasPrimaryKey 
관련 문제