Giter Site home page Giter Site logo

tldguy-createtable's Introduction

Background

As of right now, all of the data that we are storing into variables in java are lost when the application ends. We need a tool that will allow us to persist data permanently. This tool is called a database. The specific type of database we will be utilizing uses a language called SQL.

SQL stands for Structured Query Language.

Before we store or retrieve any data, we need to define the format in which it is stored. SQL utilizes tables as its format. This follows a similar format to a spreadsheet. The tables will have rows and columns.

A column defines one attribute of a table. A row defines a one complete item in the table.

Let's create our first SQL table. The syntax for Creating a table is as follows:

CREATE TABLE table_name(
     variable_name datatype constraint,
     ...
);

Note: there are two terms above that we need clarity on:

  • datatype:
    • A datatype defines what type of data we will be storing into this specific column.
    • Common datatypes:
      • int: stores whole numbers
      • double precision: stores decimal numbers
      • varchar(100): stores a string of 100 characters maximum
      • boolean: stores true and false values
  • constraint:
    • a constraint is a rule we can add to a column that anyone who wants to insert records into this table must follow
    • Common Constraints:
      • NOT NULL: the column must have a value when inserting a record
      • UNIQUE: every record in a specific column must have a unique value
    • If a constraint that was defined is not met when inserting a record, a SQLException will be thrown.

Additional reference material if needed:


Lab

Problem 1

song table

title artist
Let it be Beatles
Imagine Beatles

Problem 1: Create a new table in the "problem1.sql" file called "song" with 2 columns "Title" and "Artist" (shown above). Both columns should have the datatype varchar(255), which represents a String of up to 255 characters.

tldguy-createtable's People

Contributors

kevinchilds avatar tldguy avatar revvingupthathill avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.