SQL学习笔记——DDL
文章目录
1. CREATE DATABASE Syntax
• CREATE DATABASE database_name
2. CREATE TABLE Syntax
• CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
)
3. SQL Constraints
• NOT NULL - cannot insert a new record, or update a record without adding a value to this field
• UNIQUE - uniquely identifies each record in a table
• PRIMARY KEY
• FOREIGN KEY (REFERENCES) - points to a PRIMARY KEY in another table
• CHECK - is used to limit the value range that can be placed in a column
• DEFAULT - is used to insert a default value into a column
4. SQL Indexs
(1) An index can be created in a table to find data more quickly and efficiently
(2) CREATE INDEX Syntax:
• CREATE INDEX index_name ON table_name(column_name)
• CREATE UNIQUE INDEX index_name ON table_name(column_name)
(3) DROP INDEX Syntax:
• DROP INDEX index_name ON table_name
5. DROP TABLE Syntax
• DROP TABLE table_name
6. DROP DATABASE Syntax
• DROP DATABASE database_name
7. TRUNCATE TABLE Syntax
• TRUNCATE TABLE table_name
8. ALTER TABLE Synta
• ALTER TABLE table_name ADD column_name data_type
• ALTER TABLE table_name DROP column_name
• ALTER TABLE table_name ALTER COLUMN column_name data_type
9. SQL CREATE VIEW
(1) a view is a virtual table based on the result-set of an SQL statement
(2) CREATE VIEW Syntax
• CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
(3) UPDATE VIEW Syntax
• CREATE OR REPLACE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
(4) DROP VIEW Syntax
• DROP VIEW view_name
文章作者 wenzhixin
上次更新 2012-03-09