In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail about sql table creation method, Xiaobian feel quite practical, so share to everyone as a reference, I hope you can have some harvest after reading this article.
In sql, you can specify TABLE names (column name 1 data type, column name 2 data type,...) "to create a data table.
SQL creates databases, tables, and indexes
create a database
This creates a database:
CREATE DATABASE database name
create a table
This creates a table in the database:
CREATE TABLE table name (column name 1 data type, column name 2 data type,...)
examples
This example demonstrates how to create a table named Person with four columns. Column names are: "LastName,""FirstName,""Address," and "Age":
CREATE TABLE Person (LastName varchar,FirstName varchar,Address varchar,Age int)
This example demonstrates how to define maximum lengths for certain columns:
CREATE TABLE Person (LastName varchar(30),FirstName varchar,Address varchar,Age int(3))
The data type (data_type) specifies what data type the column can hold. The following table contains the most commonly used data types in SQL:
create an index
Indexes are created in existing tables to make locating rows faster and more efficient. You can create indexes on one or more columns of a table, and each index is named. Users cannot see indexes, they can only be used to speed up queries.
Note: Updating a table with an index takes longer than updating a table without an index because the index itself needs to be updated. Therefore, it is desirable to create indexes only on columns that are often used for searching.
Unique Index
Create a unique index on the table. A unique index means that two rows cannot have the same index value.
CREATE UNIQUE INDEX Index Name
ON Table Name (Column Name)
Column Name specifies the column you want to index.
Simple index
Create a simple index on the table. When we omit the keyword UNIQUE, we can use duplicate values.
CREATE INDEX index name
ON Table Name (Column Name)
Column Name specifies the column you want to index.
examples
This will create a simple index named "PersonIndex" in the LastName field of the Person table:
CREATE INDEX PersonIndexON Person (LastName)
If you want to index the values in a column in descending order, you can add the reserved word DESC after the column name:
CREATE INDEX PersonIndexON Person (LastName DESC)
If you want to index more than one column, you can list the column names in parentheses, separated by commas:
CREATE INDEX PersonIndexON Person (LastName, FirstName) About sql table creation method shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.