sql基本語法

2021-09-24 19:22:21 字數 1243 閱讀 6949

啟動/關閉資料庫:

1.首先進入到資料庫所在的目錄c:\program files\postgresql\11\bin

2.pg_ctl.exe -d …/data start/stop;

進入使用者:psql -h localhost -p 5432 -u 使用者名稱

可以將使用者postgres中所有的表資料備份:pg_dump -h localhost -p 5432 -u 使用者名稱 >d:\test.bak

select 所要選取的內容 from **名;

刪除內容:delete from 表名 where 所要刪除表的列名 = 『刪除的內容』;

drop 表名

truncate table 表名

select * from 表名 order by 所要排列的列名 asc(公升序)/desc(降序);

啟sql的left join 、right join 、inner join之間的區別

left join(左聯接) 返回包括左表中的所有記錄和右表中聯結字段相等的記錄

right join(右聯接) 返回包括右表中的所有記錄和左表中聯結字段相等的記錄

inner join(等值連線) 只返回兩個表中聯結字段相等的行

改名字:alter table 原名 rename to 新名字;

改密碼:\password postgres

alter user postgres with password 『所要修改的密碼』;

忘記資料庫密碼

1、關閉資料庫

2、找到進入資料庫的工作空間目錄在bin\pg_hba.conf

3、開啟pg_hba.conf將

ipv4 local connections:

host all all 127.0.0.1/32 md5

ipv6 local connections:

host all all ::1/128 md5

改為ipv4 local connections:

host all all 127.0.0.1/32 trust

ipv6 local connections:

host all all ::1/128 trust

改完之後要將trust改為md5

select 字段 into 新錶 from 舊表;

insert into 表名1 select from 表名2 where sno=『s1』;

insert into 表名 values(屬性);

SQL基本語法

update 有關update,急!在oracle資料庫中 表 a id firstname,lastname 表 b id,lastname 表 a 中原來id,firstname兩個欄位的資料是完整的 表 b中原來id,lastname兩個欄位的資料是完整的 現在要把表 b中的lastname欄...

SQL基本語法

1.select列名稱 from 表名稱 2.selectdistinct 列名稱 from 表名稱 3.select列名稱 from 表名稱 where 列 運算子值 eg select frompersons where city beijing select from persons wher...

SQL基本語法

重要的ddl語句 create database 建立新資料庫 alter database 修改資料庫 create table 建立新錶 alter table 變更 改變 資料庫表 drop table 刪除表 create index 建立索引 搜尋鍵 drop index 刪除索引 1.s...