0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SQLのテンプレート(SQL Server)

Last updated at Posted at 2022-07-21

たまにしか使わないSQLをメモ、メモ…

1.テーブルのコピー関連

・テーブルの構造コピー(カラム名、主キー等すべて同じクローンテーブル作成)

判らんかった。
SQLマネージメントスタジオで、テーブルのコピー>新規作成>…
で元テーブルのCreate文(主キーなどのCreate文含む)を作成し、テーブル名を変更してクローンテーブルを作成した。

・同じ構造のテーブルへの「データのみ」まるっとコピー

INSERT INTO [コピー先テーブル]
SELECT * 
FROM [オリジナルテーブル]

2.日付関連

・日付と時刻を合体させる方法

DECLARE @Day VARCHAR(10) = '20140801'
DECLARE @Time VARCHAR(10) = '10:10'

SELECT CONVERT(DATETIME, CONVERT(VARCHAR, @Day, 111) + ' ' + CONVERT(VARCHAR, @Time, 108))
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?