當前位置:首頁 » 編程語言 » sqltable

sqltable

發布時間: 2022-01-08 06:09:33

『壹』 怎樣用sql語句查詢一個資料庫中的所有表

查詢一個資料庫中的所有表sql語句是show tables;

顯示所有資料庫的命令是:show databases;要查看某個資料庫先要進入資料庫使用user <資料庫名>命令;進入資料庫之後才能查詢資料庫中有哪些表。使用以下命令即可查出所有表:

show tables;

(1)sqltable擴展閱讀

mysql資料庫的基本sql操作命令介紹:

1、顯示當前資料庫伺服器中的資料庫列表:mysql> SHOW DATABASES;

2、建立資料庫:mysql> CREATE DATABASE 庫名;

3、建立數據表:mysql> USE 庫名;mysql> CREATE TABLE 表名 (欄位名 VARCHAR(20), 字

名 CHAR(1));

4、刪除資料庫:mysql> DROP DATABASE 庫名;

5、刪除數據表:mysql> DROP TABLE 表名;

6、將表中記錄清空:mysql> DELETE FROM 表名;

7、往表中插入記錄:mysql> INSERT INTO 表名 VALUES ("hyq","M");

8、更新表中數據:mysql-> UPDATE 表名 SET 欄位名1='a',欄位名2='b' WHERE 欄位名3='c';

9、用文本方式將數據裝入數據表中:mysql> load data local infile "d:/mysql.txt" into table 表名;

10、導入.sql文件命令:mysql> USE 資料庫名;mysql> source d:/mysql.sql;

『貳』 怎樣在sql表查詢最新10條記錄

select*from
(selecttop10*from表名orderbydate1)table1orderbydate1desc

以上這段sql語句是查詢表中最新的10條記錄

  • 第一步是要按照「日期」降序排列

  • 第二步取前10條

『叄』 sql 表結構

column1 datatype [not null] [not null primary key], column2 datatype [not null],...)
說明:
datatype --是資料的格式,詳見表。
nut null --可不可以允許資料有空的(尚未有資料填入)。
primary key --是本表的主鍵。
2、更改表格
alter table table_name add column column_name datatype
說明:增加一個欄位(沒有刪除某個欄位的語法。)
lter table table_name add primary key (column_name)
說明:更改表得的定義把某個欄位設為主鍵。
alter table table_name drop primary key (column_name)
說明:把主鍵的定義刪除。
3、建立索引
create index index_name on table_name (column_name)
說明:對某個表格的欄位建立索引以增加查詢時的速度。
4、刪除
drop table_name
drop index_name
二、資料形態 datatypes
smallint
16 位元的整數。
interger
32 位元的整數。
decimal(p,s)
p 精確值和 s 大小的十進位整數,精確值p是指全部有幾個數(digits)大小值,s是指小數後有幾位數。如果沒有特別指定,則系統會設為 p=5; s=0 。
float
32位元的實數。
double
64位元的實數。
char(n)
n 長度的字串,n不能超過 254。
varchar(n)
長度不固定且其最大長度為 n 的字串,n不能超過 4000。
graphic(n)
和 char(n) 一樣,不過其單位是兩個字元 double-bytes, n不能超過127。這個形態是為支援兩個字元長度的字體,例如中文字。
vargraphic(n)
可變長度且其最大長度為 n 的雙字元字串,n不能超過 2000。
date
包含了 年份、月份、日期。
time
包含了 小時、分鍾、秒。
timestamp
包含了 年、月、日、時、分、秒、千分之一秒。
三、資料操作 dml(data manipulation language)
資料定義好之後接下來的就是資料的操作。資料的操作不外乎增加資料(insert)、查詢資料(query)、更改資料(update) 、刪除資料(delete)四種模式,以下分 別介紹他們的語法:
1、增加資料:
insert into table_name (column1,column2,...) values ( value1,value2, ...)
說明:
1.若沒有指定column 系統則會按表格內的欄位順序填入資料。
2.欄位的資料形態和所填入的資料必須吻合。
3.table_name 也可以是景觀 view_name。
insert into table_name (column1,column2,...) select columnx,columny,... from another_table
說明:也可以經過一個子查詢(subquery)把別的表格的資料填入。
2、查詢資料:
基本查詢
select column1,columns2,... from table_name
說明:把table_name 的特定欄位資料全部列出來
select * from table_name where column1 = xxx [and column2 > yyy] [or column3 <> zzz]
說明:
1.'*'表示全部的欄位都列出來。
2.where 之後是接條件式,把符合條件的資料列出來。
select column1,column2 from table_name order by column2 [desc]
說明:order by 是指定以某個欄位做排序,[desc]是指從大到小排列,若沒有指明,則是從小到大排列
組合查詢
組合查詢是指所查詢得資料來源並不只有單一的表格,而是聯合一個以上的表格才能夠得到結果的。
select * from table1,table2 where table1.colum1=table2.column1
說明:
1.查詢兩個表格中其中 column1 值相同的資料。
2.當然兩個表格相互比較的欄位,其資料形態必須相同。
3.一個復雜的查詢其動用到的表格可能會很多個。
整合性的查詢:
select count (*) from table_name where column_name = xxx
說明:
查詢符合條件的資料共有幾筆。
select sum(column1) from table_name
說明:
1.計算出總和,所選的欄位必須是可數的數字形態。
2.除此以外還有 avg() 是計算平均、max()、min()計算最大最小值的整合性查詢。
select column1,avg(column2) from table_name group by column1 having avg(column2) > xxx
說明:
1.group by: 以column1 為一組計算 column2 的平均值必須和 avg、sum等整合性查詢的關鍵字一起使用。
2.having : 必須和 group by 一起使用作為整合性的限制。
復合性的查詢
select * from table_name1 where exists ( select * from table_name2 where conditions )
說明:
1.where 的 conditions 可以是另外一個的 query。
2.exists 在此是指存在與否。
select * from table_name1 where column1 in ( select column1 from table_name2 where conditions )
說明:
1. in 後面接的是一個集合,表示column1 存在集合裡面。
2. select 出來的資料形態必須符合 column1。
其他查詢
select * from table_name1 where column1 like 'x%'
說明:like 必須和後面的'x%' 相呼應表示以 x為開頭的字串。
select * from table_name1 where column1 in ('xxx','yyy',..)
說明:in 後面接的是一個集合,表示column1 存在集合裡面。
select * from table_name1 where column1 between xx and yy
說明:between 表示 column1 的值介於 xx 和 yy 之間。
3、更改資料:
update table_name set column1='xxx' where conditoins
說明:
1.更改某個欄位設定其值為'xxx'。
2.conditions 是所要符合的條件、若沒有 where 則整個 table 的那個欄位都會全部被更改。
4、刪除資料:
delete from table_name where conditions
說明:刪除符合條件的資料。
說明:關於where條件後面如果包含有日期的比較,不同資料庫有不同的表達式。具體如下:
(1)如果是access資料庫,則為:where mydate>#2000-01-01#
(2)如果是oracle資料庫,則為:where mydate>cast('2000-01-01' as date) 或:where mydate>to_date('2000-01-01','yyyy-mm-dd')
在delphi中寫成:
thedate='2000-01-01';
query1.sql.add('select * from abc where mydate>cast('+''''+thedate+''''+' as date)');
如果比較日期時間型,則為:
where mydatetime>to_date('2000-01-01 10:00:01','yyyy-mm-dd hh24:mi:ss')

