mysql資料庫之SQL語言之DML 資料操縱語言

2021-08-27 05:42:45 字數 1884 閱讀 1327

建表:

insert into tablename values(value1,value2,...);          

必須按照建表字段順序賦值

insert into tablename(colname1,colname2,....) values(value1,value2,...);

給指定字段賦值

練習:建表teacher,字段,tid int(4),tname varchar(20),tage int(2),birth date

create table teacher(tid int(4),tname varchar(20),tage int(2),birth date);

插入資料:

練習:插入一條資料  1001,高圓圓,38,'1983-10-12'

insert into teacher values(1001,'高圓圓',38,'1983-10-12');

練習:插入一條資料 1002,夜華,40

insert into teacher values(1002,'夜華',40,null);

insert into teacher(tname,tid,tage)values('白淺',1003,100);

檢視是否新增進表

select * from teacher;

ps:

alter table teacher character set utf8;

建立表時直接修改預設編碼集為utf8

刪除表中的資料:

delete關鍵字:刪除表中的資料

格式:delete from tablename [where 條件]

練習1:刪除表temp_t02中的所有資料。

delete from temp_t02;

練習2:刪除表中temp_t02中的tid為1001的記錄。

delete from temp_t02 where tid=1001;

練習3:刪除表temp_t02中 tid為1002和位址為上海的的資料

delete from temp_t02 where tid=1002 and address='上海';

修改表中的資料:

update關鍵字:修改表中的資料

格式:

update tablename set colname1=value1[,colname2=value2] [where 條件]

練習1:修改表temp_t02中的字段address為中國。

update temp_t02 set address='中國';

練習2:修改表temp_t02中的tid為1002的address為英國,人名為micheal。

update temp_t02 set address='英國',tname='micheal' where tid=1002;

練習3:將生日為null的記錄的tname改為'general'

update temp_t02 set tname='general' where tbirth is null;

練習4:將tid為1001的tbirth改為'2000-8-8';

update temp_t02 set tbirth = '2000-8-8' where tid = 1001;

練習5:將tid為1002的address改為null.

update temp_t02 set address=null where tid=1002;

Sql資料庫語言

我今天學習了一下資料庫簡單的sql 語言。1.建立資料庫 cerate database users 2.建立資料庫的位置 on primary filename d data data mdf size 50mb,maxsize 100mb,filegrowth 2mb log on name u...

mysql資料庫操作 SQL查詢語言

sql structured query language ddl create drop alter dml insert delete udpate dql select dcl grant revoke 刪除和建立資料庫 drop database if exists company crea...

資料庫系統之SQL語言

sql語言是集ddl 資料庫定義語言,用來定義資料庫和資料表 dml 資料操縱語言,用於操縱資料庫中的資料 dcl 資料控制語言,如設定資料的訪問許可權 於一體的資料庫語言。sql語言主要由以下9個單詞引導的操作語句構成 dml語句引導詞 insert,delete,update,select dc...