Friday, May 31, 2019

SQL Summary(3)



SQL Summary(3)
Stored Procedure
Related image     stored procedure which calls by itself until it reaches some boundary condition. This recursive function or procedure helps programmers to use the same set of code any number of times.Stored procedure can be used as a modular programming – means create once, store and call for several times whenever required. This supports faster execution instead of executing multiple queries. This reduces network traffic and provides better security to the data. Howeverit can be executed only in the Database and utilizes more memory in the database server.

Online Transaction Processing (OLTP)
     Online Transaction Processing (OLTP) manages transaction based applications which can be used for data entry, data retrieval and data processing. OLTP makes data management simple and efficient. Unlike OLAP systems goal of OLTP systems is serving real-time transactions. An example will be shopping online and use card to pay for it on a transaction webpage.

CLAUSE
     SQL clause is defined to limit the result set by providing condition to the query. This usually filters some rows from the whole set of records.

   I think this three is the most important one and the ones that are the most connected to our daily life. As this three affects online shopping, the storage of the device and also cloud disks.

What I'll be doing tomorrow?
I will be reviewing more SQL summaries tomorrow.

SQL(6)---Queries with constraints

Queries with constraints
SQL supports a number of useful operators to do things like case-insensitive string comparison and wildcard pattern matching.
I am reviewing the operators again as I really want to do better in quizzes. And so I found the notes for it and decided to repost it again.

May--->June Post

May--->June Post
     In May,  I have tried to master another programming language which is SQL. SQL is a language that allows programmers to set up tables in rows. This language is useful for statistic, as it allows you to find what you want easily in simple codes. However, after I did the quiz, I noticed that I am not fully mastered in the theories about the language. But I think I am still able to use the codes correctly if I need to.
     In June, Since this is going to be a short month. I am planning to post things about the website that I was trying to working on on Sublime Text on my laptop. I am stuck with the structure and classes of the website at the moment, but I believe that I will be able to overcome this soon. And I will be posting pictures about the process。

SQL Summary(4)

 SQL Summary(4)
Data Integrity
     Data Integrity defines the accuracy and consistency of data stored in a database. It can also define integrity constraints to enforce business rules on the data when it is entered into the application or database.
Image result for constraint in database

Auto Increment
     Auto increment keyword allows the user to create a unique number to be generated when a new record is inserted into the table. AUTO INCREMENT keyword can be used in Oracle and IDENTITY keyword can be used in SQL SERVER. Mostly this keyword can be used whenever PRIMARY KEY is used.

Cluster and Non-Cluster Index
     Clustered index is used for easy retrieval of data from the database by altering the way that the records are stored. Database sorts out rows by the column which is set to be clustered index.
     A nonclustered index does not alter the way it was stored but creates a complete separate object within the table. It point back to the original table rows after searching.
Datawarehouse
     Datawarehouse is a central repository of data from multiple sources of information. Those data are consolidated, transformed and made available for the mining and online processing. Warehouse data have a subset of data called Data Marts.
Image result for data warehouse
Joins 
  • Self-join is set to be query used to compare to itself. This is used to compare values in a column with other values in the same column in the same table. ALIAS ES can be used for the same table comparison.
  • Cross join defines as Cartesian product where number of rows in the first table multiplied by number of rows in the second table. If suppose, WHERE clause is used in cross join then the query will work like an INNER JOIN.
User defined functions

     User defined functions are the functions written to use that logic whenever required. It is not necessary to write the same logic several times. Instead, function can be called or executed whenever needed.

  • Scalar Functions.
  • Inline Table valued functions.
  • Multi statement valued functions.

Collation

     Collation is defined as set of rules that determine how character data can be sorted and compared. This can be used to compare A and, other language characters and also depends on the width of the characters. ASCII value can be used to compare these character data.


Types of collation sensitivity

  • Case Sensitivity – A and a and B and b.
  • Accent Sensitivity.
  • Kana Sensitivity – Japanese Kana characters.
  • Width Sensitivity – Single byte character and double byte character.

Why did I take all these notes?

   The reason why I took these notes is because of a SQL quiz that I took. I got a lot of it wrong after just taking lessons from Codecademy. And so, I looked up the lesson page for the quiz that I took which is from a few different websites. Which includes w3schools and other ones. The key words and points in these three summaries that I wrote are all the important notes that should be memorized for doing other SQL quizzes.

Wednesday, May 29, 2019

SQL Summary(2)

SQL Summary(2)
View
     A view is a virtual table which consists of a subset of data contained in a table. Views are not virtually present, and it takes less space to store. View can have data of one or more tables combined, and it is depending on the relationship.
Index
     An index is performance tuning method of allowing faster retrieval of records from the table. An index creates an entry for each value and it will be faster to retrieve data.

