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

Insufficient access rights to perform the operation. (Exception from HRESULT: 0x80072098)

While accessing the active directory (AD) and authorization manager (AZMAN) , If you get “   Insufficient access rights to perform the operation. (Exception from HRESULT: 0x80072098)  “ message check the    account that is being used to get the LDAP query from AD .  ERROR DETAILS Exception Details:  System.Runtime.InteropServices.COMException: Insufficient access rights to perform the operation. (Exception from HRESULT: 0x80072098) Source Error: Line 154:    'Session("FullName") = System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString() Line 155: Line 156:    If Not User.IsInRole("Role1") Then Line 157:          Response.Redirect("./Login.aspx") Line 158:    End If  Stack Trace : .... SOLVE IT Steps to do check the app pool rights: Click on the website name that you are having problem with in IIS  In the right panel you will se...

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 +...

Do's and Don't SQL

Do's: Writing comments whenever something is not very obvious, as it won’t impact the performance.  (--) for single line  (/*…*/) to mark a section Use proper indentation Use Upper Case for all SQL keywords. SELECT, UPDATE, INSERT, WHERE, INNER JOIN, AND, OR, LIKE. Use BEGIN... END block for multiple statements in conditional code  Use Declare and Set in beginning of Stored procedure Create objects in same database where its relevant table exists otherwise it will reduce network performance. Use PRIMARY key in WHERE condition of UPDATE or DELETE statements as this will avoid error possibilities. If User table references Employee table than the column name used in reference should be UserID where User is table name and ID primary column of User table and UserID is reference column of Employee table. Use select column name instead of select * Use CTE (Common Table Expression); its scope is limited to the next statement in SQL query, instead of...