সিনট্যাক্স
COLUMN_KEY='PRI' প্রাইমারি কি কলাম নির্দেশ করে। CASE এক্সপ্রেশন দিয়ে কাস্টম মেসেজ:
select column_name, case when column_key='PRI' then 'This is a Primary key Column' else 'This is not a Primary key Column' end as Output from information_schema.columns where table_schema=database() and `table_name`='yourTableName' order by `table_name`, ordinal_position;
টেবিল তৈরি (Id প্রাইমারি কি)
mysql> create table DemoTable1886 ( Id int NOT NULL, FirstName varchar(20), LastName varchar(20), Age int, DateOfBirth datetime, Education varchar(40), PRIMARY KEY(Id) ); Query OK, 0 rows affected (0.00 sec)
প্রাইমারি কি কলাম যাচাই
mysql> select column_name, case when column_key='PRI' then 'This is a Primary key Column' else 'This is not a Primary key Column' end as Output from information_schema.columns where table_schema=database() and `table_name`='DemoTable1886' order by `table_name`, ordinal_position;
+-------------+--------------------------------+ | COLUMN_NAME | Output | +-------------+--------------------------------+ | Id | This is a Primary key Column | | FirstName | This is not a Primary key Column| | LastName | This is not a Primary key Column| | Age | This is not a Primary key Column| | DateOfBirth | This is not a Primary key Column| | Education | This is not a Primary key Column| +-------------+--------------------------------+ 6 rows in set (0.00 sec)
ব্যাখ্যা: INFORMATION_SCHEMA.COLUMNS মেটাডেটা টেবিলে COLUMN_KEY কলামে 'PRI' (Primary), 'UNI' (Unique), 'MUL' (Non-unique index) বা খালি মান থাকে। এটি ডাইনামিক SQL বা স্কিমা ইন্সপেকশন টুল তৈরির জন্য কার্যকর।