[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-573232-105":3,"detail-sidebar-cat-1-en-105":81,"doc-detail-573232-en":126},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":74,"head_meta":76,"extra_data":78,"updated_unix":80},105,"en","sql-cheat-sheet-sql-basics-sql-statements","SQL Cheat Sheet - SQL Basics - SQL Statements","","Concise SQL cheat sheet covering core database operations and common query patterns. Includes creating and selecting databases, defining tables with constraints and default values, inserting sample rows, altering table structure by adding/removing columns and changing data types, updating specific records, and deleting rows or tables. Provides examples for retrieving data with SELECT, filtering with LIKE/IN/comparison and NULL checks, limiting output with TOP, sorting with ORDER BY, and aggregating using COUNT, SUM, MAX, MIN, AVG, GROUP BY with HAVING, plus CAST/CONVERT.",{"@graph":14,"@context":73},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/template/","Template",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/template/general/","General",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/template/sql-cheat-sheet-sql-basics-sql-statements/573232/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/sql-cheat-sheet-sql-basics-sql-statements/573232.png","ImageObject",442,249,{"name":42,"@type":43},"Jordan Avery","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-16","2026-10-13",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",5,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69],{"name":60,"@type":61,"acceptedAnswer":62},"How do you create and switch to a database in SQL?","Question",{"text":63,"@type":64},"Use CREATE DATABASE to create the database, then use USE \u003Cdatabase_name> to switch to it.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"How can you filter records using LIKE, IN, NULL, and ranges?",{"text":68,"@type":64},"Use WHERE ... LIKE for pattern matching, WHERE ... IN (...) for multiple values, IS NULL / IS NOT NULL for null checks, and BETWEEN for inclusive ranges.",{"name":70,"@type":61,"acceptedAnswer":71},"What are the common aggregate functions and how do you use GROUP BY with HAVING?",{"text":72,"@type":64},"Use COUNT, SUM, MAX, MIN, and AVG to compute totals and statistics. Combine GROUP BY with HAVING to filter groups based on aggregate results, such as COUNT(...) > 1 or AVG(...) > a threshold.","https://schema.org",{"og:url":32,"og:type":75,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":77,"canonical":32},"index,follow",{"doc_id":79,"site_id":7},573232,1792082639,{"code":4,"msg":82,"data":83},"success",[84,89,94,99,104,109,114,119,123],{"id":85,"doc_module":22,"doc_module_name":25,"category_name":86,"show_sort_weight":87,"slug":88},11,"Presentations",90,"presentations",{"id":90,"doc_module":22,"doc_module_name":25,"category_name":91,"show_sort_weight":92,"slug":93},12,"Resumes",80,"resumes",{"id":95,"doc_module":22,"doc_module_name":25,"category_name":96,"show_sort_weight":97,"slug":98},14,"Invoices",70,"invoices",{"id":100,"doc_module":22,"doc_module_name":25,"category_name":101,"show_sort_weight":102,"slug":103},15,"Posters",60,"posters",{"id":105,"doc_module":22,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},16,"Social Media",50,"social-media",{"id":110,"doc_module":22,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},17,"Forms",40,"forms",{"id":115,"doc_module":22,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},18,"Letters",30,"letters",{"id":120,"doc_module":22,"doc_module_name":25,"category_name":121,"show_sort_weight":55,"slug":122},21,"Paper Templates","papers-templates",{"id":124,"doc_module":22,"doc_module_name":25,"category_name":29,"show_sort_weight":4,"slug":125},158,"general-158",{"code":4,"msg":82,"data":127},{"doc_id":79,"user_id":128,"nickname":42,"user_avatar":129,"doc_module":22,"category_id":124,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":130,"file_id":131,"file_url":132,"file_type":133,"file_size":134,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":105,"language":135,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":136,"faqs":137,"seo_title":138,"seo_description":12,"update_tm":139,"read_time":140},1099523882367,"https://ap-avatar.wpscdn.com/davatar_9964176cb1d06d4a9deccf72a44ae3dc","Structured Query language (SQL)  \n| 1. Create database | create database sample2 |\n| --- | --- |\n| 2. Use the database | use sample2 |\n| 3. Create table | create table customer (\u003Cbr>customerid int identity(1, 1) primary key,\u003Cbr>customernumber int not null unique check (customernumber>0), lastname varchar(30) not null,\u003Cbr>firstname varchar(30) not null, areacode int default 71000, address varchar(50),\u003Cbr>country varchar(50) default 'Malaysia') |\n| 4. Insert values into table | insert into customer values\u003Cbr>(100,'Fang Ying','Sham','418999','sdadasfdfd',default),\u003Cbr>(200,'Mei Mei','Tan',default,'adssdsadsd','Thailand'),\u003Cbr>(300,'Albert','John',default,'dfdsfsdf',default) |\n| 5. Display record from table | --display all records\u003Cbr>select * from customer\u003Cbr>--display particular columns\u003Cbr>select customerid , customernumber , lastname , firstname from customer |\n| 6. Add new column to table | alter table customer\u003Cbr>add phonenumber varchar (20) |\n| 7. Add values to newly added column/ Update table | update customer set phonenumber = '1234545346' where customerid=1\u003Cbr>update customer set phonenumber = '45554654' where customerid=2 |\n| 8. Delete a column | alter table customer\u003Cbr>drop column phonenumber |\n| 9. Delete record from table--if not put ‘where’, will delete all record | delete\u003Cbr>from customer\u003Cbr>where country = 'Thailand' |\n| 10. Delete table | drop table customer |\n| 11. Change data type | alter table customer\u003Cbr>alter column phonenumber varchar (10) |\n\n\n| 1. Create database | create database SaleOrder |\n| --- | --- |\n| 2. Use the database | use SaleOrder |\n| 3. Create tables | create table dbo.customer ( CustomerID int NOT null primary key, CustomerFirstName varchar(50) NOT null,\u003Cbr>CustomerLastName varchar(50) NOT null, CustomerAddress varchar(50) NOT null, CustomerSuburb varchar(50) null, CustomerCity varchar(50) NOT null, CustomerPostCode char(4) null, CustomerPhoneNumber char(12) null,);\u003Cbr>create table dbo. inventory ( InventoryID tinyint NOT null primary key, InventoryName varchar(50) NOT null, InventoryDescription varchar(255) null,);\u003Cbr>create table dbo.employee ( EmployeeID tinyint NOT null primary key, EmployeeFirstName varchar(50) NOT null,\u003Cbr>EmployeeLastName varchar(50) NOT null,\u003Cbr>EmployeeExtension char(4) null,);\u003Cbr>create table [dbo](dbo.sale)[.](dbo.sale)[sale](dbo.sale) (\u003Cbr>SaleID tinyint not null primary key,\u003Cbr>CustomerID int not null references customer(CustomerID), InventoryID tinyint not null references Inventory(InventoryID), EmployeeID tinyint not null references Employee (EmployeeID), SaleDate date not null,\u003Cbr>SaleQuantity int not null, SaleUnitPrice smallmoney not null ); |\n| 4. Check what table inside | select * from information_schema.tables |\n| 5. View specific row | --top: show only the first two\u003Cbr>select top 2 * from customer\u003Cbr>--top 40 percent: also means show the first two\u003Cbr>select top 40 percent * from customer |\n| 6. View specific column | --sort result (by default is ascending)\u003Cbr>select customerfirstname, customerlastname from customer order by customerlastname desc\u003Cbr>select customerfirstname, customerlastname from customer\u003Cbr>order by 4, 2, 3 desc --Order By Based on column no. without typing column name\u003Cbr>--distinct: only show unique value\u003Cbr>select distinct customerlastname from customer order by customerlastname |\n\n\n| 7. Save table to another table | --into file_name: save result in another table (BASE TABLE)\u003Cbr>select distinct customerlastname into temp\u003Cbr>from customer\u003Cbr>order by customerlastname\u003Cbr>select * from temp--see the table (data type will remain) |  |\n| --- | --- | --- |\n| 8. Like (search something) | -- (underscore sign) _ is only specific for one character only\u003Cbr>-- (percent sign) % represents zero, one, or multiple characters\u003Cbr>select * from customer\u003Cbr>where customerlastname like '_r%' |  |\n| 9. In (search something) | --search multiple items\u003Cbr>select * from customer\u003Cbr>where customerlastname in ( 'Brown', ‘Michael’, ’Jim’) |  |\n| 10. > (search somethi","cbCaiaWnUzdq4ljb","https://ap.wps.com/l/cbCaiaWnUzdq4ljb","pdf",673016,"English","# SQL Basics\n## Database and Table Operations\n## Querying and Filtering\n## Sorting and Limiting\n## Aggregation and Expressions","[{\"question\":\"How do you create and switch to a database in SQL?\",\"answer\":\"Use CREATE DATABASE to create the database, then use USE \\u003cdatabase_name\\u003e to switch to it.\"},{\"question\":\"How can you filter records using LIKE, IN, NULL, and ranges?\",\"answer\":\"Use WHERE ... LIKE for pattern matching, WHERE ... IN (...) for multiple values, IS NULL / IS NOT NULL for null checks, and BETWEEN for inclusive ranges.\"},{\"question\":\"What are the common aggregate functions and how do you use GROUP BY with HAVING?\",\"answer\":\"Use COUNT, SUM, MAX, MIN, and AVG to compute totals and statistics. Combine GROUP BY with HAVING to filter groups based on aggregate results, such as COUNT(...) \\u003e 1 or AVG(...) \\u003e a threshold.\"}]","SQL Cheat Sheet - SQL Basics - SQL Statements | PDF",1791935276,6]