Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
 
SQL QURIES
SQL - Data Types
SQL recognizes 4 general types of data. As the database designer you will be selecting which type of datathat can be placed in each table column. Before we look at each type of table column we will elaborate on specificdata types and how they are handled in SQL.
Character Strings - ('Words or numbers')
Numbers - (3, 3.423, -17)
Booleans - (True / False)
Nulls - (empty fields)
SQL - NULL Values
A null value may be the most foreign to new programmers. Stating that a value has a null value indicates thatnothing exists in that table field. When the table is created you may either allow a table to have a null value or maydisallow null values for each table column.
SQL Code:
CREATE TABLE weekly_payroll(employee_id VARCHAR(10) PRIMARY KEY,total_hours INT NULL,hourly_rate MONEY NOT NULL,);
SQL - Numeric Data
Dates, time stamps, integers, and money are all numeric data types. The advantage of working with numbersis that SQL has built in functions such as the AVG() or SUM() functions that will return the average or the sum of anumeric column.
Numbers:
rate_of_pay 
2726.6628.40
SQL - Boolean Data
Boolean values are either yes/no (true/false) types of data. Others use a 1/0 (1 for yes 0 for no) approach.Either something is or something is not.
Boolean Values:
admin
11
 
0
SQL - Character Strings
Character strings are sentences, symbols, or a combination of both. Math functions can not be performed withcharacter strings.
Character Strings:
employee_id 
TS_0036TS_0078CL_1099
Tips
Dates and times should always be set to "NOT NULL" since time always exists.
Character Strings are sometimes referred to as varchar(s).
SQL - Commands
SQL commands can be categorized into three distinct groups. Each type of command plays an essential rolewhile working with your database. One analogy might be to think of each SQL Command as a possible tool in your tool shed. Certain duties require specific tools and the more tools you have in your shed, the greater the chancesthat you will have the exact tool you need for the appropriate job.
SQL - What is a Clause
Clauses were mentioned briefly in the 
 lesson. To briefly recap, they are the commands issuedduring a query. SELECT, INSERT, ADD, DROP, CREATE, etc are all clauses that begin each SQL Query andexecute some sort of action upon your database.
SQL - What is a Function
There are a number of functions built into SQL that can add column values for you, average column values, or even change lowercase to uppercase strings. These functions are used directly inside of your queries and areexcellent tools for you to use.
SQL Code:
Count() functionSELECT COUNT(*) FROM
table_one
;
The query above will return a numeric value representing the number of rows that have been inserted intoyour database. We will be covering this function as well as many others as this tutorial continues.
SQL - What is an Operator 
 
Operators are a means by which SQL can manipulate numbers and strings or test for equality. They come infour flavors including: Arithmatic, Range, Equality, and Logical. As your skills with SQL grow, you may want thelanguage to start performing some basic arithmatic for you or perhaps you wish to select a range of rows with anumeric column value larger than 5. This becomes possible with operators.
SQL Code:
SELECT * FROM
table_one
WHEREcolumn_one > 5;
Operators
are used in
expressions
or 
conditional statements
. they show equality, inequality, or a combinationof both. Mathematical operators are found in every computer language and may be familiar to you. SQL operatorsfollow the same rules you may have learned in a math class or know from previous programming experience.Operators come in three flavors, mathematical, logical, or range operations. Mathematical operators add,subtract, multiply, divide, and compare equality of numbers and strings. There are two logical operators,
 AND / OR 
.Range operators include the infamous < and > symbols used to compare equality. Take note of the following tablesfor future reference.
SQL Arithmetic Operators:
OperatorExampleResultDefinition
+7 + 7= 14Addition-7 - 7= 0Subtraction*7 * 7= 49Multiplication/7 / 7= 1Division%7 % 7= 0ModulusModulus may be the only unfamiliar term on the chart. this term describes the result when one number isdivided by another number resulting in a remainder. For example 4 % 3 would result with a value of 1 since 1 is leftover after 4 is divided by 3.
SQL Range Operators:
OperatorExampleDefinedResult
<7 < 47 less than 4?False>7 > 4greater than 4?True<=7 <= 11Is 7 less than or equal to 11?True>=7 >= 11Is 7 greater than or equal to 11?False
SQL Equality Operators:
OperatorExampleDefinedResult
=5 = 5Is 5 equal to 5?True<>7 <> 2Is 7 not equal to 2?True
SQL Logical Operators:
OperatorDefinedExample
ANDAssociates two values using ANDif (($x AND $y) == 5)...ORAssociates two values using ORif (($x OR $y) == 5)...
SQL - Expressions
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more