mysql必背 必背的mysql語句 doc

2021-10-18 02:16:39 字數 2016 閱讀 2690

必背的mysql語句

必背的mysql語句

set names gbk;互動字符集

1--互動字符集要和我的sql語句的編碼保持一致

出現亂碼問題:

mysql_connect("localhost","root","printf");

mysql_query("set names utf8");

mysql_query("insert into....");

insert into use (id, name) values(1,"小小帥");

1--資料庫的編碼是utf8

alter database psd1312 default character set utf8;

2--資料表的編碼是utf8

alter table user deafault character set utf8;

3--表中中文字段是否為utf8

alter table user modify username char(10) default charset=utf8 not null;

00001:建帶有預設編碼的資料庫(psd1305..預設編碼為:gbk)

create database psd1308 default character set gbk;

00002:先判斷是否存在的建表方式(course表 id int(4) ,非空自增長)

drop table course;

create table course(id int(4) auto_increment not null);

或者create table if not exists course(id int(4) auto_increment not null);

00003:增刪改

增增加字段(demo表 uid int)

alter table demo add uid int;

增加記錄 (demo表 id ,name ,*** ,age)

insert into demo(id ,name ,*** , age)values(1 , "lanol" , "female", "18");

增加唯一索引(demo表 unique)

alter table demo modify id int unique;

增加主鍵(demo表 primary key)

alter table demo modify id int primary key;

alter table tb change id id int(10) not null auto_increment=1;

增加預設(demo表 not null default 0)

alter table demo modify age int not null default 0;

增加外來鍵(t1表 t2表 foreign key references )

alter table t1 add foreign key(typeid) references t2(typeid);

刪刪除字段(demo表 刪id)

alter table demo drop id;

刪除記錄(demo表 id=2)

delete from demo where id = 2;

刪除表(demo表)

drop table demo;

刪資料庫(資料庫psd1305)

drop database psd1308;

刪除唯一索引(show demo表+id為索引名)

show index from demo; alter table demo drop index id;-->id為索引名

刪除主鍵:--->先刪除自增長再刪除主鍵

alter table tb change id id int(10);//刪除自增長

alter table tb drop primary key;//刪除主建

改改欄位名(demo表中的id改為uid int)

alter table demo chang

python必背內容

1 print 輸出 print 函式的基本用法如下 print 輸出內容 其中,輸出內容可以是數字和字串 使用引號括起來 此類內容將直接輸出,也可 以是包含運算子的表示式,此類內容將計算結果輸出。例如 a 100 變數a,值為100 b 5 變數b,值為5 print 9 輸出數字9 print ...

C語言必背程式

1 輸出 9 9口訣。共9行 9列,i控制行,j控制列。include stdio.h main if leap 內迴圈結束後,leap 依然為1,則m 是素數 for i 2 i 5 i for j 1 j i 1 j a i j a i 1 j a i 1 j 1 for i 0 i 5 i 7...

pandas 必背函式操作

1 五個常用屬性 index,columns,shape,values,dtypes 2 常用函式 set index,reset index,del df column name pd.read csv 3 時間 數字 字串轉換 字串轉換 切割 df column name astype str ...