當前位置:首頁 » 編程語言 » sql倉庫表
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql倉庫表

發布時間: 2023-02-02 23:16:25

A. 如何建立倉庫sql數據表關系

市 面上所謂的破解軟體都一般是沒有破解完的,軟體功能不全的,
我 們公司使用的易 順 佳 軟體不錯。
很 詳細的幫助文件與使用視頻。

B. 用SQL語句復制倉庫表生成名為BAK的表文件

SQL 不支持對表的直接備份。
--你可以考慮把指定的表以文本文件的形式來進行備份/恢復

if exists(select 1 from sysobjects where name= 'File2Table ' and objectproperty(id, 'IsProcere ')=1)
drop procere File2Table
go

/*--實現數據導入/導出的存儲過程

可以實現導入/導出 整個資料庫/指定表 到文本文件

/*--調用示例

導出調用示例
--導出指定表,這里指定導出表:地區資料 和 基本信息,文件名前綴為:zj
exec file2table 'zj ', ' ', ' ', 'd:\ ', 'xzkh_sa ', '地區資料,基本信息 '
--導出整個資料庫到c:\docman目錄下,無文件前綴
exec file2table 'zj ', ' ', ' ', 'd:\txt\ ', 'xzkh_sa '

導入調用示例
--導入指定表,這里指定導出表:地區資料 和 基本信息,文件名前綴為:zj
exec file2table 'zj ', ' ', ' ', 'c:\zj ', 'xzkh_sa ', '地區資料,基本信息 ',0
--導入整個資料庫從c:\docman目錄下,無文件前綴
exec file2table 'zj ', ' ', ' ', 'C:\docman\ ', 'xzkh_sa ', ' ',0
--*/
create procere File2Table
@servername varchar(200)--伺服器名
,@username varchar(200)--用戶名,如果用NT驗證方式,則為空 ' '
,@password varchar(200)--密碼
,@path varchar(1000)--目錄名+文件前綴,目錄名必須以 '\ '結束,文件名自動用表名.txt
,@dbname varchar(500)--資料庫名
,@tbname varchar(8000)= ' '--表名列表,如果不指定,則表示所有用戶表
,@isout bit=1--1為導出(默認),0為導入
as
declare @sql varchar(8000),@sql1 varchar(8000)
declare @tbstation int,@filestation int

--初始化數據處理語句
select @sql= 'bcp " '+@dbname+ '.. '
,@tbstation=len(@sql)+1
,@sql=@sql
+case when @isout=1 then ' " out ' else ' " in ' end
+ ' " '+@path
,@filestation=len(@sql)+1
,@sql=@sql
+ '.txt " /c '+ ' /S " '+@servername
+case when isnull(@username, ' ')= ' ' then ' '
else ' " /U " '+@username end
+ ' " /P " '+isnull(@password, ' ')+ ' " '

--數據導入/導出處理
--定義數據處理的游標
set @sql1= 'declare #tb cursor for select name from '
+@dbname+ '..sysobjects where xtype= ' 'U ' ' '
+case when isnull(@tbname, ' ')= ' ' then ' '
else ' and name in ( ' ' '+replace(@tbname, ', ', ' ' ', ' ' ')+ ' ' ') ' end
exec(@sql1)
open #tb
fetch next from #tb into @tbname
while @@fetch_status=0
begin
select @sql1=stuff(@sql,@tbstation,0,@tbname)
,@sql1=stuff(@sql1,@filestation+len(@tbname),0,@tbname)
exec master..xp_cmdshell @sql1,no_output
fetch next from #tb into @tbname
end
close #tb
deallocate #tb
go

C. 6.倉庫管理系統中的表結構如下所示,請根據要求寫出SQL命令完成下題:

