當前位置:首頁 » 編程語言 » sql資料庫基本命令
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql資料庫基本命令

發布時間: 2023-04-01 12:24:18

sql資料庫常用命令及語法舉例

下面是一些常用的SQL語句,雖然很基礎,可是卻很值得收藏,對於初學者非常實用

⑵ 用sql創建資料庫的命令

1、使用create
database語句創建資料庫最簡單的方式,該方式只需要指定database-name參數即可,該參數表示要創建的資料庫的名稱,其他與資料庫有關的選項都採用系統的默認值。
2、如果希望在創建資料庫時明確指定資料庫的文件和這些文件的大小以及增長的方式,就需要了解create
database語句的語法。
3、在語法格式中,每一種特定的符號都表示特殊的含義。
使用create
database語句創建資料庫:
1、
打開【sql
server
management
studio】窗口,並連接到伺服器。選擇【文件】→【新建】→【資料庫引擎查詢】命令或者單擊標准工具欄上的【新建查詢】按鈕,創建一個查詢輸入窗口,在窗口內輸入語句,創建「新建的數據1」資料庫,保存位置為「c」。
2、單擊【執行】按鈕執行語句,如果執行成功,在查詢窗口的【查詢】中可以看到「命令以成功完成」。的提示信息框。在【對象資源管理器】窗口中書涮新,展開資料庫節點就可以看到新建的數據了。

⑶ sql分離資料庫的命令怎麼寫

對於用存儲過程來分離資料庫,如果發現無法終止用戶鏈接,可以使用ALTER DATABASE命令,並利用一個能夠中斷已存在鏈接的終止選項來把資料庫設置為SINGLE_USER模式,褲猜設置為SIGLE_USER代碼如下:

ALTER DATABASE [DatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

下面是分離資料庫的CMD命令

EXEC sp_detach_db DatabaseName

一伍純或旦一個資料庫分離成腔伍功,從SQL Server角度來看和刪除這個資料庫沒有什麼區別。

⑷ 列出sql資料庫user中的表的命令為

列出sql資料庫user中的表的搭孫亂命令為:describe user
SQL是英文Structured Query Language的縮寫,意思為結構化查詢語言。SQL語言的主要功凱世能就是同各種資料庫建立聯系,進行溝通。按照ANSI(美國知檔國家標准協會)的規定,SQL被作為關系型資料庫管理系統的標准語言。SQL Server是由Microsoft開發和推廣的關系資料庫管理系統(RDBMS)。

⑸ SQL一些簡單資料庫命令

  • 命令:

    select

    sql 資料庫查詢表格的命令:用SELECT 語句

  • 用法:

    查詢某一列:SELECT 列名稱 FROM 表名稱

    查詢所有列:SELECT * FROM 表名稱

  • 注釋:

    SQL 語句對大小寫不敏感。SELECT 等效於 select。

⑹ SQL資料庫語句大全

SQL資料庫語句大全:

1、選擇:select * from table1 where 范圍

2、插入:insert into table1(field1,field2) values(value1,value2)

3、刪除:delete from table1 where 范圍

4、更新:update table1 set field1=value1 where 范圍

5、排序:select * from table1 order by field1,field2 [desc]

6、總數:select count as totalcount from table1

7、求和:select sum(field1) as sumvalue from table1

⑺ MySQL 資料庫常用命令 簡單超級實用版

1、MySQL常用命令
create
database
name;
創建資料庫
use
databasename;
選擇資料庫
drop
database
name
直接刪除資料庫,不提醒
show
tables;
顯示表
describe
tablename;
表的詳細描述
select
中加上distinct去除重復欄位
mysqladmin
drop
databasename
刪除資料庫前,有提示。
顯示當前mysql版本和當前日期
select
version(),current_date;
2、修改mysql中root的密碼:
shell>mysql
-u
root
-p
mysql>
update
user
set
password=password(」xueok654123″)
where
user='root';
mysql>
flush
privileges
//刷新資料庫
mysql>use
dbname;
打開資料庫:
mysql>show
databases;
顯示所有資料庫
mysql>show
tables;
顯示資料庫mysql中所有的表:先use
mysql;然後
mysql>describe
user;
顯示表mysql資料庫中user表的列信息);
3、grant
創建一個可以從任何地方連接伺服器的一個完全的超級用戶,但是必須使用一個口令something做這個
mysql>
grant
all
privileges
on
*.*
to
user@localhost
identified
by
'something'
with
增加新用戶
格式:grant
select
on
資料庫.*
to
用戶名@登錄主機
identified
by
「密碼」
GRANT
ALL
PRIVILEGES
ON
*.*
TO
monty@localhost
IDENTIFIED
BY
'something'
WITH
GRANT
OPTION;
GRANT
ALL
PRIVILEGES
ON
*.*
TO
monty@」%」
IDENTIFIED
BY
'something'
WITH
GRANT
OPTION;
刪除授權:
mysql>
revoke
all
privileges
on
*.*
from
root@」%」;
mysql>
delete
from
user
where
user=」root」
and
host=」%」;
mysql>
flush
privileges;
創建一個用戶custom在特定客戶端it363.com登錄,可訪問特定資料庫fangchandb
mysql
>grant
select,
insert,
update,
delete,
create,drop
on
fangchandb.*
to
custom@
it363.com
identified
by

