MySQL Create Table In Hindi

📔 : MySQL 🔗

पिछले topic में हमने Database को create और drop करना दिखा इस topic में हम database में tables को create करना सीखेंगे।

जैसा कि आपको पता है कि tables को किसी न किसी database में ही create करते हैं , तो जल्दी से सबसे पहले database create कर लेते हैं।

Create Database

CREATE DATABASE tutorials;

ऊपर दी गयी command जब आप run करेंगे तो उसका output कुछ इस तरह से होगा।

Query OK, 1 row affected (0.001 sec)

Switch Database

OK , तो हमारा database तो create हो गया है अब हमें उस database में काम करने के लिए database को switch करना पड़ेगा।

switch करने का मतलब है एक तरह से database को select करना फिर जो भी हम table create या data insert करेंगे वो इस database में होगा।

USE tutorials;

Output

Database changed

Finally database switch हो गया है , अब हम इसी database में एक customers name की table create करेंगे।

table create करने से पहले मई आपको MySQL Data Types पढने के लिए recommend करूंगा।

MySQL Create Table

CREATE TABLE customers ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50) NOT NULL, email VARCHAR(50) NOT NULL, mobileno VARCHAR(20), address VARCHAR(100) );

query का output कुछ इस तरह से होगा।

Query OK, 0 rows affected (0.066 sec)

query , Ok है मतलब हमारी table create हो गयी है। आगे बढ़ने से पहले ये समझ लेते हैं कि table में किया क्या है।

customers table में कुल 5 columns हैं -

  • id : इसका type int है , जो PRIMARY KEY है। हर table में एक primary key होनी चाहिए जिससे records को easily manage कर सकें और एक table में maximum एक ही primary key होती है। AUTO_INCREMENT है मतलब आपको इसकी value manually enter नहीं करनी पड़ेगी। जब आप कोई नया record insert करोगे तो automatically इसकी value fill हो जायगी।

  • name : इस column का type VARCHAR(50) है , मतलब insert की जाने वाली value string होगी जिसकी maximum length 50 तक हो सकती है। NOT NULL है मतलब column value mandatory है। record insert करते time इसकी value आपको देनी ही पड़ेगी।

  • email : name column की तरह ही email column का type VARCHAR है और length 50 है।

  • mobileno : इस column का भी type VARCHAR है लेकिन maximum length 20 है , मतलब 20 से ज्यादा character हम enter नहीं कर सकते हैं। हालाँकि यह एक तरह से optional field है तो record insert करते time आप इसकी value नहीं भी देंगे तो भी कोई बात नहीं।

  • address : इस column का भी type VARCHAR है और length 100 है।

MySQL Show Table List

आपके database में सभी tables की listing के लिए SHOW command का use किया जाता हैं।

SHOW TABLES;

Output :

+---------------------+
| Tables_in_tutorials |
+---------------------+
| customers           |
+---------------------+
1 row in set (0.001 sec)

MySQL Describe Table

किसी table का structure के बारे में जानने के लिए DESCRIBE command का use किया जाता है। इस command की help से आप table के सभी columns के बारे में information ले सकते हैं जैसे column का name , type etc

DESCRIBE customers;

Output :

+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| id       | int(11)      | NO   | PRI | NULL    | auto_increment |
| name     | varchar(50)  | NO   |     | NULL    |                |
| email    | varchar(50)  | NO   |     | NULL    |                |
| mobileno | varchar(20)  | YES  |     | NULL    |                |
| address  | varchar(100) | YES  |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+
5 rows in set (0.054 sec)

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers