Skip to main content

SQL Syntax

SQL (Structured Query Language) is a programming language used for managing and manipulating relational databases. Here's a basic overview of its syntax:


  1. SELECT: Used to retrieve data from a database.

SELECT column1, column2 FROM table_name WHERE condition;


Example


SELECT first_name, last_name FROM employees WHERE department = 'HR';




  1. INSERT INTO: Used to insert new records into a table.

INSERT INTO table_name (column1, column2) VALUES (value1, value2);


Example


INSERT INTO employees (first_name, last_name) VALUES ('John', 'Doe');



  1. UPDATE: Used to modify existing records in a table.

UPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;


Example


UPDATE employees SET department = 'Finance' WHERE employee_id = 101;


  1. DELETE: Used to delete records from a table.

DELETE FROM table_name WHERE condition;


Example


DELETE FROM employee WHERE employee_id=102;


  1. CREATE TABLE: Used to create a new table in the database.

CREATE TABLE table_name (

    column1 datatype,

    column2 datatype,

    ...

);


Example


CREATE TABLE employees ( employee_id INT PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50), department VARCHAR(50) );



  1. ALTER TABLE: Used to modify an existing table.

ALTER TABLE table_name ADD column_name datatype;


Example


ALTER TABLE employees ADD email VARCHAR(100);



  1. DROP TABLE: Used to delete a table and all its data from the database.

DROP TABLE table_name;


Example


DROP TABLE table_name;



  1. JOIN: Used to combine rows from two or more tables based on a related column.

SELECT * FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;



Example


SELECT orders.order_id, customers.customer_name FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id;




  1. GROUP BY: Used to group rows that have the same values into summary rows.

SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;


Example


SELECT product_id, SUM(quantity) AS total_quantity FROM orders GROUP BY product_id;



  1. ORDER BY: Used to sort the result set in ascending or descending order.

SELECT * FROM table_name ORDER BY column_name ASC|DESC;


Example


SELECT * FROM customers ORDER BY last_name ASC;



These are some of the fundamental SQL commands and their syntax. The exact syntax may vary slightly depending on the database management system you are using (e.g., MySQL, PostgreSQL, SQLite, etc.), so it's always a good idea to consult the documentation specific to your database.

 

Comments

Popular posts from this blog

Power BI tenant settings and admin portal

As of my last update, Power BI offers a dedicated admin portal for managing settings and configurations at the tenant level. Here's an overview of Power BI tenant settings and the admin portal: 1. Power BI Admin Portal: Access : The Power BI admin portal is accessible to users with admin privileges in the Power BI service. URL : You can access the admin portal at https://app.powerbi.com/admin-portal . 2. Tenant Settings: General Settings : Configure general settings such as tenant name, regional settings, and language settings. Tenant Administration : Manage user licenses, permissions, and access rights for Power BI within the organization. Usage Metrics : View usage metrics and reports to understand how Power BI is being used across the organization. Service Health : Monitor the health status of the Power BI service and receive notifications about service incidents and outages. Audit Logs : Access audit logs to track user activities, access requests, and administrative actions wit...

Understanding the Power BI ecosystem and workflow

Understanding the Power BI ecosystem and workflow involves getting familiar with the various components of Power BI and how they interact to provide a comprehensive data analysis and visualization solution. Here's a detailed explanation: Power BI Ecosystem The Power BI ecosystem consists of several interconnected components that work together to enable users to connect to data sources, transform and model data, create visualizations, and share insights. The main components are: Power BI Desktop Power BI Service Power BI Mobile Power BI Gateway Power BI Report Server Power BI Embedded PowerBI Workflow Here’s a typical workflow in the Power BI ecosystem: Step 1: Connect to Data Sources Power BI Desktop:  Connect to various data sources like Excel, SQL databases, cloud services, and more. Power BI Gateway:  If using on-premises data sources, install and configure the gateway for secure data transfer. Step 2: Data Transformation and Modeling Power BI Desktop:  Use Power Query...

DAX UPPER Function

The DAX UPPER function in Power BI is used to convert all characters in a text string to uppercase. This function is useful for standardizing text data, ensuring consistency in text values, and performing case-insensitive comparisons. Syntax: UPPER(<text>) <text>: The text string that you want to convert to uppercase. Purpose: The UPPER function helps ensure that text data is consistently formatted in uppercase. This can be essential for tasks like data cleaning, preparing text for comparisons, and ensuring uniformity in text-based fields. E xample: Suppose you have a table named "Customers" with a column "Name" that contains names in mixed case. You want to create a new column that shows all names in uppercase. UppercaseName = UPPER(Customers[Name]) Example Scenario: Assume you have the following "Customers" table: You can use the UPPER function as follows: Using the UPPER function, you can convert all names to uppercase: UppercaseName = ...