1.資料庫層面
建立資料庫
create database database-name
刪除資料庫
drop database database-name
2.表建立新錶
create table tablename(col1 type1 [not null] [primary key], col2 type2……)
根據已有的表建立新錶
create table new_tablename as
select col1,col2……
from old_table definition only
刪除表drop table tablename
更新表(增加列)
alter table tablename
add column coltype
新增主鍵約束
alter table tablename
add primary key(col)
刪除主鍵約束
alter table tablename
drop primary key(col)
建立索引
create [unique] index idxname
on tablename(col…)
刪除索引
drop index idxname
常用sql語句整理
a 判斷資料庫是否存在 if exists select from sys.databases where name 庫名 刪除資料庫 drop database 庫名b 判斷要建立的表名是否存在 if exists select from dbo.sysobjects where id objec...
常用SQL語句整理
檢視資料庫 show databases 選擇資料庫 use database name 表定義資訊 describe table name 插入資料 insert into table name filed 1 field n values value 1 value n eg insert in...
常用sql語句整理
查詢 無條件查詢 select from table name 條件查詢 select from table name where 條件 排序查詢 select col1,col2,from table name where 條件 order by 列名 desc asc 模糊查詢 select f...