SQL 指南-创建数据库、表、索引
2006-04-10 10:26
302 查看
创建数据库
CREATE DATABASE database_name |
创建表
在数据库中创建表:CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, ....... ) |
示例
This example demonstrates how you can create a table named "Person", with four columns. The column names will be "LastName", "FirstName", "Address", and "Age":CREATE TABLE Person ( LastName varchar, FirstName varchar, Address varchar, Age int ) |
CREATE TABLE Person ( LastName varchar(30), FirstName varchar, Address varchar, Age int(3) ) |
Data Type | Description |
---|---|
integer(size) int(size) smallint(size) tinyint(size) | Hold integers only. The maximum number of digits are specified in parenthesis. |
decimal(size,d) numeric(size,d) | Hold numbers with fractions. The maximum number of digits are specified in "size". The maximum number of digits to the right of the decimal is specified in "d". |
char(size) | Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. |
varchar(size) | Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. |
date(yyyymmdd) | Holds a date |
Create Index
Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries.Note: Updating a table containing indexes takes more time than updating a table without, this is because the indexes also need an update. So, it is a good idea to create indexes only on columns that are often used for a search.
A Unique Index
Creates a unique index on a table. A unique index means that two rows cannot have the same index value.
CREATE UNIQUE INDEX index_name ON table_name (column_name) |
A Simple Index
Creates a simple index on a table. When the UNIQUE keyword is omitted, duplicate values are allowed.
CREATE INDEX index_name ON table_name (column_name) |
Example
This example creates a simple index, named "PersonIndex", on the LastName field of the Person table:CREATE INDEX PersonIndex ON Person (LastName) |
CREATE INDEX PersonIndex ON Person (LastName DESC) |
CREATE INDEX PersonIndex ON Person (LastName, FirstName) |
相关文章推荐
- mssql2000数据库执行SQL语句来创建数据库以及数据表还有索引
- Oracle11G-SQL开发指南-10-创建表、序列、索引和视图
- SQL语句创建(数据库|数据表|索引)
- SQL指南-删除索引、表、数据库
- SQL 创建索引,遍历数据库所有表
- 手动创建数据库表,索引、设置存储引擎、注释等的sql脚本
- SQL高级教程:SQL 创建数据库、表以及索引
- SQL 创建数据库、表以及索引
- 精通数据库SQL——索引与视图的创建
- SQL 创建数据库、表以及索引
- [zz]SQL 创建数据库、表以及索引
- 在VB.NET中 用代码 利用SQL语句创建数据库、表、存储过程、视图、索引、规则、修改表、查看数据等的方法
- Oracle之SQL基础--创建数据库对象(序列 视图)及索引
- Oracle sql 调优:使用虚拟索引在生产环境测试创建索引对数据库性能的影响
- Oracle sql 调优:使用虚拟索引在生产环境测试创建索引对数据库性能的影响
- 创建数据库、表、主外键、各种约束、存储过程、视图、索引、事务使用、触发器、创建登录账号、数据库用户 Sql语句示例
- sql创建数据库、表、索引、触发器、存储过程学习
- sql优化之:数据库索引创建原则,or/in/union与索引优化,聚集索引/非聚集索引/联合索引/索引覆盖,MySQL冗余数据的三种方案,MySQL双主一致性架构优化(来源:架构师之路)
- 使用SQL脚本创建数据库,操作主键、外键与各种约束(MS SQL Server)
- SQL索引一步到位(此文章为“数据库性能优化二:数据库表优化”附属文章之一)