Posted on March 8th, 2018
Posted on February 14th, 2018
@NotNull
@Size(min = 2, max = 14)
Posted on November 24th, 2016
Posted on April 15th, 2016
MSSQL varchar, nvarchar 預設長度 30
nvarchar
, varchar
不給長度時, 有預設 30 的限制
以後記得, 所有對資料庫欄位的 update, 都應該要備份, 以確保不會有慘劇發生…
Posted on February 26th, 2015
密碼過期時就得修改密碼 , 否則該帳號將無法使用:
ALTER USER "使用者名稱" IDENTIFIED BY "新密碼" REPLACE "舊密碼"
查詢 Default user profile 的密碼期限: (預設是 180
天)
SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME';
查詢 user 是哪一種 profile: (預設應該都是 default
)
SELECT username,PROFILE FROM dba_users;
修改 default user profile 密碼過期的時間 (這邊改為無限制: UNLIMITED
)
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
Posted on December 26th, 2014
START WITH ... CONNECT BY PRIOR ...
SELECT Id
FROM Category START WITH Id=2 CONNECT BY
PRIOR Id=Parentid
with
WITH n (id, name) AS
(SELECT id, name
FROM category
WHERE id = 2 --父節點 id
UNION ALL SELECT child.id, child.name
FROM Category AS child, n
WHERE n.id = child.parentId)
SELECT * FROM n
如果要透過 n
再查詢, 例如查詢分類樹底下所有 binder
(假設 Binder
和 Category
透過 Binder_Category
來記錄關聯性)
WITH n (id, name) AS
(SELECT id,
name
FROM category
WHERE id = 2 --父節點 id
UNION ALL SELECT child.id,
child.name
FROM Category AS child, n
WHERE n.id = child.parentId)
SELECT *
FROM Binder bb
LEFT JOIN Binder_Category bc ON bc.binder_id = bb.id
WHERE bc.cat_id IN (SELECT id FROM n)
(感謝 April 大大教學)
Posted on November 7th, 2014
No - you have to do it the other way around: add it right from the get go as INT IDENTITY
- it will be filled with identity values when you do this:
ALTER TABLE dbo.YourTable
ADD ID INT IDENTITY
and then you can make it the primary key:
ALTER TABLE dbo.YourTable
ADD CONSTRAINT PK_YourTable
PRIMARY KEY(ID)
Posted on November 7th, 2014
匯入大檔, 錯誤大概都會長這樣...
資料來源選擇: 一般檔案來源
選好欲匯入的檔案,左側點選 進階
將文字欄位的 DataType 改成 文字資料流[DT_TEXT]
二位元組不帶正負號的整數[DT_UI2]
圖片來源: http://lanfar.pixnet.net
REF: SQL Server:匯入資料遭遇“文字已截斷"錯誤 from 蘭花❉心得報告
Posted on September 17th, 2014
這就是 Stored Procedures
, 不過這似乎要有權限才能完成!
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
Posted on September 16th, 2014
The following SQL will get you the row count of all tables in a database:
CREATE TABLE #counts
(
table_name varchar(255),
row_count int
)
EXEC sp_MSForEachTable @command1='INSERT #counts (table_name, row_count) SELECT ''?'', COUNT(*) FROM ?'SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC
The output will be a list of tables and their row counts.
If you just want the total row count across the whole database, appending:
SELECT SUM(row_count) AS total_row_count FROM #counts
will get you a single value for the total number of rows in the whole database.
REF:
Fetch_row_count_for_all_tables_in_a_SQL_SERVER by adrianbanks from stackoverflow.com
Notes from my experience.