Skip to main content

Create Database and Tabe


Create Database
CREATE DATABASE  -----> syntax
*****you can use the CREATE statement only to create objects onthe local server


CREATE DATABASE
[ON [PRIMARY]
([NAME = <’logical file name’>,]
FILENAME = <’file name’>
[, SIZE = ]
[, MAXSIZE = size in kilobytes, megabytes, gigabytes, or terabytes>]
[, FILEGROWTH = ])]
[LOG ON
([NAME = <’logical file name’>,]
FILENAME = <’file name’>
[, SIZE = ]
[, MAXSIZE = size in kilobytes, megabytes, gigabytes, or terabytes>]
[, FILEGROWTH = ])]
[ COLLATE ]
[ FOR ATTACH [WITH ]| FOR ATTACH_REBUILD_LOG| WITH DB_CHAINING
ON|OFF | TRUSTWORTHY ON|OFF]
[AS SNAPSHOT OF ]
[;]

CREATE DATABASE Accounting
ON
(NAME = ‘Accounting’,
FILENAME = ‘c:\Program Files\Microsoft SQL Server\
MSSQL.1\mssql\data\AccountingData.mdf’,
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5)
LOG ON
(NAME = ‘AccountingLog’,
FILENAME = ‘c:\Program Files\Microsoft SQL Server\
MSSQL.1\mssql\data\AccountingLog.ldf’,
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB)
GO

Create Table:::::::::::::::::::::

CREATE TABLE [database_name.[owner].]table_name
(
[[DEFAULT ]
|[IDENTITY [(seed, increment) [NOT FOR REPLICATION]]]]
[ROWGUIDCOL]
[COLLATE ]
[NULL|NOT NULL]
[]
|[column_name AS computed_column_expression]
|[]
[,...n]
)
[ON {|DEFAULT}]
[TEXTIMAGE_ON {|DEFAULT}]


USE Accounting
CREATE TABLE Customers
(
CustomerNo int IDENTITY NOT NULL,
CustomerName varchar(30) NOT NULL,
Address1 varchar(30) NOT NULL,
Address2 varchar(30) NOT NULL,
City varchar(20) NOT NULL,
State char(2) NOT NULL,
Zip varchar(10) NOT NULL,
Contact varchar(25) NOT NULL,
Phone char(15) NOT NULL,
FedIDNo varchar(9) NOT NULL,
DateInSystem smalldatetime NOT NULL
)

table name::::::::::::::
--capitalize the first letter and use lowercase for the remaining letters.
--Limit the use of abbreviations.
--When building tables based on other tables (usually called linking or associate tables), you
should include the names of all of the parent tables in your new table name.
--When you have two words in the name, do not use any separators (run the words together)—

Default::::::::::::::
this is the value you want to be used for any rows that are inserted without a user-supplied value for this particular column.

Identity (almost like primary Key Constraints but wid one difference):::::::::::::::::::::::::::::::::
when you make a column an identity column, SQL Server automatically assigns a sequenced number to this column with
every row you insert. The number that SQL Server starts counting from is called the seed value, and the
amount that the value increases or decreases by with each row is called the increment.An identity column must be numeric, and, in practice, it is almost always implemented with an integer
or bigint datatype.
*******an IDENTITY column and a PRIMARY KEY are completely separate notions— in IDENTITY columns you can reset the seed value and count back up through values you’ve used before

Column Constraints::::::::::::::::::::::::::::
they are restrictions and rules that you place on individual columns about the data that can be inserted into that column. (for ex. if a column shd have the month(1 to 12) it should not allow 13 to be inserted.

Computed Columns::::::::::::::::::::::::::::::::::
its value is derived from other columns in the table by executing some .
syntax:
AS
EX: ExtendedPrice AS Price * Quantity

Table Constraints:::::::::::::::::::::::::::::::::::
table-level constraints include PRIMARY and FOREIGN KEY constraints, as well as CHECK constraints.

Creating a Table::::::::::::::::::::::::::::::::::::
Ex:
CREATE TABLE Customers

Comments

Popular posts from this blog

Adding a linked Server using the GUI

Adding a linked Server using the GUI There are two ways to add another SQL Server as a linked server.  Using the first method, you need to specify the actual server name as the “linked server name”.  What this means is that everytime you want to reference the linked server in code, you will use the remote server’s name.  This may not be beneficial because if the linked server’s name changes, then you will have to also change all the code that references the linked server.  I like to avoid this method even though it is easier to initially setup.  The rest of the steps will guide you through setting up a linked server with a custom name: To add a linked server using SSMS (SQL Server Management Studio), open the server you want to create a link from in object explorer. In SSMS, Expand Server Objects -> Linked Servers -> (Right click on the Linked Server Folder and select “New Linked Server”) Add New Linked Server The “New Linked Server” Dialog a...

JavaScript Interview Questions

This is a compilations of all the interview questions related to Javascript that i have encountered.  Q: Difference between window.onload and onDocumentReady? A: The onload event does not fire until every last piece of the page is loaded, this includes css and images, which means there’s a huge delay before any code is executed. That isnt what we want. We just want to wait until the DOM is loaded and is able to be manipulated. onDocumentReady allows the programmer to do that. Q:  What is the difference between == and === ? A: The == checks for value equality, but === checks for both type and value. Few examples: "1" == 1; // value evaluation only, yields true "1" === 1; // value and type evaluation, yields false "1" == true; // "1" as boolean is true, value evaluation only, yields true "1" === false; // value and type evaluation, yields false Q: What does “1″+2+5 evaluate to? What about 5 + 2 +...

Lookup!!

LOOKUP As the name suggests, Excel gives us the option to lookup for a number or text in a specific area which needs to be stated. If the value is found the corresponding value or text is returned The syntax for LOOKUP is as follows; =LOOKUP( lookup_value , lookup_vector , result_vector )       In the diagram, column D contains varying salaries, against which there is a company car in column E which corresponds to each salary. For example, a £20030 salary gets a Golf, a £35000 salary gets a Scorpio. A LOOKUP formula can be used to return whatever car is appropriate to a salary figure that is entered. In this case, the lookup_value is the cell where the salary is entered (B13), the lookup_vector is the salary column (D3:D11), and the result_vector is the car column (E3:E11). Hence the formula; =LOOKUP(B13,D3:D11,E3:E11) Typing 40000 in cell B13 will set the lookup_value. LOOKUP will search through the lookup_vector to find the matching salary, and return th...