Basic operations of the database

Source: Internet
Author: User

Basic operations of the database

1. Database--Table structure--Fields (columns)

2. Each row of data represents a single piece of data (record)

One. Create

> New Database

Select Link--Right click--Create Database--Enter the name of the database you need--(if you choose a MySQL database, you need to choose a character set)--Character Set Select "UTF-8" (recommended) or "GBK"--Determine

> Storage Data

New database Double click to open--table--right--Create a table (you can write a paragraph)

Length: The maximum number of characters in this string, (arbitrary length, general write 50)

> Create a field or insert a field

> Save (or Ctrl+s)

> table name--OK

> Return to the page that created the table again-click the Design table (or right-click the design table)

Two. Manually add data

> Open a table (or double-click)

> Manually enter data

> below ' + '--add again; ' √ ' to save.

Three. Implement database creation by code (query--Find database--click Create query (the code executed in the database is called query))

T-SQL statement: is a generic database operation statement

1. Create a table:

CREATE TABLE Family

(

Code varchar (primary key,//primary key: Primary key column

Name varchar (not NULL),//not null: Non-empty

Sex bit

);

CREATE TABLE Nation

(

Code varchar (primary key),

Name varchar (50)

);

CREATE TABLE Info

(

Code int Auto_increment PRIMARY KEY,//self-growing column, integer data, default starting from 1, typically as primary key column

Name varchar (50),

Sex bit,

Brithday date,

Height float,

Nation varchar (references) Nation (code)//references Nation (code) is called: foreign key

)

Note: Between two tables is two batches, if you want to link the two statements need to add a semicolon ";", and the last field after you finish writing do not add a comma ","

Features of the database

1. Relational database, with strict specifications

2. Each table must have a primary key (primary key column): A field that uniquely identifies a single piece of data

3. Primary key cannot be added repeatedly

4. A relationship between a table and a table (example: Nation in an info table is represented by a number, another nation table stores the actual information, nation the relationship between the table and the Info table), and the table that controls the other table is called the primary table (Nation table). Another table is called a foreign key relationship---from a table (info table)

> Save

Keywords that are commonly used

Primary key: Primary key

NOT null: Non-empty

Auto_increment: Self-growing column, must be integral, auto-grow without adding

References: referencing foreign key relationships

Note: In SQL, no matter which database, there is no string data type, to use varchar to represent the string, Boolean type with bit, Boolean type does not write length, the storage date time is represented by date (or DateTime);

An integer int, a decimal float, or a double. Boolean 0 and 1, datetime representation, example: 2016-01-17; generally only carchar need to write length, others do not

Basic operations of the database

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.