共計(jì) 968 個(gè)字符,預(yù)計(jì)需要花費(fèi) 3 分鐘才能閱讀完成。
自動(dòng)寫代碼機(jī)器人,免費(fèi)開通
這篇文章給大家分享的是有關(guān)在數(shù)據(jù)庫中 sql 的九個(gè)常用語句是什么的內(nèi)容。丸趣 TV 小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨丸趣 TV 小編過來看看吧。
一、基礎(chǔ)
1、說明:創(chuàng)建數(shù)據(jù)庫
CREATE DATABASE database-name
2、說明:刪除數(shù)據(jù)庫
drop database dbname
3、說明:備份 sql server
— 創(chuàng)建 備份數(shù)據(jù)的 device
USE master
EXEC sp_addumpdevice disk , testBack , c:\mssql7backup\MyNwind_1.dat
— 開始 備份
BACKUP DATABASE pubs TO testBack
4、說明:創(chuàng)建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根據(jù)已有的表創(chuàng)建新表:
A:create table tab_new like tab_old (使用舊表創(chuàng)建新表)
B:create table tab_new as select col1,col2… from tab_old definition only
5、說明:刪除新表
drop table tabname
6、說明:增加一個(gè)列
Alter table tabname add column col type
注:列增加后將不能刪除。DB2 中列加上后數(shù)據(jù)類型也不能改變,唯一能改變的是增加 varchar 類型的長(zhǎng)度。
7、說明:添加主鍵:Alter table tabname add primary key(col)
說明:刪除主鍵:Alter table tabname drop primary key(col)
8、說明:創(chuàng)建索引:create [unique] index idxname on tabname(col….)
刪除索引:drop index idxname
注:索引是不可更改的,想更改必須刪除重新建。
9、說明:創(chuàng)建視圖:create view viewname as select statement
刪除視圖:drop view viewname
感謝各位的閱讀!關(guān)于“在數(shù)據(jù)庫中 sql 的九個(gè)常用語句是什么”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
向 AI 問一下細(xì)節(jié)