SQL Advanced Applications (create DATABASE, create TABLE)

Source: Internet
Author: User
Tags sql create database

SQL CREATE DATABASE

Create database is used for creating databases with the following syntax

CREATE DATABASE database_name

Example: Creating a database named Db_test

CREATE DATABASE Db_test

You can add database tables by using CREATE table.

SQL CREATE TABLE

The CREATE TABLE statement creates a table in the database with the following syntax

CREATE TABLE table_name (    column name 1 data type,    column name 2 data type,    column name 3 data type,    ...)

The data type (DATA_TYPE) specifies what data type the column content holds, and the table below contains the most commonly used data types in SQL

Data Type Description

Integer (size)

int (size)

smallint (size)

tinyint (size)

Holds integers only. Specify the maximum number of digits within the parentheses.

Decimal (SIZE,D)

Numeric (SIZE,D)

Accommodates numbers with decimals.

"Size" Specifies the maximum number of digits. "D" Specifies the maximum number of digits to the right of the decimal point.

char (size)

Holds a fixed-length string (which can hold letters, numbers, and special characters).

Specifies the length of the string in parentheses.

varchar (size)

Accommodates variable-length strings that can hold letters, numbers, and special characters.

Specifies the maximum length of the string in parentheses.

Date (YYYYMMDD) accommodate the date.

CREATE Table Instance

Create a table named "Persons" that contains 5 columns with the column names: Id_p, LastName, FirstName, Address, city

CREATE TABLE (    id_p int,    LastName varchar (255),    FirstName varchar (255),    Address varchar (255)    , City varchar (255))

The data type of the id_p column is int, which contains integers. The data type of the remaining 4 columns is varchar, with a maximum length of 255 characters.

An empty "Persons" table looks like this:

City
id_p LastName FirstName Address

You can use the INSERT into statement to write data to an empty table.

SQL Advanced Applications (create DATABASE, create TABLE)

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.