Subscribe to my mailing List to notify every new posted topics:
I. What is Table?
Table is where data dump or stored in Database. A table is a collection of related data held in a table format within a database. It consists of columns and rows. In relational databases, and flat file databases, a table is a set of data elements using a model of vertical columns and horizontal rows, the cell being the unit where a row and column intersect.
To create a new table, you use the
CREATE TABLE statement as follows:
CREATE TABLE table_name ( pk_column data_type PRIMARY KEY, column_1 data_type NOT NULL, column_2 data_type, ..., table_constraints );
I just want to create the table belong in my testDB Database . so to open the Query tab. Just Right click the database name “testDB” and select or click “New Query”.
This is my sample T-SQL State to create table. I just want to create student table in my testDB database.
- Create Table stable is a command statement to create a table in the database.
- Student is the name of table which I want to create in my Database name testDB.
- Columns – student_id, firstname, lastname, middlename, and TDT is the sample column belong the table student I created.
- Datatype – this is the assign datatype of each column. Int for student_id to use is a primary key. Varchar and datetime for the others. there many datatype but this is what I commonly use of those.
- Not Null means table column is not open for null value. so every new row those column must have data. it is required. to create column that considered null value is to use only Null.
- Key Identify(1,1) mean is to enable autoincrement number.
This is the SQL statement.
Create Table student ( student_id INT Primary KEY IDENTITY (1, 1), firstname VARCHAR(50) NOT NULL, lastname VARCHAR(50) NOT NULL, middlename VARCHAR(50) NOT NULL, TDT datetime );
Here is it, table successfully created.
After refreshing the database, the student table appear.
this is the table design. the student_id set as primary key and also autoincrement. and the other column is set correctly.
In this blog, I will show how to use and where to use UNION in SQL. Explain How its work and why we need to use […]
In this blog, I will show step by step how to call a Web Service or Rest API in your T-SQL. explain how its works […]
A Common Table Expression also called CTE in short form, is a temporary named result set that you can reference within a SELECT, INSERT, UPDATE, […]
In this blog, I will show step by step how to use SQL Sub-Query in SQL Query. explain how its works and why we need […]