passwd'
重命名表:
mysql
>
alter
table
t1
rename
t2;
4、mysqlmp
備份資料庫
shell>
mysqlmp
-h
host
-u
root
-p
dbname
>dbname_backup.sql
恢復資料庫
shell>
mysqladmin
-h
myhost
-u
root
-p
create
dbname
shell>
mysqlmp
-h
host
-u
root
-p
dbname
<
dbname_backup.sql
如果只想卸出建表指令,則命令如下:
shell>
mysqladmin
-u
root
-p
-d
databasename
>
a.sql
如果只想卸出插入數據的sql命令,而不需要建表命令,則命令如下:
shell>
mysqladmin
-u
root
-p
-t
databasename
>
a.sql
那麼如果我只想要數據,而不想要什麼sql命令時,應該如何操作呢?

mysqlmp
-T./
phptest
driver
其中,只有指定了-T參數才可以卸出純文本文件,表示卸出數據的目錄,./表示當前目錄,即與mysqlmp同一目錄。如果不指定driver
表,則將卸出整個資料庫的數據。每個表會生成兩個文件,一個為.sql文件,包含建表執行。另一個為.txt文件,只包含數據,且沒有sql指令。
5、可將查詢存儲在一個文件中並告訴mysql從文件中讀取查詢而不是等待鍵盤輸入。可利用外殼程序鍵入重定向實用程序來完成這項工作。例如,如果在文件my_file.sql
中存放有查
詢,可如下執行這些查詢:
例如,如果您想將建表語句提前寫在sql.txt中:
mysql
>
mysql
-h
myhost
-u
root
-p
database
<
sql.txt

⑻ sql資料庫的基本操作

