Table Designs Flashcards

0
Q

Creating table

A
IF OBJECT_ID('schemaname.tblname', 'U') IS NOT NULL
   DROP TABLE schemaname.tblname'
CREATE TABLE schemaname.tblname
(
Colname datatype NULL/NOT NULL,
Colname2 datatype NULL/NOT NULL,
Colname3 datatype NULL/NOT NULL
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

Naming tbls

A

means tbl is temporary
## means creating a global tbl
Can use letter or underscore
Tbl can store 1024 columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Alter tbl com

A
Change column name
Add a new column
Delete column
Enable/disable triggers
Switch tbl to another partition

ALTER TABLE tblname
ADD col datatype NULL/NOT NULL

ALTER TABLE tblname
DROP COLUMN colname

ALTER TABLE tblname
ALTER COLUMN colname whatever u want 2 do

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Dropping tbl

A

It removed tbl definitions
Days
Indexes, triggers, constraints, permissions

Any VIEWS or STORED PROCEDURED have to be dropped separately

DROP TABLE tblname
note: this will ONLY fail if foreign key constraint exists.

To delete data but not tbl definition use
TRUNCATE TABLE tblname

How well did you know this?
1
Not at all
2
3
4
5
Perfectly