Indexes





  • Unique Index
  • This indexing does not allow the field to have duplicate values if the column is unique indexed. Unique index can be applied automatically when primary key is defined.
    • Clustered Index
    This type of index reorders the physical order of the table and search based on the key values. Each table can have only one clustered index.
    • NonClustered Index
    NonClustered Index does not alter the physical order of the table and maintains logical order of data. Each table can have 999 nonclustered indexes.

    Cursor
         A database Cursor is a control which enables traversal over the rows or records in the table. This can be viewed as a pointer to one row in a set of rows. Cursor is very much useful for traversing such as retrieval, addition and removal of database records.

    Database Relationships

    • One to One Relationship.
    • One to Many Relationship.
    • Many to One Relationship.
    • Self-Referencing Relationship.
    DB query
         A DB query is a code written in order to get the information back from the database. Query can be designed in such a way that it matched with our expectation of the result set. Simply, a question to the Database.

    Subquery
         A subquery is a query within another query. The outer query is called as main query, and inner query is called subquery. SubQuery is always executed first, and the result of subquery is passed on to the main query.

    • A correlated subquery cannot be considered as independent query, but it can refer the column in a table listed in the FROM the list of the main query.
    • A Non-Correlated subquery can be considered as independent query and the output of subquery are substituted in the main query.
    Stored procedure
         Stored Procedure is a function consists of many SQL statement to access the database system. Several SQL statements are consolidated into a stored procedure and execute them whenever and wherever required.

    DB trigger
         A DB trigger is a code or programs that automatically execute with response to some event on a table or view in a database. Mainly, trigger helps to maintain the integrity of the database.
    Image result for trigger in database

    What is the difference between DELETE and TRUNCATE commands?
         DELETE command is used to remove rows from the table, and WHERE clause can be used for conditional set of parameters. Commit and Rollback can be performed after delete statement.
         TRUNCATE removes all rows from the table. Truncate operation cannot be rolled back.
    What are local and global variables and their differences?
         Local variables are the variables which can be used or exist inside the function. They are not known to the other functions and those variables cannot be referred or used. Variables can be created whenever that function is called.
         Global variables are the variables which can be used or exist throughout the program. Same variable declared in global cannot be used in functions. Global variables cannot be created whenever that function is called.
    Constraint
    Constraint can be used to specify the limit on the data type of table. Constraint can be specified while creating or altering the table statement. Sample of constraint are.
    • NOT NULL.
    • CHECK.
    • DEFAULT.
    • UNIQUE.
    • PRIMARY KEY.
    • FOREIGN KEY.
    What I'll be doing tomorrow?
    I will be continuing doing the SQL summary and reasons will be explained why I  am doing this summary.

    Tuesday, May 28, 2019

    SQL Summary(1)

    SQL Summary(1)

    DBMS
         A Database Management System (DBMS) is a program that controls creation, maintenance and use of a database. DBMS can be termed as File Manager that manages data in a database rather than saving it in file systems.

    Image result for database
    RDBMS
         RDBMS stands for Relational Database Management System. RDBMS store the data into the collection of tables, which is related by common fields between the columns of the table. It also provides relational operators to manipulate the data stored into the tables.

    Database 
         Database is nothing but an organized form of data for easy access, storing, retrieval and managing of data. This is also known as structured form of data which can be accessed in many ways.

    KEYS
    • Primary key
    A primary key is a combination of fields which uniquely specify a row. This is a special kind of unique key, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.

    • Unique key
    A Unique key constraint uniquely identified each record in the database. This provides uniqueness for the column or set of columns.

    • Foreign key
    A foreign key is one table which can be related to the primary key of another table. Relationship needs to be created between two tables by referencing foreign key with the primary key of another table.

    JOINS
    • Inner Join
    Inner join return rows when there is at least one match of rows between the tables.
    • Right Join
    Right join return rows which are common between the tables and all rows of Right hand side table. Simply, it returns all the rows from the right hand side table even though there are no matches in the left hand side table.
    • Left Join
    Left join return rows which are common between the tables and all rows of Left hand side table. Simply, it returns all the rows from Left hand side table even though there are no matches in the Right hand side table.
    • Full Join
    Full join return rows when there are matching rows in any one of the tables. This means, it returns all the rows from the left hand side table and all the rows from the right hand side table.
    • What is a join?
    This is a keyword used to query data from more tables based on the relationship between the fields of the tables. Keys play a major role when JOINs are used.

    Normalization
    Normalization is the process of minimizing redundancy and dependency by organizing fields and table of a database. The main aim of Normalization is to add, delete or modify field that can be made in a single table.

    Denormalization
    Denormalization is a technique used to access the data from higher to lower normal forms of database. It is also process of introducing redundancy into a table by incorporating data from the related tables.

    Different Normalizations
    Related image
    • First Normal Form (1NF):
    This should remove all the duplicate columns from the table. Creation of tables for the related data and identification of unique columns.
    • Second Normal Form (2NF):
    Meeting all requirements of the first normal form. Placing the subsets of data in separate tables and Creation of relationships between the tables using primary keys.
    • Third Normal Form (3NF):
    This should meet all requirements of 2NF. Removing the columns which are not dependent on primary key constraints.
    • Fourth Normal Form (3NF):
    Meeting all the requirements of third normal form and it should not have multi- valued dependencies.

    What I'll be doing tomorrow?
      I will be continue doing the summary of the SQL because I got a really low mark on the quiz which is like 10%. So I decided to gather the notes of SQL and try memorize it then do the quiz again.

    Monday, May 27, 2019

    Self practice website

    After a few days of class, flex and lunch time. This is what I came to so far...

    And this is what it looks like:
    file:///Users/crystalzhang/Desktop/html%20files/index.html

    What my plan is after this is I want to learn more about designing the website. Because the website right now is just a basic format and does not have lots of design. Big companies would never use a website like this.

    Self practice project starting statement

    I kind of got tired of learning and blogging a new lesson everyday. So I decided to do something different that is more fun to me and allows me to review what I have learned in the first two units. And so, I am going to---build a website.

    This website is going to be about online shopping. I am going to make this web page an info page for a few of the shopping websites and also what they sell. The three website that I'm going to pick is Ebay, Amazon and Taobao.

    And I am going to build this website from scratch which means only with code and nothing else.

    Thursday, May 23, 2019

    SQL(5)---Queries with constraints EXAMPLE

    Queries with constraints
    EXAMPLE:

    • Find the movie with a row id of 6

    SELECT id, title FROM movies 
    WHERE id = 6;

    The table will look like:


  • Find the movies released in the year between 2000 and 2010


  • SELECT title, year FROM movies
    WHERE year BETWEEN 2000 AND 2010;

    The table will look like:



  • Find the movies not released in the years between 2000 and 2010

  • SELECT title, year FROM movies
    WHERE year < 2000 OR year > 2010;

    The table will look like:

  • Find the first 5 Pixar movies and their release year



  • SELECT title, year FROM movies 
    WHERE year <= 2003;



    The table will look like:

    NOTES: This was the example that I looked at to help my understanding of the lesson. 
    What I'll be doing tomorrow?
    Queries with constraints

    Wednesday, May 22, 2019

    SQL(4)---Manipulation

    Manipulation
    In order to create a Table, we use the code below:
    CREATE TABLE celebs ( id INTEGER, name TEXT, age INTEGER );

    The words in yellow can be replaced by other variable words and values.

    Then, to insert a row into the table, we use the code below:
    INSERT INTO celebs (id, name, age) VALUES (1, 'Justin Bieber', 22);

    The value row is the values you would put into the row of that table.

    Add columns to a table, we use:
    ALTER TABLE celebs ADD COLUMN twitter_handle TEXT; SELECT * FROM celebs;
    1. ALTER TABLE is a clause that lets you make the specified changes.
    2. celebs is the name of the table that is being changed.
    3. ADD COLUMN is a clause that lets you add a new column to a table: 
    • twitter_handle is the name of the new column being added
    • TEXT is the data type for the new column
    4. NULL is a special value in SQL that represents missing or unknown data. Here, the rows that existed before the column was added have NULL values for twitter_handle.
    The ALTER TABLE statement adds a new column to a table.

    Change existing records, we use:
    UPDATE celebs SET twitter_handle = '@taylorswift13' WHERE id = 4; SELECT * FROM celebs;



    1. UPDATE is a clause that edits a row in the table. 
    2. celebs is the name of the table. 
    3. SET is a clause that indicates the column to edit.

    The UPDATE statement edits a row in a table.

    Delete existing records, we use:
    DELETE FROM celebs WHERE twitter_handle IS NULL; SELECT * FROM celebs;
    1. DELETE FROM is a clause that lets you delete rows from a table.
    2. celebs is the name of the table we want to delete rows from.
    3. WHERE is a clause that lets you select which rows you want to delete. Here we want to delete all of the rows where the twitter_handle column IS NULL.
    4.IS NULL is a condition in SQL that returns true when the value is NULL and false otherwise.
    The DELETE FROM statement deletes one or more rows from a table.

    Used to tell the database to reject inserted data that does not adhere to a certain restriction.
    CREATE TABLE awards ( id INTEGER PRIMARY KEY, recipient TEXT NOT NULL, award_name TEXT DEFAULT 'Grammy' );
    1. PRIMARY KEY columns can be used to uniquely identify the row. Attempts to insert a row with an identical value to a row already in the table will result in a constraint violation which will not allow you to insert the new row.
    2. UNIQUE columns have a different value for every row. This is similar to PRIMARY KEY except a table can have many different UNIQUE columns.
    3. NOT NULL columns must have a value. Attempts to insert a row without a value for a NOT NULL column will result in a constraint violation and the new row will not be inserted.
    4. DEFAULT columns take an additional argument that will be the assumed value for an inserted row if the new row does not specify a value for that column.
    Constraints that add information about how a column can be used are invoked after specifying the data type for a column.

    REVIEW:
    SQL is a programming language designed to manipulate and manage data stored in relational databases.
    • relational database is a database that organizes information into one or more tables.
    • table is a collection of data organized into rows and columns.
    statement is a string of characters that the database recognizes as a valid command.
    • CREATE TABLE creates a new table.
    • INSERT INTO adds a new row to a table.
    • SELECT queries data from a table.
    • ALTER TABLE changes an existing table.
    • UPDATE edits a row in a table.
    • DELETE FROM deletes rows from a table.
    Constraints add information about how a column can be used.