国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > MySQL > 正文

MySQL數(shù)據(jù)庫(kù)操作的基本命令

2024-07-24 12:51:51
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

一、創(chuàng)建數(shù)據(jù)庫(kù):

create data data _name;

 php中創(chuàng)建數(shù)據(jù)庫(kù)的兩種方法:(mysql_create_db(),mysql_query())

$conn = mysql_connect(“l(fā)ocalhost”,”username”,”password”) or die ( “could not connect to localhost”); mysql_create_db(“data _name”) or die (“could not create data ”); $string = “create data data _name”; mysql_query( $string) or die (mysql_error());

二、選定數(shù)據(jù)庫(kù)

在創(chuàng)建表之前,必須要選定要?jiǎng)?chuàng)建的表所在的數(shù)據(jù)庫(kù)

選定數(shù)據(jù)庫(kù):

 通過(guò)命令行客戶(hù)端:

use data _name

 通過(guò)

php: mysql_select_db()
$conn = mysql_connect(“l(fā)ocalhost”,”username”,”password”) or die ( “could not connect to localhost”); mysql_select_db(“test”,$conn) or die (“could not select data ”);

三、創(chuàng)建表

create table table_name

如:

create table table_name ( column_1 column_type column attributes, column_2 column_type column attributes, column_3 column_type column attributes, primary key (column_name), index index_name(column_name) )

在命令行客戶(hù)端需要鍵入整個(gè)命令

在php中使用,mysql_query()函數(shù)

如:

$conn = mysql_connect(“l(fā)ocalhost”,”username”,”password”) or die ( “could not connect to localhost”); mysql_select_db(“test”,$conn) or die (“could not select data ”); $query = “create table my_table (col_1 int not null primary key, col_2 text )”; mysql_query($query) or die (mysql_error());

四、創(chuàng)建索引

index index_name(indexed_column)

五、表的類(lèi)型

 ISAM MyISAM BDB Heap

 聲明表類(lèi)型的語(yǔ)法:

create table table_name type=table_type (col_name column attribute);

默認(rèn)使用MyISAM

六、修改表

alter table table_name

更改表名

alter table table_name rename new_table_name

或者(高版本中)

rename table_name to new_table_name

添加和刪除列

添加列:

alter table table_name add column column_name colomn attributes

例如:

alter table my_table add column my_column text not null

first 指定插入的列位于表的第一列

after 把新列放在已經(jīng)存在的列的后面

    例如:

alter table my_table add column my_next_col text not null firstalter table my_table add column my_next_col text not null after my_other _column
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 柏乡县| 宁远县| 达孜县| 保山市| 威远县| 久治县| 乌兰察布市| 定南县| 库车县| 金门县| 黑水县| 定襄县| 文山县| 蕉岭县| 西吉县| 丹阳市| 巫山县| 宁都县| 淮阳县| 曲松县| 肇庆市| 理塘县| 明水县| 娄底市| 托克托县| 射洪县| 随州市| 平舆县| 和林格尔县| 丰台区| 秀山| 弥勒县| 化德县| 抚远县| 海南省| 海宁市| 西乡县| 汝城县| 武平县| 莆田市| 韩城市|