--1--
select*from倉庫where面積>350
--2--
select倉庫號,avg(工資)from職工
--3--
select姓名,工資intozgxxfrom職工
--4--
select姓名from職工where姓名like('張%')
--5--
select姓名,工資from職工where倉庫號='WH1'
--6--
select*from訂單where訂購日期like('2008%06%')
--7--
select*from訂單where職工號='E1'
--8--
select供應商號,sum(訂單數量)as合計訂單數from訂單groupby供應商號
--9--
select職工號,sum(訂單數量)as合計訂單數from訂單groupby職工號
--10--
select*from供應商where供應商名like('%北京%')
--11--
update職工set倉庫號='WH4'where姓名='孫小空'
--12--
selectsum(面積)面積總和from倉庫
--13--
selectcount(職工號)as人數,倉庫號from職工groupby倉庫號

D. SQL的題目,最基礎的~等~~

1. 從職工關系中檢索所有工資值。
答:select 工資 from 職工表
2. 檢索倉庫關系中的所有記錄
答:select * from 倉庫表
3. 檢索工資多於1230元的職工號
答:select 職工號 from 職工表 where 工資>1230
4.檢索哪些倉庫有工資多於1210元的職工。
答:select distinct 倉庫號 from 職工表 where 工資>1210
5. 給出在倉庫「wh1」或「wh2」工作,並且工資少於1250元的職工號。
答:select 職工號 from 職工表 where 工資<1250 ;
and (倉庫號="wh1" or 倉庫號="wh2")
注意:邏輯運算符的優先順序從高到低依次為not、and、or。運算符的優先順序:括弧 算術運算 關系運算 邏輯運算.
說明:前面的幾個例子在from之後只指定了一張表,也就是說這些檢索只基於一張表。如果有where子句,系統首先根據指定的條件依次檢驗關系中的每條記錄,然後選出滿足條件的記錄(相當於關系的選擇操作),並顯示select子句中指定屬性的值(相當於關系的投影操作)。
6. 找出工資多於1230元的職工號和他們所在的城市。
答:select 職工表.職工號, 倉庫表.城市 from 職工表,倉庫表 ;
where 職工表.倉庫號=倉庫表.倉庫號 and 工資>1230
7. 找出工作在面積大於400的倉庫的職工號以及這些職工工作所在的城市。
答:select 職工表.職工號, 倉庫表.城市, 倉庫表.面積 ;
from 職工表,倉庫表 where 職工表.倉庫號=倉庫表.倉庫號 ;
and 倉庫表.面積>400
說明:以上兩題為簡單的聯接查詢.
8. 哪些城市至少有一個倉庫的職工工資為1250元
答:
方法一:
Select 倉庫表.城市 from 職工表,倉庫表 where 職工表.倉庫號=倉庫表.倉庫號 and 職工表.工資=1250
方法二:
select 倉庫號 from 職工表 where 工資=1250 into dbf abc.dbf
select 倉庫表.城市 from 倉庫表,abc where 倉庫表.倉庫號=abc.倉庫號
方法三:
select 城市 from 倉庫表 where 倉庫號 in (select 倉庫號 from 職工表 where 工資=1250)
說明: 這屬於嵌套查詢. 這類查詢所要求的結果出自一個關系,但相關的條件卻涉及多個關系.
可以看到,方法三的命令中含有兩個select-from-where查詢塊,即內層查詢塊和外層查詢塊,內層查詢塊檢索到的倉庫值是wh1和wh2,這樣就可以寫出等價命令:
select 城市 from 倉庫表 where 倉庫號 in ("wh1","wh2")
或者
select 城市 from 倉庫表 where 倉庫號="wh1" or 倉庫號="wh2"
9. 查詢所有職工的工資都多於1210元的倉庫的信息。
答:
方法一:
select 倉庫號,min(工資) as 工資 from 職工表 group by 倉庫號 into dbf 倉庫min工資.dbf
select 倉庫表.* from 倉庫表,倉庫min工資 where 倉庫表.倉庫號=倉庫min工資.倉庫號 and 倉庫min工資.工資>1210
方法二:
select * from 倉庫表 where 倉庫表.倉庫號 not in (select 倉庫號 from 職工表 where 工資<=1210 ) and 倉庫表.倉庫號 in (select 倉庫號 from 職工表)
(錯誤方法)
select * from 倉庫表 where 倉庫表.倉庫號 not in (select 倉庫號 from 職工表 where 工資<=1210 )
注意:上述檢索結果錯誤,會將沒有職工的倉庫檢索出來.如果要求排除那些還沒有職工的倉庫,檢索要求可以敘述為:檢索所有職工的工資都大於1210元的倉庫的信息,並且該倉庫至少要有一名職工.
(錯誤方法)
select * from 倉庫表 where 倉庫表.倉庫號 in (select 倉庫號 from 職工表 where 工資>1210 )
注意:上述查詢結果錯誤。它會查出倉庫號為wh1的信息,但wh1的職工工資並不都大於1210。
10. 找出和職工e4掙同樣工資的所有職工。
答: Select 職工號 from 職工表 where 工資 in (select 工資 from 職工表 where 職工號="e4")
說明:7、9、10題都是基於多個關系的查詢,這類查詢所要求的結果出自一個關系,但相關的條件卻涉及多個關系.我們稱之為嵌套查詢。嵌套查詢優選含有兩個select-from-where查詢塊的查詢結構。
11. 檢索出工資在1220元到1240元范圍內的職工信息。
答:select * from 職工表 where 工資 between 1220 and 1240
說明: "工資 between 1220 and 1240"等價於"工資>=1220 and 工資<=1240"
如果要求查詢工資不在1220元到1240元范圍內的職工信息
說明: select * from 職工表 where 工資 not between 1220 and 1240
12. 從供應商關系中檢索出全部公司的信息,不要工廠或其他供應商的信息。
Select * from 供應商表 where "公司" $ 供應商名
13. 找出不在北京的全部供應商信息。
Select * from 供應商表 where 地址!="北京"
或者
Select * from 供應商表 where not(地址="北京")
14. 按職工的工資值升序檢索出全部職工信息。
答:select * from 職工表 order by 工資
如果需要將結果按降序排列,只要加上desc
select * from 職工表 order by 工資 desc
說明:使用SQL SELECT可以將查詢結果排序,排序的短語是order by ,具體格式如下:
order by order_item [ASC|DESC] [,order_item [ASC|DESC]……]
15. 先按倉庫號排序,再按工資排序並輸出全部職工信息。
答:Select * from 職工表 order by 倉庫號,工資
16. 找出供應商所在地的數目。
答:select count(distinct 地址) from 供應商表
注意:除非對表中的記錄數進行計數,一般count函數應該使用distinct
比如: select count(*) from 供應商表
查詢結果是供應商表中的記錄數.
說明:可用於計算檢索的函數有:count——計數 sum——求和
avg——計算平均值 max——求最大值 min——求最小值
17. 求支付的工資總數
答:select sum(工資) from 職工表
18. 求北京和上海的倉庫職工的工資總和
答: select sum(工資) from 職工表,倉庫表 where 職工表.倉庫號=倉庫表.倉庫號 and (城市="北京" or 城市="上海")
方法二:
select sum(工資) from 職工表 where 倉庫號 in (select 倉庫號 from 倉庫表 where 城市="北京" or 城市="上海")
19. 求所有職工的工資都多於1210元的倉庫的平均面積
答:Select avg(面積) from 倉庫表 where 倉庫號 not in(select 倉庫號 from 職工表 where 工資<=1210) and 倉庫號 in(select 倉庫號 from 職工表)
20. 求在wh2倉庫工作的職工的最高工資值
答:select max(工資) from 職工表 where 倉庫號="wh2"
21. 求每個倉庫的職工的平均工資
答:select 倉庫號,avg(工資) from 職工表 group by 倉庫號
說明:可以利用group by 子句進行分組計算查詢.group by短語的格式如下:group by groupcolumn[,groupcolumn……][having filtercondition]
可以按一列或多列分組,還可以用having 進一步限定分組的條件.
注意:where /group by等子句都不能放在from子句之前.
22. 求至少有兩個職工的每個倉庫的平均工資。
答: select 倉庫號,count(*),avg(工資) from 職工表 group by 倉庫號 having count(*)>=2
說明:having子句總是跟在group by 子句之後,不可以單獨使用.having子句用於限定分組.
23. 找出尚未確定供應商的訂購單
答:select * from 訂購單表 where 供應商號 is null
24. 列出已經確定了供應商的訂購單信息
答:select * from 訂購單表 where 供應商號 is not null

