mysql資料庫建庫建表執行個體

來源:互聯網
上載者:User

標籤:sts   字元   自動   預設   ack   auto   l資料庫   mysql資料庫   開啟   

一。執行個體。

drop database if exists school; //如果存在SCHOOL則刪除
create database school; //建立庫SCHOOL
use school; //開啟庫SCHOOL
create table teacher //建立表TEACHER
(
    id int(3) auto_increment not null primary key,
    name char(10) not null,
    address varchar(50) default ‘‘深圳‘‘,
    year date
); //建表結束

desc teacher;//查詢表結構。

//以下為插入欄位
insert into teacher values(‘‘‘‘,‘‘glchengang‘‘,‘‘深圳一中‘‘,‘‘1976-10-10‘‘);
insert into teacher values(‘‘‘‘,‘‘jack‘‘,‘‘深圳一中‘‘,‘‘1975-12-23‘‘);

註:在建表中
1、將ID設為長度為3的數字欄位:int(3);並讓它每個記錄自動加一:auto_increment;並不可為空:not null;而且讓他成為主欄位primary key。

2、將NAME設為長度為10的字元欄位

3、將ADDRESS設為長度50的字元欄位,而且預設值為深圳。

4、將YEAR設為日期欄位。

 

 

二。命令:

表操作命令:
複製表結構:create table table1 like table2;
複製資料:insert into table1 select * from table2 ;

清空資料表:truncate table t1;

 

mysql資料庫建庫建表執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.