sql - queries
In previous chapter i have explained you How to Make Tables In MS SQL..Now i am gonna eplain you What are the queris of SQL
SQL coins the term query as the name for its commands. Basically, all SQL code is written in the form of a query statement and then executed against a database. All SQL queries perform some type of data operation such as selecting data, inserting/updating data, or creating data objects such as SQL databases and SQL tables. Each query statement begins with a clause such as SELECT,UPDATE, CREATE or DELETE.
SELECT queries are the most commonly used SQL commands, so let's take a look at a SELECT query that will return records from the orders table that we created previously in the SQL Tables lesson.
SQL Query Code:
USE mydatabase;
SELECT * FROM orders;
SQL Query Results:
id | customer | day_of_order | product | quantity |
1 | Gauravsam | 2008-08-01 00:00:00.000 | Pen | 4 |
We'll explain the mechanics of this code in the next lesson. For now, just know that SELECT queries essentially tell SQL to go and "fetch" table data for your viewing pleasure.
Here's a look at a few different query types including a INSERT and SELECTquery we will be covering in the next lesson, SQL Select.
SQL Query Examples:
-- Inserts data into a SQL Database/Table
INSERT INTO orders (customer,day_of_order,product, quantity)
VALUES('Gauravsam','8/1/08','Pen',4);
-- Selects data from a SQL Database/Table
SELECT * FROM orders;
-- Updates data in a Database/Table
UPDATE orders SET quantity = '6'
WHERE id = '1'
More information about these queries can be found at the following links: SQL Insert, SQL Update, SQL Delete
sql - query structure review
Structurally, each SQL query we have seen in this lesson are similar. Each start with a clause telling SQL which operation to perform and the remaining lines provide more detailed information as to how we want SQL to go about performing each SQL Command.
No comments:
Post a Comment