E. SQL多表查詢的條件問題

就是連接條件
說白了就是2個表根據什麼欄位進行關聯;

關聯舉個例子說吧:
表a存儲了一個人的基本信息,如(學號、姓名、年齡等)
表b存儲了這個人的每次考試的信息(學號,成績等)
那麼這連個表是有聯系的,那麼根據什麼聯系呢,可以根據這個學員的學號進行關聯。

F. 怎樣用SQL寫一個倉庫管理系統

首先配置SQLSERVER2005:

打開」Microsoft SQL Server Management Studio「 直接用Windows 用戶連接進入,再在「安全性」中的「登錄名」內的「新建登錄名」,你就對應的添好「確定」就可以了。

再在你對應的「資料庫」里「安全性」用戶,把你建的用戶添加進去。

關鍵地方,查看「伺服器 屬性」在 「安全性」選上 「SQL Server 和 Windows 身份驗證模式」點 「確定」系統會提示你重新啟動SQL Server 你「停止」重啟一下就配好了。

接著看C#連接SQL Server2005的代碼語句:

strcon = strcon + @"Data Source=" + strcons[0];
strcon = strcon + "," + strcons[2] + ";";
strcon = strcon + "Network Library=" + strcons[1] + ";";
strcon = strcon + "Initial Catalog=" + strcons[3] + ";";
strcon = strcon + "User ID=" + strcons[4] + ";";
strcon = strcon + "Password=" + strcons[5] + ";";
strcon = strcon + "Persist Security Info=True";

