mysql建表測試

來源:互聯網
上載者:User

標籤:creat   參考   新聞   插入   預設   table   create   varchar   new   

drop table if exists news; --如果存在表則刪除
create table news  --建立表
(
        id int unsigned not null auto_increment,
        title varchar(30) not null default ‘‘ comment ‘新聞標題‘,
        class_id int unsigned not null default ‘0‘ comment ‘所屬分類的id‘,
        content text not null comment ‘詳情‘,
        primary key(id),
        index `i_title`(title), index `i_class_id`(class_id)
) engine=‘innodb‘ default charset utf8 comment = ‘新聞表‘;--設定引擎為innodb  預設編碼為utf8
drop table if exists  news_class;
create table news_class
(
        id int unsigned not null auto_increment,
        class_name varchar(10) not null default ‘‘ comment ‘分類名稱‘,
        primary key(id),
        index `i_class_name`(class_name)
) engine=‘innodb‘ default charset utf8 comment="新聞分類表";
-- 分類, php新聞 id=1  linux新聞 id=2  mysql新聞 id=3 其下 新聞
insert into news_class (class_name) values (‘php新聞‘),(‘Linux新聞‘),(‘Mysql新聞‘);--插入資料庫3條資料
insert into news(title,class_id,content) values --批量插入資料
(‘php新聞1‘,‘1‘,‘詳情‘),
(‘php新聞2‘,‘1‘,‘詳情‘),
(‘linux新聞1‘,‘2‘,‘詳情‘),
(‘linux新聞2‘,‘2‘,‘詳情‘),
(‘未知分類新聞‘,‘4‘,‘詳情‘);
--以下是參考寫入資料的方法replace into news_class(class_name) values(‘測試‘)
insert into news_class set class_name=‘abc‘;

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.