Skip to main content

SQL> Data Definition Language

SQLData Definition Language - DDL
Data Definition Language (DDL) is a part of SQL that is used to create, modify, and delete database objects such as table, view, and index. Below are the most common DDL commands:

डेटा डेफिनिशन लैंग्वेज (डीडीएल) एसक्यूएल का एक हिस्सा है जो डेटाबेस ऑब्जेक्ट्स जैसे टेबल, व्यू, और इंडेक्स को बनाने, संशोधित करने और हटाने के लिए उपयोग किया जाता है। नीचे सबसे सामान्य 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 - DDLCreate 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" 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:

तालिका बनाते समय छह प्रकार की बाधाओं को रखा जा सकता है:

  • NOT NULL Constraint: Ensures that a column cannot have NULL value. यह सुनिश्चित करता है कि एक कॉलम में NULL मान नहीं हो सकता है
  • DEFAULT Constraint: Provides a default value for a column when none is specified. जब कोई भी निर्दिष्ट नहीं होता है, तो कॉलम के लिए एक डिफ़ॉल्ट मान प्रदान करता है।
  • UNIQUE Constraint: Ensures that all values in a column are different. यह सुनिश्चित करता है कि एक कॉलम के सभी मान अलग-अलग हैं।
  • CHECK Constraint: Makes sure that all values in a column satisfy certain criteria. यह सुनिश्चित करता है कि एक कॉलम के सभी मान कुछ मानदंडों को पूरा करते हैं।
  • Primary Key Constraint: Used to uniquely identify a row in the table. तालिका में एक पंक्ति को विशिष्ट रूप से पहचानने के लिए उपयोग किया जाता है।
  • Foreign Key Constraint: Used to ensure referential integrity of the data. डेटा की संदर्भात्मक अखंडता सुनिश्चित करने के लिए उपयोग किया जाता है।

  • 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);

    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);

    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];

    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;

    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;

    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

    Popular posts from this blog

    Excel VBA Code For Clear Cell एक्सेल VBA कोड क्लियर सेल के लिए

    # VBA Code to Clear Cell :- To  clear cells using VBA , use a statement with the following structure:- VBA का उपयोग :-  सेल  को साफ करने के लिए Cells.Clear VBA Statement Explanation Item:  Cells. VBA Construct:  Range object. Description:  Range object representing the cells you want to clear. You can usually return a Range object with constructs such as the Worksheet.Range, Worksheet.Cells (with Range.Item), Range.Offset, Range.Resize or Application.ActiveCell properties. If you explicitly declare an object variable to represent Cells, use the Range object data type. Item:  Clear. VBA Construct:  Range.Clear method. Description:  The Range.Clear method clears the Range object you specify (Cells). Range.Clear clears the entire Range object, including values, formulas and formatting. VBA स्टेटमेंट स्पष्टीकरण 1. आइटम: सेल। VBA निर्माण: रेंज ऑब्जेक्ट। विवरण: रेंज ऑब्जेक्ट उन कोश...

    Insert Multiple Blank Row मल्टीपल ब्लैंक रो डालें

    👍  If you ever need to insert multiple blank rows into your data, doing it manually could be very time consuming if you have a large data set. Here’s a quick way to do this by inserting a blank row into your data after every Nth record. यदि आपको कभी भी अपने डेटा में कई रिक्त पंक्तियों को सम्मिलित करने की आवश्यकता होती है, तो मैन्युअल रूप से ऐसा करने में बहुत समय लग सकता है यदि आपके पास एक बड़ा डेटा सेट है। हर Nth रिकॉर्ड के बाद आपके डेटा में एक रिक्त पंक्ति सम्मिलित करके ऐसा करने का एक त्वरित तरीका है। Add a column  to the right of your data. If the helper column is in  E1 , then add this formula into  E2  and copy it down to the end of the data. Change N to a number (5 if you want every 5th row etc…). =MOD(ROW(E2)-ROW($E$1)-1,N) Now  highlight  the whole column. Go to the  Home  tab in the ribbon. In the  Editing  section, press the  Find & Select  button. In the drop down menu, select  Find . You ...

    Basic Excel Learn by Online ऑनलाइन द्वारा बेसिक एक्सेल जानें