strcons[0] 伺服器名稱,一般添機器的IP
strcons[1]協議DBMSSOCN(為tcp/ip協議)
strcons[2]]埠號,一般為1433
strcons[3] 資料庫名
strcons[4] 用戶名
strcons[5]密碼

埠號也要配置一下:

在控制面板里的服務和應用程序中的SQL Server配置管理中的SQL Server 2005網路配置內的SQL

Server2005的協議TCP/IP默認為已禁用,在它的屬性設置它的埠號為1433 「確定」 啟動。

G. SQL SERVER請教!

二、查詢有兩個訂單及以上的職工的職工號(Eno)和訂單數量,寫出SQL語句,並對執行結果截圖。(15分)
Select eno, count(Ono)
from orders
group by eno
HAVING count(Ono)>=2
三、刪除職工』趙一』訂單金額在18000及以下的訂單記錄,寫出SQL語句,並對結果截圖。(15分)
Delete From orders
Where eno=(select eno from employees where ename='趙一')
and omoney<=18000
四、創建存儲過程Get_SumMoney。
1)以職工姓名(Ename)為參數,計算這個職工所獲訂單的金額(Omoney)總和,寫出SQL語句,並對執行結果截圖。(15分)
--創建存儲過程
alter procere get_summoney
@ename varchar(50),@omoney int output
As
Select @omoney=sum(omoney)
From orders,Employees
where orders.eno=Employees.eno and Employees.ename=@ename

2)使用存儲過程Get_SumMoney計算職工 』趙一』 獲得的訂單金額總和,寫出SQL語句,並對執行結果截圖。(5分)
--執行存儲過程
DECLARE @ename varchar(50),@omoney int --定義局部變數
SELECT @ename='趙一'
EXECUTE get_summoney @ename,@omoney OUTPUT
SELECT @omoney 訂單的金額

H. SQL語句 統計部分倉庫數量

  1. 指定要統計的倉庫名稱

    select count(數量) from (select * from tableName where 倉庫名稱 in ('倉1','倉2','倉3'));

  2. 不指定名稱

    select count(數量) from tableName where rownum<=num; ps:num就是要查幾個倉庫,可以當參數傳入, 上面的倉1 倉2 也可以當參數傳入