Sql command pdf


















Just install any of the RDBMS that you like from their official website and you should be able to create a database server by simply following their instructions. Once you have a database server ready, you can get access to a Query Editor where you can type all your SQL queries. To work with SQL, you need to understand that data is organized into tables. One database would contain all the data for a single application in most cases.

A single database would have multiple tables that store values. For example:- If you have a restaurant management application or implemented E-Delivery solution for smooth operations, you would have a database that contains tables such as:. Each table would contain a specific type of data and various tables could have different types of relations.

Using SQL relations, we can combine values from different tables to fetch the data that we require. More on relations in a later section. To create a table, we would require two things.

Firstly, we would need all the fields that we want to store in a table. Secondly, we want to define the type of data that would enter into a table. Let's take the restaurant management application's Customers table as an example. We want to store some information about each of our customers such as their name, Phone Number, and Postal Code.

Now that we are done with the first step, we need to define the data types of these values. The name of a customer would be of character data type because we need to store alphabetical characters.

The postal code would be of type integer because we need to store numbers. Here is how the table would look like:. To identify each customer uniquely, we add an ID to them so that we can use this ID to connect data from various tables.

So, the final table structure could look something like this. To create tables for manipulating data effectively, we need to work with the correct data type. Let's say we want to work with dates, it would be easier to create a column for holding DATE type values instead of storing them as a string and writing logic to manipulate the values.

Now that we have our table s ready, let's see how we can store and retrieve data from the tables in our database. These are the most fundamental operations that one can perform on any database. For creating any application, these 4 types of operations are crucial. They are The general syntax for insert is:.

To insert data into our customer's table, we would use the following statement:. To read data from a table, we would use the Select statement where we define the columns that we want to fetch. The general syntax is:. If we wanted to select the name and phone number of a customer from our table, we would use:.

To update specific column s of specific row s , we make use of the Update statement. The general syntax for an update statement is:. WHERE conditions For example, if we wanted to update the phone number of a customer that has an ID of 2, we would write our query as:. If we wanted to remove some rows from a table, we would use the delete statement. WHERE condition Let's say we want to remove all the customers who live in a particular area.

So, we simply delete those rows that have a specific area code:. SQL has various operators that allow you to manipulate and compare multiple values. These are very useful and handy while creating queries. In a database, different tables store different values and these values are related to each other. To identify each row uniquely, we make use of SQL keys. An SQL key is either a single column or attribute or a group of columns that can uniquely identify rows in a table.

SQL Keys ensures that there aren't any rows with duplicate values. However, the most powerful use of keys is to establish relations between multiple tables in a database. To do so, we need to understand Primary Key and Foreign Key. The following sections of this SQL cheatsheet explain both of these concepts. It is a key that uniquely identifies a single row in a table. For example, in a customer's table, the ID key can be used as a primary key to uniquely identify a single customer. This key can then be used to fetch data from multiple tables that have data related to the customer.

For Example: -. A foreign key is used to link two tables together by establishing a relationship. The table that contains the foreign key is known as the child table, while the table containing the primary key for the foreign key is known as the parent table. For example: Let's say we have 3 different tables to manage a restaurant - products, users, and orders. In our products table, we list all our products and in the user's table, we have details of all our users. When a user places an order, we save the data in the orders table.

But, instead of saving the complete details of the product and all the information of the user, we save their primary keys in the orders table.

Here, we create a primary key for the order ID as it uniquely identifies an order. Also, we create two foreign keys that reference different primary keys. Once you understand Primary Key and Foreign Key, you can use joins to fetch data by combining multiple tables. Let's take the orders, customers, and products table as an example. We can join the orders table with customers and products table to get only the information that we require. Let's say we want to see all the orders with the customer's name, product name, and product price as follows:.

If nothing is specified, sorting is done in Ascending order ASC. Note:- We can use any type of join that we want. The condition via which we want to join the tables needs to be specified after the ON keyword. We can even eliminate the AS keyword in this case and simply write the Alias after the table name.

Note: - We separate each row with a pair of brackets followed by a comma. SQL is a definite requirement when you are trying to build an application of any size and scale. Learning SQL might be tough for beginners, but once you get the hang of it, it's just like thinking. If you can remember a particular operation or keyword, you can open up this SQL commands cheat sheet to get all the required information.

A floating-point number value where the total digits are set by the size parameter,. SQL Arithmetic Operators. SQL Bitwise Operators.

SQL Comparison Operators. SQL Compound Operators. SQL Logical Operators. Primary Key. Foreign Key. Retrieve specific columns. Retrieve Filtered Rows. Retrieve Distinct Rows. Count the Filtered Rows.

Sort Rows Based on Criteria. Get Average, Sum, Max, Min, etc. Get all Values from two Tables. Get selected values from two tables. Insert All Values in Order a Table. Insert Selected Values in a Table. Create a New Table. Remove all Values from a Table. Add a Column to the Table. Remove a Column from a Table.

Update Column Value for all Rows. Update Column Value for Selected Rows. Filter by Multiple Matching Conditions. Filter Rows by Multiple Parallel Conditions. Filter Rows Based on Values in a List. Filter Rows with Values in a Range. Data Type. CHAR size. A fixed-length string that can contain numbers, letters, and special characters. The string length is from 0 - The statements which defines the structure of a database, create tables, specify their keys, indexes and so on.

Want to get certified in SQL! With this, we come to an end of SQL commands Cheat sheet. Still have queries? Leave a Reply Cancel reply. Your email address will not be published. Read More. Become a Certified Professional. Introduction: SQL is a basic query language which every programmer must know. Master Most in Demand Skills Now! Career Transition. Leave a Reply Cancel reply Your email address will not be published.

It is an keyword in SQL that is used to rename a column or table using an alias name. It is a function that takes the name of a column as argument and counts the number of rows when the column is not NULL.



0コメント

  • 1000 / 1000