SQL基礎語句

2021-09-11 18:01:41 字數 1404 閱讀 5514

1. 建立表

create table actor

(actor_id smallint(5) not null primary key,

first_name varchar(45) not null,

last_name varchar(45) not null,

last_update timestamp not null default (datetime('now','localtime'))

);

2.插入、批量插入

insert or ignore into actor

values(1,'penelope','guiness','2006-02-15 12:34:33'),

(2,'nick','wahlberg','2006-02-15 12:34:33');

insert into *** select from
3.建立索引

唯一索引

create unique index uniq_idx_firstname on actor(first_name);
強制索引

select * from salaries indexed by idx_emp_no where emp_no=10005
4.建立檢視

create view actor_name_view as

select first_name as first_name_v,last_name as last_name_v

from actor

5.新增列

alter table actor 

add create_date datetime not null default('0000-00-00 00:00:00』)

6.選取第

一、第三(倒數第

一、第三

order by *** desc limit 1

order by *** desc limit 1 offset 2

7.外連線

select a.xx b.*** from a left outer join b on a.xx=b.***
left join on ... where *** is null
8.striftime(輸出,時間)

輸出:』%d『為字元,「%d」為數

9.字串

包含字串 like '%***%'

拼接字串 select ***||xx||*** as ***

SQL基礎語句

一.資料庫查詢語句 select 1.查詢所有資料 select from 表名 select from exam books 2.按照一定的條件查詢 select from 表名 where 條件 select from exam books where id 20 3.範圍條件查詢 select...

SQL基礎語句

1.1.1dml 資料操作語言 1.1.2 ddl 資料定義語言 select update delete insert 1.2.1 select語法a.查詢所有 select from 表名 b.查詢列 select 列名 from 表名 注意 查詢列名時,列名用逗號隔開,最後的列名不要加逗號1....

基礎sql語句

從資料庫中刪除資料 delete 插入資料 insert into 建立新資料庫 create database 修改資料庫 alter database 建立新錶 create table 變更資料庫表 alter table 刪除表 drop table 建立索引 create index 刪除...