SQL Server【基礎】DDL 數據定義語言
DDL
操作數據庫,schema,表等語句
Create,Alter,Drop,DECLARE
- database
--1、說明:創建數據庫
Create DATABASE database-name thus
--2、說明:刪除數據庫
drop database dbname
- schema
--1、創建schema
create schema myschema
- table index view
--1、說明:創建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
--根據已有的表創建新表:
create table tab_new like tab_old --(使用舊表創建新表)
create table tab_new as select col1,col2… from tab_old definition only
--2、說明:刪除新表
drop table tabname
--3、說明:增加一個列
Alter table tabname add column col type
--注:列增加后將不能刪除。DB2中列加上后數據類型也不能改變,唯一能改變的是增加varchar類型的長度。
--4、說明:添加主鍵:
Alter table tabname add primary key(col)
--說明:刪除主鍵:
Alter table tabname drop primary key(col)
--5、說明:創建索引:
create [unique] index idxname on tabname(col….)
--刪除索引:
drop index idxname
--注:索引是不可更改的,想更改必須刪除重新建。
--6、說明:創建視圖:
create view viewname as select statement
--刪除視圖:
drop view viewname
浙公網安備 33010602011771號