『肆』 如何設置窗口中的SQLTable的表樣式

Table無法直接綁定數據但是給它套上個Repeater控制項就可以了。代碼如下:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="width: 420px;">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width: 20px; color: #f89e00;" valign="top" align="center">

</td>
<td style="width: auto;">
<a href="#" mce_href="#" target="_blank">
<%#Eval("AAAA")%>
</a>
</td>
<td style="width: 60px;">
<%#Eval("BBBB")%>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td style="width: 20px; color: #f89e00;" valign="top" align="center">

</td>
<td style="width: auto;">
<a href="#" mce_href="#" target="_blank">
<%#Eval("AAAA")%>"
</a>
</td>
<td style="width: 60px;">
<%#Eval("BBBB")%>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

『伍』 如何用SQL創建一個表格

1、打開SQL Server,在資料庫處,右鍵資料庫,點擊新建資料庫。

『陸』 sql表的結構:

  1. 查詢某天的借閱總數,某人的借閱總數;;

    查詢某天的借閱總數:

    select count(*) from table where借閱日期 = '(具體日期)'

    某人的借閱總數:

    select count(*) from table where 借閱人 = 『人名』

  2. 查詢某月的借閱記錄,並按借閱日期、借閱時間排序
    select *,from table where date_format(借閱日期,'%Y-%m') = '年-月' order by 借閱日期,借閱時間

  3. 查詢每本書的借閱總數,查詢每個借閱人的平均預計借閱天數
    查詢每本書的借閱總數:

    select借閱圖書ISBN,count(借閱圖書ISBN) from table group by借閱圖書ISBN

    查詢每個借閱人的平均預計借閱天數:

    select AVG(預計借閱天數) ,借閱人from table group by借閱人

『柒』 SQL中@有那幾種用法select * from sqltable@sqldb 中@的作用是什麼要詳細的

--從你這個select*fromsqltable@sqldb中看@符號只是普通的一個字元,應該是from後面那張表的名字中的一個字元,即表名的組成部分
--sql中@的用法一般都表示變數,declare申明變數時變數前要使用@
一個@用戶自定義局部變數
兩個@@系統全局變數

『捌』 sql 表 定義

是指MSSQL?這個在MSSQL里是錯誤的,如果需要特殊處理也是用「[]」來括起來,比如說表、欄位名稱中有空格,或是MSSQL里的保存關鍵字等等,都需要[]括起來。

『玖』 如何創建SQL表

  • 創建資料庫表首先得創建好資料庫,資料庫的具體創建方法請參見:http://jingyan..com/article/63f236280e53740209ab3d53.html

  • 3

    創建數據表的源代碼如下,各命令詳見請自行網路。

    use test

    go

    if exists(select name from sys.tables where name='Student')

    drop table Student

    go

    create table Student

    (sname nchar(10) primary key,

    sex nchar(2) not null,

    bir datetime

    )

『拾』 sql表結構怎麼查詢,

加入你的表的名字是 T_tmp,用下面的語句就可以得到你的表結構

select * from syscolumns where id=(select id from sysobjects where name='T_tmp')

熱點內容
java文件怎麼保存 發布:2024-05-22 11:17:17 瀏覽:827
安卓系統是哪裡造的 發布:2024-05-22 11:11:23 瀏覽:473
linux下sh 發布:2024-05-22 11:10:16 瀏覽:309
勞動資源配置中的自然配置是什麼 發布:2024-05-22 10:54:53 瀏覽:675
asp的資料庫 發布:2024-05-22 10:29:05 瀏覽:138
plc軟體編程程序 發布:2024-05-22 10:29:00 瀏覽:470
獲取資料庫信息 發布:2024-05-22 10:15:11 瀏覽:780
雲通信伺服器 發布:2024-05-22 10:12:10 瀏覽:401
job調用存儲過程 發布:2024-05-22 10:01:46 瀏覽:391
jsp導入java 發布:2024-05-22 10:00:50 瀏覽:181