{"id":459,"date":"2023-01-25T13:36:07","date_gmt":"2023-01-25T13:36:07","guid":{"rendered":"http:\/\/learnlearn.uk\/ibcs\/?page_id=459"},"modified":"2023-01-25T13:36:07","modified_gmt":"2023-01-25T13:36:07","slug":"database-definition-language-queries","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/","title":{"rendered":"Database Definition Language Queries"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<h3>What is a Database Definition Language?<\/h3>\n<p>This is the programming language used to construct and alter the design of tables contained within a database. The most common form of DDL is Structured Query Language(SQL).<\/p>\n<p>This language is not used to directly alter the data stored within a table, rather it is used to construct the framework within which data is contained &#8211; this type of data that is used to define other data is known as <strong>metadata<\/strong> &#8211; data about data.<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">CREATE DATABASE<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Creating a Database &#8211; CREATE DATABASE<\/h3>\n<p>The syntax to create a database in SQL is simple:<\/p>\n<p><span class=\"sqlkeywordcolor\">CREATE<\/span>\u00a0<span class=\"sqlkeywordcolor\">DATABASE<\/span>\u00a0<em>databasename<\/em>; e.g.\u00a0<span class=\"sqlkeywordcolor\">CREATE<\/span>\u00a0<span class=\"sqlkeywordcolor\">DATABASE<\/span>\u00a0<i>library.db<\/i><\/p>\n<p>To do the same in SQLite then you would use the shell command<\/p>\n<p>sqlite3 library.db\u00a0 &lt;-\u00a0 if library.db already exists it will open the database, otherwise it will create it.<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">CREATE TABLE<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Creating a Table &#8211; CREATE TABLE<\/h3>\n<p><strong>Example 1 &#8211; Simple Non Relational Table<\/strong><\/p>\n<p>CREATE TABLE users(firstname varchar(255), lastname varchar(255), age integer, dateofbirth date);<\/p>\n<p><strong>Example 2 &#8211; Create a table with a primary key<\/strong><\/p>\n<p>CREATE TABLE Orders (OrderID integer NOT NULL PRIMARY KEY, OrderNumber integer NOT NULL, CustomerID integer FOREIGN KEY REFERENCES Customers(CustomerID));<\/p>\n<p>&nbsp;<\/p>\n<div class=\"arconix-box arconix-box-lgreen\"><div class=\"arconix-box-content\">\n<p><strong>SQL Data Types<\/strong><\/p>\n<ul>\n<li>Char &#8211; Fixed Length Text<\/li>\n<li>Varchar(255) &#8211; Variable Length (For SQLite use &#8211; Text)<\/li>\n<li>Integer &#8211; Store a whole number<\/li>\n<li>Boolean &#8211; Stores 1 or 0 for Boolean<\/li>\n<li>Real &#8211; Floating point number<\/li>\n<li>Date \/ Time &#8211; (SQLite has no date\u00a0 or time data type so use Text \/ Float \/ Integer and use something like Epoch Time)<\/li>\n<\/ul>\n<\/div><\/div>\n\n<\/div><h2 class=\"tabtitle\">ALTER TABLE<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Modifying a table &#8211; ALTER TABLE<\/h3>\n<p>If you want to alter the structure of a table (change column names \/ data types) then you can use the ALER table command.<\/p>\n<p>Examples:<\/p>\n<p>ALTER TABLE username ADD COLUMN height real;<\/p>\n<p>ALTER TABLE username MODIFY COLUMN height integer<\/p>\n<p>ALTER TABLE username DROP COLUMN email;<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">DROP TABLE<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Deleting a table &#8211; DROP TABLE<\/h3>\n<p>Deleting a table is easily with the drop table command.<\/p>\n<p>DROP TABLE users;<\/p>\n<p>Warning &#8211; this will drop the table straight away without warning &#8211;\u00a0<a href=\"https:\/\/thenewstack.io\/junior-dev-deleted-production-database\/\">A\u00a0 costly mistake that many an unwary junior developer has made..<\/a><\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>What is a Database Definition Language? This is the programming language used to construct and alter the design of tables contained within a database. The most common form of DDL is Structured Query Language(SQL). This language is not used to directly alter the data stored within a table, rather it is used to construct the&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Database Definition Language Queries<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Database Definition Language Queries - IB Computer Science<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Database Definition Language Queries - IB Computer Science\" \/>\n<meta property=\"og:description\" content=\"What is a Database Definition Language? This is the programming language used to construct and alter the design of tables contained within a database. The most common form of DDL is Structured Query Language(SQL). This language is not used to directly alter the data stored within a table, rather it is used to construct the&hellip;&nbsp;Read More &raquo;Database Definition Language Queries\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/\" \/>\n<meta property=\"og:site_name\" content=\"IB Computer Science\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/\",\"name\":\"Database Definition Language Queries - IB Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\"},\"datePublished\":\"2023-01-25T13:36:07+00:00\",\"dateModified\":\"2023-01-25T13:36:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"IB Computer Science\",\"item\":\"https:\/\/learnlearn.uk\/ibcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Database Definition Language Queries\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"name\":\"IB Computer Science\",\"description\":\"- learnlearn..uk\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\",\"name\":\"IB Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"width\":300,\"height\":41,\"caption\":\"IB Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Database Definition Language Queries - IB Computer Science","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/","og_locale":"en_GB","og_type":"article","og_title":"Database Definition Language Queries - IB Computer Science","og_description":"What is a Database Definition Language? This is the programming language used to construct and alter the design of tables contained within a database. The most common form of DDL is Structured Query Language(SQL). This language is not used to directly alter the data stored within a table, rather it is used to construct the&hellip;&nbsp;Read More &raquo;Database Definition Language Queries","og_url":"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/","og_site_name":"IB Computer Science","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/","url":"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/","name":"Database Definition Language Queries - IB Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#website"},"datePublished":"2023-01-25T13:36:07+00:00","dateModified":"2023-01-25T13:36:07+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/ibcs\/database-definition-language-queries\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"IB Computer Science","item":"https:\/\/learnlearn.uk\/ibcs\/"},{"@type":"ListItem","position":2,"name":"Database Definition Language Queries"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/ibcs\/#website","url":"https:\/\/learnlearn.uk\/ibcs\/","name":"IB Computer Science","description":"- learnlearn..uk","publisher":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/ibcs\/#organization","name":"IB Computer Science","url":"https:\/\/learnlearn.uk\/ibcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","contentUrl":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","width":300,"height":41,"caption":"IB Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/ibcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"What is a Database Definition Language? This is the programming language used to construct and alter the design of tables contained within a database. The most common form of DDL is Structured Query Language(SQL). This language is not used to directly alter the data stored within a table, rather it is used to construct the&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/459"}],"collection":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/comments?post=459"}],"version-history":[{"count":1,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/459\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/459\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/media?parent=459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}