溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

在數(shù)據(jù)庫(kù)中sql的九個(gè)常用語(yǔ)句是什么

發(fā)布時(shí)間:2021-01-15 09:43:55 來(lái)源:億速云 閱讀:354 作者:小新 欄目:數(shù)據(jù)庫(kù)

這篇文章給大家分享的是有關(guān)在數(shù)據(jù)庫(kù)中sql的九個(gè)常用語(yǔ)句是什么的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

一、基礎(chǔ)
1、說(shuō)明:創(chuàng)建數(shù)據(jù)庫(kù)
CREATE DATABASE database-name
2、說(shuō)明:刪除數(shù)據(jù)庫(kù)
drop database dbname
3、說(shuō)明:備份sql server
--- 創(chuàng)建 備份數(shù)據(jù)的 device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- 開(kāi)始 備份
BACKUP DATABASE pubs TO testBack
4、說(shuō)明:創(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、說(shuō)明:刪除新表
drop table tabname
6、說(shuō)明:增加一個(gè)列
Alter table tabname add column col type
注:列增加后將不能刪除。DB2中列加上后數(shù)據(jù)類(lèi)型也不能改變,唯一能改變的是增加varchar類(lèi)型的長(zhǎng)度。
7、說(shuō)明:添加主鍵: Alter table tabname add primary key(col)
說(shuō)明:刪除主鍵: Alter table tabname drop primary key(col)
8、說(shuō)明:創(chuàng)建索引:create [unique] index idxname on tabname(col….)
刪除索引:drop index idxname
注:索引是不可更改的,想更改必須刪除重新建。
9、說(shuō)明:創(chuàng)建視圖:create view viewname as select statement
刪除視圖:drop view viewname

感謝各位的閱讀!關(guān)于“在數(shù)據(jù)庫(kù)中sql的九個(gè)常用語(yǔ)句是什么”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI