테이블의 필드에 NOT NULL 속성이 있는지 확인하려면 두 가지 구문 중 하나를 사용할 수 있습니다. 첫 번째 구문은 다음과 같습니다 -
desc yourTableName;
다음은 두 번째 구문입니다 -
select column_name, is_nullable from information_schema.columns where table_schema = ‘yourDatabaseName’ and table_name = 'yourTableName’;
먼저 예제를 보고 테이블을 생성해 보겠습니다 -
mysql> create table DemoTable
(
StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
StudentName varchar(40),
StudentAge int NOT NULL,
IsActiveStudent ENUM('ACTIVE",INACTIVE') NOT NULL,
StudentCountryName varchar(40)
);
Query OK, 0 rows affected (1.53 sec) 첫 번째 구문은 테이블의 필드에 NOT NULL 속성이 설정되어 있는지 확인하는 다음과 같습니다. -
mysql> desc DemoTable;
이것은 다음과 같은 출력을 생성합니다 -
+--------------------+--------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------------------+------+-----+---------+----------------+
| StudentId | int(11) | NO | PRI | NULL | auto_increment |
| StudentName | varchar(40) | YES | | NULL | |
| StudentAge | int(11) | NO | | NULL | |
| IsActiveStudent | enum('ACTIVE",INACTIVE') | NO | | NULL | |
| StudentCountryName | varchar(40) | YES | | NULL | |
+--------------------+--------------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec) 두 번째 구문은 테이블의 필드에 NOT NULL 속성이 설정되어 있는지 확인하는 다음과 같습니다. -
mysql> select column_name, is_nullable from information_schema.columns where table_schema = 'web' and table_name = 'DemoTable';
이것은 다음과 같은 출력을 생성합니다 -
+--------------------+-------------+ | COLUMN_NAME | IS_NULLABLE | +--------------------+-------------+ | StudentId | NO | | StudentName | YES | | StudentAge | NO | | IsActiveStudent | NO | | StudentCountryName | YES | +--------------------+-------------+ 5 rows in set (0.00 sec)