In layman's SQL note-Data and tables

Source: Internet
Author: User

1. The concept and composition of the database

A database is a container for saving tables and other related SQL structures.
Databases are made up of a variety of tables, and tables in a database are always interconnected.
The information in the database consists of a table consisting of rows and columns, a set of Rillie that describe a thing, a property of an object, and a column of data stored in a table.
Note that the column is also called: field, row is also called attribute.

2. Steps to create a table:

1. Classify the data before creating the table, paying particular attention to the data type of each column.
2. Using the CREATE DATABASE statement, create the databases that store all the tables.
Create a database named Gregs_list, and note the semicolon at the end of the following.

3. Enter the database using the USE DATABASE statement and create the table.

4. All tables are built with the CREATE TABLE statement, which contains the column names and their data types.

5. Some common data types are char, VARCHAR, BLOG, INT, DEC, DATE, DATETIME, storage rules for each data type are different
CHAR (size): Saves fixed-length characters, with a string length of up to 255 characters in parentheses.
VARCHAR (size): holds a variable-length string, specifying the maximum length of the string in parentheses, up to 255, or the text type if it is worth more than 255.
BLOG: Store A large number of text databases.
INT: The number should be an integer, including integers and negative numbers.
DEC (NUM1, num2): Saves floating-point numbers, the first NUM1 represents the total number of digits, and the second num2 represents the number of digits after the decimal point.
Date: Dates in the format: YYYY-MM-DD
DateTime: Combination of date and time: Yyyy-mm-dd HH:MM:SS.

3. Deleting and displaying a database

1. Delete a database or a table in a database
Syntax: DROP database name
DROP Table Name
2. Check to display the previously created table:

4. Inserting data

Both the database and the table have been created, and the rest is adding data to the table, adding the data with the INSERT keyword.
Grammar:
INSERT into Your_table (column_name1, column_name2,...... )
VALUES (' value1 ', ' value2 ', ...)
Attention:
1. The value inside the second set of parentheses must be the same as the column name.
2. Quotes are not required for int and Dec types only.
Three ways to insert:
1. We can change the order of the columns, as long as we remember that the data refers to the order to be adjusted together.

2. The list name can be omitted, but the data must be fully populated and must be identical to the order in which the table was created.

3. Omit part of the column, that is, you can fill in some of the column values just fine

About NULL

Null means undefined, that is, no information has been filled in, it is not known whether it is empty or what number, the place is waiting for input data. Null is a different and null value, and a null value indicates that it has been assigned, but NULL means that no assignment has been made.
Because it is not assigned, it is not possible to compare.
We can restrict the column from being defined by adding not NULL in the column.
If the default value is listed, we can use default to set the initial default value, and if no assignment is made, it is used.
CREATE TABLE Doughnut_list
(
Doughnut_cost DEC (3,2) not NULL DEFAULT 1.00
)

In layman's SQL note-Data and tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.