命令行
1、顯示當前資料庫伺服器中的資料庫列表:mysql> SHOW DATABASES;
2、建立資料庫:mysql> CREATE DATABASE 庫名;
3、建立數據表:mysql> USE 庫名;mysql> CREATE TABLE 表名 (欄位名 VARCHAR(20), 欄位名 CHAR(1));
4、刪除資料庫:mysql> DROP DATABASE 庫名;
5、刪除數據表:mysql> DROP TABLE 表名;
6、將表中記錄清空:mysql> DELETE FROM 表名;
7、往表中插入記錄:mysql> INSERT INTO 表名 VALUES ("hyq","M");
8、更新表中數據:mysql-> UPDATE 表名 SET 欄位名1='a',欄位名2='b' WHERE 欄位名3='c';
9、用文本方式將數據裝入數據表中:mysql> load data local infile "d:/mysql.txt" into table 表名;
10、導入.sql文件命令:mysql> USE 資料庫名;mysql> source d:/mysql.sql;
11、命令行修改root密碼:mysql> update mysql.user set password=password('新密碼') where user='root';mysql> flush privileges;
12.修改密碼的三種方法:mysql>update user set password=password('123456') where user='joy_pen';mysql>flush privileges;mysql>set password for 'joy_oen'=password('123456');mysql>grant usage on *.* to 'joy_pen' identified by '123456';
1、創建資料庫
命令:create database <資料庫名> 例如:建立一個名為xhkdb的資料庫mysql> create database xhkdb;
2、顯示所有的資料庫
命令:show databases (注意:最後有個s)mysql> show databases;
3、刪除資料庫
命令:drop database <資料庫名> 例如:刪除名為 xhkdb的資料庫mysql> drop database xhkdb;
4、連接資料庫
命令: use <資料庫名> 例如:如果xhkdb資料庫存在,嘗試存取它:mysql> use xhkdb; 屏幕提示:Database changed
5、當前選擇(連接)的資料庫mysql> select database();
6、當前資料庫包含的表信息:mysql> show tables; (注意:最後有個s)
三、表操作,操作之前應連接某個資料庫
1、建表
命令:create table <表名> ( <欄位名1> <類型1> [,..<欄位名n> <類型n>]);
mysql> create table MyClass(
> id int(4) not null primary key auto_increment,
> name char(20) not null,
> sex int(4) not null default ''0'',
> degree double(16,2));
2、獲取表結構
命令: desc 表名,或者show columns from 表名
mysql>DESCRIBE MyClass
mysql> desc MyClass;
mysql> show columns from MyClass;
3、刪除表
命令:drop table <表名>
例如:刪除表名為 MyClass 的表 mysql> drop table MyClass;
4、插入數據
命令:insert into <表名> [( <欄位名1>[,..<欄位名n > ])] values ( 值1 )[, ( 值n )]
例如,往表 MyClass中插入二條記錄, 這二條記錄表示:編號為1的名為Tom的成績為96.45, 編號為2 的名為Joan 的成績為82.99,編號為3 的名為Wang 的成績為96.5.
mysql> insert into MyClass values(1,'Tom',96.45),(2,'Joan',82.99), (2,'Wang', 96.59);
5、查詢表中的數據
1)、查詢所有行
命令: select <欄位1,欄位2,...> from < 表名 > where < 表達式 >
例如:查看錶 MyClass 中所有數據 mysql> select * from MyClass;
2)、查詢前幾行數據
例如:查看錶 MyClass 中前2行數據
mysql> select * from MyClass order by id limit 0,2;
6、刪除表中數據
命令:delete from 表名 where 表達式
例如:刪除表 MyClass中編號為1 的記錄
mysql> delete from MyClass where id=1;
7、修改表中數據:update 表名 set 欄位=新值,… where 條件
mysql> update MyClass set name=''Mary'' where id=1;
8、在表中增加欄位:
命令:alter table 表名 add 欄位 類型 其他;
例如:在表MyClass中添加了一個欄位passtest,類型為int(4),默認值為0
mysql> alter table MyClass add passtest int(4) default ''0''
9、更改表名:
命令:rename table 原表名 to 新表名;
例如:在表MyClass名字更改為YouClass
mysql> rename table MyClass to YouClass;
更新欄位內容
update 表名 set 欄位名 = 新內容
update 表名 set 欄位名 = replace(欄位名,''舊內容'',''新內容'');

⑼ sql.server2016中,打開資料庫的命令是

usedatabase。
根據cmd命令行模式操作sqlserver資料庫內容可知,SQLServer2016中,打開資料庫的命令是usedatabase,刪除資料庫的命令是DROPDATABASE。
SQL是英文StructuredQueryLanguage的縮寫,意思為結構化查詢語言。SQL語言的主要功能就是同各種資料庫建立聯系。

⑽ mysql常用命令都有哪些

1.導出整個資料庫
mysqlmp-u用戶名-p–default-character-set=latin1資料庫名》導出的文件名(資料庫默認編碼是latin1)23mysqlmp-uwcnc-psmgp_apps_wcnc》wcnc.sql
2.導出一個表
mysqlmp-u用戶名-p資料庫名表名》導出的文件名23mysqlmp-uwcnc-psmgp_apps_wcncusers》wcnc_users.sql
3.導出一個資料庫結構
mysqlmp-uwcnc-p-d–add-drop-tablesmgp_apps_wcnc》d:wcnc_db.sql23-d沒有數據–add-drop-table在每個create語句之前增加一個droptable
4.導入資料庫
A:常用source命令23進入mysql資料庫控制台,45如mysql-uroot-p67mysql》use資料庫89然後使用source命令,後面參數為腳本文件(如這里用到的.sql)1011mysql》sourcewcnc_db.sql1213B:使用mysqlmp命令1415mysqlmp-uusername-pdbname《filename.sql1617C:使用mysql命令1819mysql-uusername-p-Ddbname《filename.sql啟動與退出
1、進入MySQL:啟動MySQLCommandLineClient(MySQL的DOS界面),直接輸入安裝時的密碼即可。此時的提示符是:mysql》
2、退出MySQL:quit或exit
5.創建資料庫
命令:createdatabase《資料庫名》
例如:建立一個名為xhkdb的資料庫
mysql》createdatabasexhkdb;
6.顯示所有的資料庫
命令:showdatabases(注意:最後有個s)
mysql》showdatabases;
7.刪除資料庫
命令:dropdatabase《資料庫名》
8.連接資料庫
命令:use《資料庫名》
例如:如果xhkdb資料庫存在,嘗試存取它:
9.查看當前使用的資料庫
mysql》selectdatabase();
10.當前資料庫包含的表信息:
mysql》showtables;(注意:最後有個s)