{"id":7,"date":"2018-11-15T19:58:55","date_gmt":"2018-11-15T19:58:55","guid":{"rendered":"https:\/\/barkhane.com\/sql\/sql\/"},"modified":"2024-02-07T15:04:36","modified_gmt":"2024-02-07T15:04:36","slug":"sql","status":"publish","type":"page","link":"https:\/\/barkhane.com\/sql\/","title":{"rendered":"SQL"},"content":{"rendered":"<blockquote><p><strong><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-medium wp-image-385\" src=\"https:\/\/barkhane.com\/sql\/wp-content\/uploads\/sites\/3\/2024\/02\/SQL-300x300.png\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/barkhane.com\/sql\/wp-content\/uploads\/sites\/3\/2024\/02\/SQL-300x300.png 300w, https:\/\/barkhane.com\/sql\/wp-content\/uploads\/sites\/3\/2024\/02\/SQL-150x150.png 150w, https:\/\/barkhane.com\/sql\/wp-content\/uploads\/sites\/3\/2024\/02\/SQL.png 512w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/strong><\/p>\n<p><strong>SQL\u00a0(Structured Query Language)<\/strong>\u00a0is a\u00a0domain-specific language\u00a0used in programming and designed for managing data held in a\u00a0relational database management system\u00a0(<strong>RDBMS<\/strong>), SQL is used to communicate with a database. According to <strong>ANSI<\/strong> (American National Standards Institute), It is a standard language for storing, manipulating and retrieving data in databases. It is particularly useful in handling\u00a0structured data\u00a0where there are relations between different entities\/variables of the data. SQL introduced the concept of accessing many records with one single command; and second, it eliminates the need to specify\u00a0how\u00a0to reach a record, e.g. with or without an database index. Some common relational database management systems that use SQL are: <strong>Oracle<\/strong>, <strong>Sybase<\/strong>, <strong>Microsoft SQL Server<\/strong>, <strong>Access<\/strong>, <strong>MySQL<\/strong>, etc. Although most database systems use SQL, most of them also have their own additional proprietary extensions that are usually only used on their system. However, the standard SQL commands such as \\&#8221;<strong>Select<\/strong>\\&#8221;, \\&#8221;<strong>Insert<\/strong>\\&#8221;, \\&#8221;<strong>Update<\/strong>\\&#8221;, \\&#8221;<strong>Delete<\/strong>\\&#8221;, \\&#8221;<strong>Create<\/strong>\\&#8221;, and \\&#8221;<strong>Drop<\/strong>\\&#8221; can be used to accomplish almost everything that one needs to do with a database.<\/p><\/blockquote>\n<h3><strong>Table Basics<\/strong><\/h3>\n<p>A relational database system contains one or more objects called tables. The data or information for the database are stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows. Columns contain the column name, data type, and any other attributes for the column. Rows contain the records or data for the columns. Here is a sample table called \\&#8221;weather\\&#8221;.<\/p>\n<p>city, state, high, and low are the columns. The rows contain the data for this table:<\/p>\n<table width=\"410\">\n<tbody>\n<tr>\n<td colspan=\"4\"><strong>Weather<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>city<\/strong><\/td>\n<td><strong>state<\/strong><\/td>\n<td><strong>high<\/strong><\/td>\n<td><strong>low<\/strong><\/td>\n<\/tr>\n<tr>\n<td>City A<\/td>\n<td>State A<\/td>\n<td>105<\/td>\n<td>90<\/td>\n<\/tr>\n<tr>\n<td>City B<\/td>\n<td>State A<\/td>\n<td>101<\/td>\n<td>92<\/td>\n<\/tr>\n<tr>\n<td>City C<\/td>\n<td>State A<\/td>\n<td>88<\/td>\n<td>69<\/td>\n<\/tr>\n<tr>\n<td>City D<\/td>\n<td>State B<\/td>\n<td>77<\/td>\n<td>60<\/td>\n<\/tr>\n<tr>\n<td>City E<\/td>\n<td>State C<\/td>\n<td>80<\/td>\n<td>72<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong>What is Relational Database?<\/strong><\/h3>\n<p>Relational database means the data is stored as well as retrieved in the form of relations (tables). The relational database with only one relation called\u00a0<strong>STUDENT <\/strong>which stores\u00a0<strong>ROLL_NO<\/strong>,\u00a0<strong>NAME<\/strong>,\u00a0<strong>ADDRESS<\/strong>,\u00a0<strong>PHONE<\/strong>\u00a0and\u00a0<strong>AGE<\/strong>\u00a0of students.<\/p>\n<p><strong>STUDENT<\/strong><\/p>\n<table width=\"640\">\n<tbody>\n<tr>\n<td width=\"97\"><strong>ROLL_NO<\/strong><\/td>\n<td width=\"130\"><strong>NAME<\/strong><\/td>\n<td width=\"135\"><strong>ADDRESS<\/strong><\/td>\n<td width=\"135\"><strong>PHONE<\/strong><\/td>\n<td width=\"68\"><strong>AGE<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"97\">1<\/td>\n<td width=\"130\">RAM<\/td>\n<td width=\"135\">DELHI<\/td>\n<td width=\"135\">9000000001<\/td>\n<td width=\"68\">88<\/td>\n<\/tr>\n<tr>\n<td width=\"97\"><\/td>\n<td width=\"130\">RAMESH<\/td>\n<td width=\"135\">GURGAON<\/td>\n<td width=\"135\">9000000002<\/td>\n<td width=\"68\">55<\/td>\n<\/tr>\n<tr>\n<td width=\"97\">3<\/td>\n<td width=\"130\">SUJIT<\/td>\n<td width=\"135\">ROHTAK<\/td>\n<td width=\"135\">9000000003<\/td>\n<td width=\"68\">65<\/td>\n<\/tr>\n<tr>\n<td width=\"97\">4<\/td>\n<td width=\"130\">SURESH<\/td>\n<td width=\"135\">DELHI<\/td>\n<td width=\"135\">9000000004<\/td>\n<td width=\"68\">15<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: center;\"><strong>\u00a0These are some important terminologies that are used in terms of relation.<\/strong><\/p>\n<p><strong>Attribute:<br \/>\n<\/strong>Attributes are the properties that define a relation. e.g.;\u00a0<strong>ROLL_NO<\/strong>,\u00a0<strong>NAME<\/strong>\u00a0etc.<\/p>\n<p><strong>Tuple:<br \/>\n<\/strong>Each row in the relation is known as tuple. The above relation contains 4 tuples, one of which is shown as:<\/p>\n<table width=\"640\">\n<tbody>\n<tr>\n<td width=\"97\">1<\/td>\n<td width=\"130\">RAM<\/td>\n<td width=\"135\">DELHI<\/td>\n<td width=\"135\">9000000001<\/td>\n<td width=\"68\">18<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Degree:<br \/>\n<\/strong>The number of attributes in the relation is known as degree of the relation. The\u00a0<strong>STUDENT<\/strong>\u00a0relation defined above has degree 5.<\/p>\n<p><strong>Cardinality:<br \/>\n<\/strong>The number of tuples in a relation is known as cardinality. The\u00a0<strong>STUDENT <\/strong>relation defined above has cardinality 4.<\/p>\n<p><strong>Column:<br \/>\n<\/strong>Column represents the set of values for a particular attribute. The column\u00a0<strong>ROLL_NO<\/strong>\u00a0is extracted from relation STUDENT.<\/p>\n<h3>Basics of SQL Commands<\/h3>\n<ul>\n<li>SQL commands are a set of instructions that are used to interact with the database like\u00a0Sql Server, MySql, Oracle etc. SQL commands are responsible to create and to do all the manipulation on the database. These are also responsible to give\/take out access rights on a particular database<\/li>\n<\/ul>\n<p><strong>Sql Commands Category<\/strong><\/p>\n<p>We have different sql commands for different-different purpose. We can grouped Sql Commands into five major categories depending on their functionality.<\/p>\n<ol>\n<li><strong>Data Definition Language (DDL)<br \/>\n<\/strong>These SQL commands are used to create, modify, and drop the structure of database objects like table, view, procedure, indexes etc. In this category we have CREATE, ALTER, DROP and TRUNCATE commands.<br \/>\n<strong>Note<br \/>\n<\/strong>Only with DDL commands we need to write keyword like (table, procedure, view, index, function) with the syntax of command.<br \/>\nThese commands are used to create\/modify the structure of the database object.<\/li>\n<li><strong>Data Manipulation Language (DML)<br \/>\n<\/strong>These SQL commands are used to store, modify, and delete data from database tables. In this category we have INSERT, UPDATE, and DELETE commands.<\/li>\n<\/ol>\n<ol start=\"3\">\n<li><strong>Data Query Language (DQL)<br \/>\n<\/strong>These SQL commands are used to fetch\/retrieve data from database tables. In this category we have only SEELCT command.<\/li>\n<\/ol>\n<ol start=\"4\">\n<li><strong>Transaction Control Language (TCL)<br \/>\n<\/strong>These SQL commands are used to handle changes which affect the data in database. Basically we use these commands with in the transaction or to make a stable point during changes in database at which we can rollback the database state if required. In this category we have SAVEPOINT, ROLLBACK and COMMIT commands.<\/li>\n<\/ol>\n<ol start=\"5\">\n<li><strong>Data Control Language (DCL)<br \/>\n<\/strong>These SQL commands are used to implement security on database objects like table, view, stored procedure etc. In this category we have GRANT and REVOKE commands.<\/li>\n<\/ol>\n<p>SQL commands are a set of instructions that are used to interact with the database like\u00a0Sql Server, MySql, Oracle etc. SQL commands are responsible to create and to do all the manipulation on the database. These are also responsible to give\/take out access rights on a particular database<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL\u00a0(Structured Query Language)\u00a0is a\u00a0domain-specific language\u00a0used in programming and designed for managing data held in a\u00a0relational database management system\u00a0(RDBMS), SQL is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":19,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-7","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/pages\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/pages\/7\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/media?parent=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}