| SQL > Data Definition Language - DDL |
डेटा डेफिनिशन लैंग्वेज (डीडीएल) एसक्यूएल का एक हिस्सा है जो डेटाबेस ऑब्जेक्ट्स जैसे टेबल, व्यू, और इंडेक्स को बनाने, संशोधित करने और हटाने के लिए उपयोग किया जाता है। नीचे सबसे सामान्य DDL कमांड दिए गए हैं:
SQL CREATE TABLE
SQL Data Types
SQL View
SQL CREATE VIEW
SQL Index
SQL CREATE INDEX
SQL DROP TABLE
SQL TRUNCATE TABLE
SQL USE
SQL CREATE DATABASE
SQL DROP DATABASE
SQL >Data Definition Language - DDL> Create Table Statement
In a relational database, data is stored in tables. Given that there is no way for the database vendor to know ahead of time what your data storage needs are, you will for sure need to create tables that fit your needs in the database. Therefore, the CREATE TABLE statement is one of the most fundamental components of SQL.
एक रिलेशनल डेटाबेस में, डेटा तालिकाओं में संग्रहीत किया जाता है। यह देखते हुए कि डेटाबेस विक्रेता के पास समय से पहले यह जानने का कोई तरीका नहीं है कि आपके डेटा संग्रहण की क्या ज़रूरतें हैं, आपको निश्चित रूप से ऐसी तालिकाएँ बनाने की आवश्यकता होगी जो डेटाबेस में आपकी ज़रूरतों को पूरा करती हों। इसलिए, CREATE TABLE बयान एसक्यूएल का सबसे बुनियादी घटकों में से एक है।
Before we dive into the SQL syntax for CREATE TABLE, it is a good idea to understand what goes into a table. A table is made up of rows and columns. Each row represents one piece of data, and each column can be thought of as representing a component of that piece of data. For example, if we have a table for recording customer information, then the columns may include information such as First Name, Last Name, Address, City, Country, and Birth Date. As a result, when we specify a table, we include the column headers and the type of data for each column. We may also decide to place certain limitations, or constraints, to guarantee that the data stored in the table makes sense.
इससे पहले कि हम क्रिएट टेबल के लिए SQL सिंटैक्स में गोता लगाएँ, एक टेबल में क्या जाता है, यह समझने के लिए एक अच्छा विचार है। एक तालिका पंक्तियों और स्तंभों से बनी होती है। प्रत्येक पंक्ति डेटा के एक टुकड़े का प्रतिनिधित्व करती है, और प्रत्येक कॉलम को डेटा के उस टुकड़े के एक घटक का प्रतिनिधित्व करने के रूप में सोचा जा सकता है। उदाहरण के लिए, यदि हमारे पास ग्राहक जानकारी दर्ज करने के लिए एक तालिका है, तो कॉलम में प्रथम नाम, अंतिम नाम, पता, शहर, देश और जन्म तिथि जैसी जानकारी शामिल हो सकती है। नतीजतन, जब हम एक तालिका निर्दिष्ट करते हैं, तो हम कॉलम हेडर और प्रत्येक कॉलम के लिए डेटा का प्रकार शामिल करते हैं। हम यह भी तय कर सकते हैं कि तालिका में संग्रहित डेटा को समझने के लिए कुछ सीमाएँ या बाधाएँ डालनी चाहिए।
The SQL syntax for CREATE TABLE is
CREATE TABLE "table_name"
("column 1" "data type for column 1" [column 1 constraint(s)],
"column 2" "data type for column 2" [column 2 constraint(s)],
...
[table constraint(s)] );
("column 1" "data type for column 1" [column 1 constraint(s)],
"column 2" "data type for column 2" [column 2 constraint(s)],
...
[table constraint(s)] );
"Column 1" and "column 2" represent the name of each column. After the name, we specify the data type for that column. Typical data types include integers (such as 1), real numbers (such as 0.55), strings (such as 'sql'), date/time expressions (such as '2000-JAN-25 03:22:22'), and binary types. Different relational databases allow for different data types, so please consult with a database-specific reference first.
"कॉलम 1" और "कॉलम 2" प्रत्येक स्तंभ के नाम का प्रतिनिधित्व करते हैं। नाम के बाद, हम उस कॉलम के लिए डेटा प्रकार निर्दिष्ट करते हैं। विशिष्ट डेटा प्रकारों में पूर्णांक (जैसे 1), वास्तविक संख्या (जैसे 0.55), तार (जैसे कि 'sql'), दिनांक / समय के भाव (जैसे '2000-JAN-25 03:22:22'), और बाइनरी प्रकार। विभिन्न रिलेशनल डेटाबेस विभिन्न डेटा प्रकारों के लिए अनुमति देते हैं, इसलिए पहले डेटाबेस-विशिष्ट संदर्भ के साथ परामर्श करें।
The [ ] symbol means that the phrase inside it may occur zero, one, or more times. When creating a table, specifying column and table constraints is optional, and each column and each table may have more than one constraint.
[ ] प्रतीक का अर्थ है कि इसके अंदर वाक्यांश शून्य, एक या अधिक बार हो सकता है। तालिका बनाते समय, स्तंभ और तालिका अवरोधों को निर्दिष्ट करना वैकल्पिक है, और प्रत्येक स्तंभ और प्रत्येक तालिका में एक से अधिक बाधाएँ हो सकती हैं।
Six types of constraints can be placed when creating a table:
तालिका बनाते समय छह प्रकार की बाधाओं को रखा जा सकता है:
To create a customer table with the fields specified in the second paragraph above, we would type in
उपरोक्त दूसरे पैराग्राफ में निर्दिष्ट फ़ील्ड के साथ एक ग्राहक तालिका बनाने के लिए, हम टाइप करेंगे
CREATE TABLE Customer
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date datetime);
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date datetime);
No constraints were specified in the above SQL statement. What if we want to add a constraint that says the default country is 'United States'? In other words, if no data is entered for the "Country" column, it would be set to 'United States.' In that case, we would type the following SQL:
उपरोक्त SQL कथन में कोई बाधा निर्दिष्ट नहीं की गई थी। क्या होगा यदि हम एक बाधा जोड़ना चाहते हैं जो कहता है कि डिफ़ॉल्ट देश 'संयुक्त राज्य अमेरिका' है? दूसरे शब्दों में, यदि "देश" कॉलम के लिए कोई डेटा दर्ज नहीं किया गया है, तो इसे 'संयुक्त राज्य' में सेट किया जाएगा। उस स्थिति में, हम निम्न एसक्यूएल टाइप करेंगे:
CREATE TABLE Customer
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25) default 'United States',
Birth_Date datetime);
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25) default 'United States',
Birth_Date datetime);
Sometimes the table structure we need is the same as another table in the database. In this case, we can also use CREATE TABLE to make a copy of the table structure so we do not need to type all the column names, data types, and constraints in detail. The syntax for doing this is:
कभी-कभी हमें जिस तालिका संरचना की आवश्यकता होती है, वह डेटाबेस में किसी अन्य तालिका के समान होती है। इस स्थिति में, हम तालिका संरचना की एक प्रतिलिपि बनाने के लिए CREATE TABLE का भी उपयोग कर सकते हैं, इसलिए हमें सभी स्तंभ नामों, डेटा प्रकारों और बाधाओं को विस्तार से लिखने की आवश्यकता नहीं है। ऐसा करने के लिए वाक्य रचना है:
CREATE TABLE "table_name" AS
[SQL Statement];
[SQL Statement];
To copy both the structure and data of Table1 into Table2, we would issue the following SQL statement:
तालिका 1 की संरचना और डेटा दोनों को तालिका 2 में कॉपी करने के लिए, हम निम्नलिखित एसक्यूएल बयान जारी करेंगे:
CREATE TABLE Table2 AS
SELECT * FROM Table1;
SELECT * FROM Table1;
To copy the structure of Table1 into Table2 without any data, we would issue the following SQL statement:
बिना किसी डेटा के तालिका 1 की संरचना को कॉपी करने के लिए, हम निम्नलिखित एसक्यूएल स्टेटमेंट जारी करेंगे:
CREATE TABLE Table2 AS
SELECT * FROM Table1
WHERE 0 = 1;
SELECT * FROM Table1
WHERE 0 = 1;
The WHERE 0 = 1 clause is always false. Therefore, no row of data will be copied from Table1 to Table2. Only the table structure is copied over.
WHERE 0 = 1 क्लॉज हमेशा गलत होता है। इसलिए, तालिका 1 से तालिका 2 तक डेटा की कोई पंक्ति कॉपी नहीं की जाएगी। केवल तालिका संरचना की प्रतिलिपि बनाई गई है।
Comments
Post a Comment
Your advice or suggestions will be much appreciated and welcomed....